Show More
@@ -1,887 +1,886 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """IPython Shell classes. |
|
3 | 3 | |
|
4 | 4 | All the matplotlib support code was co-developed with John Hunter, |
|
5 | 5 | matplotlib's author. |
|
6 | 6 | |
|
7 |
$Id: Shell.py |
|
|
7 | $Id: Shell.py 703 2005-08-16 17:34:44Z fperez $""" | |
|
8 | 8 | |
|
9 | 9 | #***************************************************************************** |
|
10 | 10 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
11 | 11 | # |
|
12 | 12 | # Distributed under the terms of the BSD License. The full license is in |
|
13 | 13 | # the file COPYING, distributed as part of this software. |
|
14 | 14 | #***************************************************************************** |
|
15 | 15 | |
|
16 | 16 | from IPython import Release |
|
17 | 17 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
18 | 18 | __license__ = Release.license |
|
19 | 19 | |
|
20 | 20 | # Code begins |
|
21 | 21 | import __main__ |
|
22 | 22 | import __builtin__ |
|
23 | 23 | import sys |
|
24 | 24 | import os |
|
25 | 25 | import code |
|
26 | 26 | import threading |
|
27 | 27 | import signal |
|
28 | 28 | |
|
29 | 29 | import IPython |
|
30 | 30 | from IPython.iplib import InteractiveShell |
|
31 | 31 | from IPython.ipmaker import make_IPython |
|
32 | 32 | from IPython.genutils import Term,warn,error,flag_calls |
|
33 | 33 | from IPython.Struct import Struct |
|
34 | 34 | from IPython.Magic import Magic |
|
35 | 35 | from IPython import ultraTB |
|
36 | 36 | |
|
37 | 37 | # global flag to pass around information about Ctrl-C without exceptions |
|
38 | 38 | KBINT = False |
|
39 | 39 | |
|
40 | 40 | # global flag to turn on/off Tk support. |
|
41 | 41 | USE_TK = False |
|
42 | 42 | |
|
43 | 43 | #----------------------------------------------------------------------------- |
|
44 | 44 | # This class is trivial now, but I want to have it in to publish a clean |
|
45 | 45 | # interface. Later when the internals are reorganized, code that uses this |
|
46 | 46 | # shouldn't have to change. |
|
47 | 47 | |
|
48 | 48 | class IPShell: |
|
49 | 49 | """Create an IPython instance.""" |
|
50 | 50 | |
|
51 | 51 | def __init__(self,argv=None,user_ns=None,debug=1, |
|
52 | 52 | shell_class=InteractiveShell): |
|
53 | 53 | self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, |
|
54 | 54 | shell_class=shell_class) |
|
55 | 55 | |
|
56 | 56 | def mainloop(self,sys_exit=0,banner=None): |
|
57 | 57 | self.IP.mainloop(banner) |
|
58 | 58 | if sys_exit: |
|
59 | 59 | sys.exit() |
|
60 | 60 | |
|
61 | 61 | #----------------------------------------------------------------------------- |
|
62 | 62 | class IPShellEmbed: |
|
63 | 63 | """Allow embedding an IPython shell into a running program. |
|
64 | 64 | |
|
65 | 65 | Instances of this class are callable, with the __call__ method being an |
|
66 | 66 | alias to the embed() method of an InteractiveShell instance. |
|
67 | 67 | |
|
68 | 68 | Usage (see also the example-embed.py file for a running example): |
|
69 | 69 | |
|
70 | 70 | ipshell = IPShellEmbed([argv,banner,exit_msg,rc_override]) |
|
71 | 71 | |
|
72 | 72 | - argv: list containing valid command-line options for IPython, as they |
|
73 | 73 | would appear in sys.argv[1:]. |
|
74 | 74 | |
|
75 | 75 | For example, the following command-line options: |
|
76 | 76 | |
|
77 | 77 | $ ipython -prompt_in1 'Input <\\#>' -colors LightBG |
|
78 | 78 | |
|
79 | 79 | would be passed in the argv list as: |
|
80 | 80 | |
|
81 | 81 | ['-prompt_in1','Input <\\#>','-colors','LightBG'] |
|
82 | 82 | |
|
83 | 83 | - banner: string which gets printed every time the interpreter starts. |
|
84 | 84 | |
|
85 | 85 | - exit_msg: string which gets printed every time the interpreter exits. |
|
86 | 86 | |
|
87 | 87 | - rc_override: a dict or Struct of configuration options such as those |
|
88 | 88 | used by IPython. These options are read from your ~/.ipython/ipythonrc |
|
89 | 89 | file when the Shell object is created. Passing an explicit rc_override |
|
90 | 90 | dict with any options you want allows you to override those values at |
|
91 | 91 | creation time without having to modify the file. This way you can create |
|
92 | 92 | embeddable instances configured in any way you want without editing any |
|
93 | 93 | global files (thus keeping your interactive IPython configuration |
|
94 | 94 | unchanged). |
|
95 | 95 | |
|
96 | 96 | Then the ipshell instance can be called anywhere inside your code: |
|
97 | 97 | |
|
98 | 98 | ipshell(header='') -> Opens up an IPython shell. |
|
99 | 99 | |
|
100 | 100 | - header: string printed by the IPython shell upon startup. This can let |
|
101 | 101 | you know where in your code you are when dropping into the shell. Note |
|
102 | 102 | that 'banner' gets prepended to all calls, so header is used for |
|
103 | 103 | location-specific information. |
|
104 | 104 | |
|
105 | 105 | For more details, see the __call__ method below. |
|
106 | 106 | |
|
107 | 107 | When the IPython shell is exited with Ctrl-D, normal program execution |
|
108 | 108 | resumes. |
|
109 | 109 | |
|
110 | 110 | This functionality was inspired by a posting on comp.lang.python by cmkl |
|
111 | 111 | <cmkleffner@gmx.de> on Dec. 06/01 concerning similar uses of pyrepl, and |
|
112 | 112 | by the IDL stop/continue commands.""" |
|
113 | 113 | |
|
114 | 114 | def __init__(self,argv=None,banner='',exit_msg=None,rc_override=None): |
|
115 | 115 | """Note that argv here is a string, NOT a list.""" |
|
116 | 116 | self.set_banner(banner) |
|
117 | 117 | self.set_exit_msg(exit_msg) |
|
118 | 118 | self.set_dummy_mode(0) |
|
119 | 119 | |
|
120 | 120 | # sys.displayhook is a global, we need to save the user's original |
|
121 | 121 | # Don't rely on __displayhook__, as the user may have changed that. |
|
122 | 122 | self.sys_displayhook_ori = sys.displayhook |
|
123 | 123 | |
|
124 | 124 | # save readline completer status |
|
125 | 125 | try: |
|
126 | 126 | #print 'Save completer',sys.ipcompleter # dbg |
|
127 | 127 | self.sys_ipcompleter_ori = sys.ipcompleter |
|
128 | 128 | except: |
|
129 | 129 | pass # not nested with IPython |
|
130 | 130 | |
|
131 | 131 | # FIXME. Passing user_ns breaks namespace handling. |
|
132 | 132 | #self.IP = make_IPython(argv,user_ns=__main__.__dict__) |
|
133 | 133 | self.IP = make_IPython(argv,rc_override=rc_override,embedded=True) |
|
134 | 134 | |
|
135 | 135 | self.IP.name_space_init() |
|
136 | 136 | # mark this as an embedded instance so we know if we get a crash |
|
137 | 137 | # post-mortem |
|
138 | 138 | self.IP.rc.embedded = 1 |
|
139 | 139 | # copy our own displayhook also |
|
140 | 140 | self.sys_displayhook_embed = sys.displayhook |
|
141 | 141 | # and leave the system's display hook clean |
|
142 | 142 | sys.displayhook = self.sys_displayhook_ori |
|
143 | 143 | # don't use the ipython crash handler so that user exceptions aren't |
|
144 | 144 | # trapped |
|
145 | 145 | sys.excepthook = ultraTB.FormattedTB(color_scheme = self.IP.rc.colors, |
|
146 | 146 | mode = self.IP.rc.xmode, |
|
147 | 147 | call_pdb = self.IP.rc.pdb) |
|
148 | 148 | self.restore_system_completer() |
|
149 | 149 | |
|
150 | 150 | def restore_system_completer(self): |
|
151 | 151 | """Restores the readline completer which was in place. |
|
152 | 152 | |
|
153 | 153 | This allows embedded IPython within IPython not to disrupt the |
|
154 | 154 | parent's completion. |
|
155 | 155 | """ |
|
156 | 156 | |
|
157 | 157 | try: |
|
158 | 158 | self.IP.readline.set_completer(self.sys_ipcompleter_ori) |
|
159 | 159 | sys.ipcompleter = self.sys_ipcompleter_ori |
|
160 | 160 | except: |
|
161 | 161 | pass |
|
162 | 162 | |
|
163 | 163 | def __call__(self,header='',local_ns=None,global_ns=None,dummy=None): |
|
164 | 164 | """Activate the interactive interpreter. |
|
165 | 165 | |
|
166 | 166 | __call__(self,header='',local_ns=None,global_ns,dummy=None) -> Start |
|
167 | 167 | the interpreter shell with the given local and global namespaces, and |
|
168 | 168 | optionally print a header string at startup. |
|
169 | 169 | |
|
170 | 170 | The shell can be globally activated/deactivated using the |
|
171 | 171 | set/get_dummy_mode methods. This allows you to turn off a shell used |
|
172 | 172 | for debugging globally. |
|
173 | 173 | |
|
174 | 174 | However, *each* time you call the shell you can override the current |
|
175 | 175 | state of dummy_mode with the optional keyword parameter 'dummy'. For |
|
176 | 176 | example, if you set dummy mode on with IPShell.set_dummy_mode(1), you |
|
177 | 177 | can still have a specific call work by making it as IPShell(dummy=0). |
|
178 | 178 | |
|
179 | 179 | The optional keyword parameter dummy controls whether the call |
|
180 | 180 | actually does anything. """ |
|
181 | 181 | |
|
182 | 182 | # Allow the dummy parameter to override the global __dummy_mode |
|
183 | 183 | if dummy or (dummy != 0 and self.__dummy_mode): |
|
184 | 184 | return |
|
185 | 185 | |
|
186 | 186 | # Set global subsystems (display,completions) to our values |
|
187 | 187 | sys.displayhook = self.sys_displayhook_embed |
|
188 | 188 | if self.IP.has_readline: |
|
189 | 189 | self.IP.readline.set_completer(self.IP.Completer.complete) |
|
190 | 190 | |
|
191 | 191 | if self.banner and header: |
|
192 | 192 | format = '%s\n%s\n' |
|
193 | 193 | else: |
|
194 | 194 | format = '%s%s\n' |
|
195 | 195 | banner = format % (self.banner,header) |
|
196 | 196 | |
|
197 | 197 | # Call the embedding code with a stack depth of 1 so it can skip over |
|
198 | 198 | # our call and get the original caller's namespaces. |
|
199 | 199 | self.IP.embed_mainloop(banner,local_ns,global_ns,stack_depth=1) |
|
200 | 200 | |
|
201 | 201 | if self.exit_msg: |
|
202 | 202 | print self.exit_msg |
|
203 | 203 | |
|
204 | 204 | # Restore global systems (display, completion) |
|
205 | 205 | sys.displayhook = self.sys_displayhook_ori |
|
206 | 206 | self.restore_system_completer() |
|
207 | 207 | |
|
208 | 208 | def set_dummy_mode(self,dummy): |
|
209 | 209 | """Sets the embeddable shell's dummy mode parameter. |
|
210 | 210 | |
|
211 | 211 | set_dummy_mode(dummy): dummy = 0 or 1. |
|
212 | 212 | |
|
213 | 213 | This parameter is persistent and makes calls to the embeddable shell |
|
214 | 214 | silently return without performing any action. This allows you to |
|
215 | 215 | globally activate or deactivate a shell you're using with a single call. |
|
216 | 216 | |
|
217 | 217 | If you need to manually""" |
|
218 | 218 | |
|
219 | 219 | if dummy not in [0,1]: |
|
220 | 220 | raise ValueError,'dummy parameter must be 0 or 1' |
|
221 | 221 | self.__dummy_mode = dummy |
|
222 | 222 | |
|
223 | 223 | def get_dummy_mode(self): |
|
224 | 224 | """Return the current value of the dummy mode parameter. |
|
225 | 225 | """ |
|
226 | 226 | return self.__dummy_mode |
|
227 | 227 | |
|
228 | 228 | def set_banner(self,banner): |
|
229 | 229 | """Sets the global banner. |
|
230 | 230 | |
|
231 | 231 | This banner gets prepended to every header printed when the shell |
|
232 | 232 | instance is called.""" |
|
233 | 233 | |
|
234 | 234 | self.banner = banner |
|
235 | 235 | |
|
236 | 236 | def set_exit_msg(self,exit_msg): |
|
237 | 237 | """Sets the global exit_msg. |
|
238 | 238 | |
|
239 | 239 | This exit message gets printed upon exiting every time the embedded |
|
240 | 240 | shell is called. It is None by default. """ |
|
241 | 241 | |
|
242 | 242 | self.exit_msg = exit_msg |
|
243 | 243 | |
|
244 | 244 | #----------------------------------------------------------------------------- |
|
245 | 245 | def sigint_handler (signum,stack_frame): |
|
246 | 246 | """Sigint handler for threaded apps. |
|
247 | 247 | |
|
248 | 248 | This is a horrible hack to pass information about SIGINT _without_ using |
|
249 | 249 | exceptions, since I haven't been able to properly manage cross-thread |
|
250 | 250 | exceptions in GTK/WX. In fact, I don't think it can be done (or at least |
|
251 | 251 | that's my understanding from a c.l.py thread where this was discussed).""" |
|
252 | 252 | |
|
253 | 253 | global KBINT |
|
254 | 254 | |
|
255 | 255 | print '\nKeyboardInterrupt - Press <Enter> to continue.', |
|
256 | 256 | Term.cout.flush() |
|
257 | 257 | # Set global flag so that runsource can know that Ctrl-C was hit |
|
258 | 258 | KBINT = True |
|
259 | 259 | |
|
260 | 260 | class MTInteractiveShell(InteractiveShell): |
|
261 | 261 | """Simple multi-threaded shell.""" |
|
262 | 262 | |
|
263 | 263 | # Threading strategy taken from: |
|
264 | 264 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by Brian |
|
265 | 265 | # McErlean and John Finlay. Modified with corrections by Antoon Pardon, |
|
266 | 266 | # from the pygtk mailing list, to avoid lockups with system calls. |
|
267 | 267 | |
|
268 | 268 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
269 | 269 | user_ns = None, banner2='',**kw): |
|
270 | 270 | """Similar to the normal InteractiveShell, but with threading control""" |
|
271 | 271 | |
|
272 | 272 | IPython.iplib.InteractiveShell.__init__(self,name,usage,rc,user_ns,banner2) |
|
273 | 273 | |
|
274 | 274 | # Locking control variable |
|
275 | 275 | self.thread_ready = threading.Condition() |
|
276 | 276 | |
|
277 | 277 | # Stuff to do at closing time |
|
278 | 278 | self._kill = False |
|
279 | 279 | on_kill = kw.get('on_kill') |
|
280 | 280 | if on_kill is None: |
|
281 | 281 | on_kill = [] |
|
282 | 282 | # Check that all things to kill are callable: |
|
283 | 283 | for t in on_kill: |
|
284 | 284 | if not callable(t): |
|
285 | 285 | raise TypeError,'on_kill must be a list of callables' |
|
286 | 286 | self.on_kill = on_kill |
|
287 | 287 | |
|
288 | 288 | def runsource(self, source, filename="<input>", symbol="single"): |
|
289 | 289 | """Compile and run some source in the interpreter. |
|
290 | 290 | |
|
291 | 291 | Modified version of code.py's runsource(), to handle threading issues. |
|
292 | 292 | See the original for full docstring details.""" |
|
293 | 293 | |
|
294 | 294 | global KBINT |
|
295 | 295 | |
|
296 | 296 | # If Ctrl-C was typed, we reset the flag and return right away |
|
297 | 297 | if KBINT: |
|
298 | 298 | KBINT = False |
|
299 | 299 | return False |
|
300 | 300 | |
|
301 | 301 | try: |
|
302 | 302 | code = self.compile(source, filename, symbol) |
|
303 | 303 | except (OverflowError, SyntaxError, ValueError): |
|
304 | 304 | # Case 1 |
|
305 | 305 | self.showsyntaxerror(filename) |
|
306 | 306 | return False |
|
307 | 307 | |
|
308 | 308 | if code is None: |
|
309 | 309 | # Case 2 |
|
310 | 310 | return True |
|
311 | 311 | |
|
312 | 312 | # Case 3 |
|
313 | 313 | # Store code in self, so the execution thread can handle it |
|
314 | 314 | self.thread_ready.acquire() |
|
315 | self.code_to_run_src = source | |
|
316 | 315 | self.code_to_run = code |
|
317 | 316 | self.thread_ready.wait() # Wait until processed in timeout interval |
|
318 | 317 | self.thread_ready.release() |
|
319 | 318 | |
|
320 | 319 | return False |
|
321 | 320 | |
|
322 | 321 | def runcode(self): |
|
323 | 322 | """Execute a code object. |
|
324 | 323 | |
|
325 | 324 | Multithreaded wrapper around IPython's runcode().""" |
|
326 | 325 | |
|
327 | 326 | # lock thread-protected stuff |
|
328 | 327 | self.thread_ready.acquire() |
|
329 | 328 | |
|
330 | 329 | # Install sigint handler |
|
331 | 330 | try: |
|
332 | 331 | signal.signal(signal.SIGINT, sigint_handler) |
|
333 | 332 | except SystemError: |
|
334 | 333 | # This happens under Windows, which seems to have all sorts |
|
335 | 334 | # of problems with signal handling. Oh well... |
|
336 | 335 | pass |
|
337 | 336 | |
|
338 | 337 | if self._kill: |
|
339 | 338 | print >>Term.cout, 'Closing threads...', |
|
340 | 339 | Term.cout.flush() |
|
341 | 340 | for tokill in self.on_kill: |
|
342 | 341 | tokill() |
|
343 | 342 | print >>Term.cout, 'Done.' |
|
344 | 343 | |
|
345 | 344 | # Run pending code by calling parent class |
|
346 | 345 | if self.code_to_run is not None: |
|
347 | 346 | self.thread_ready.notify() |
|
348 | 347 | InteractiveShell.runcode(self,self.code_to_run) |
|
349 | 348 | |
|
350 | 349 | # We're done with thread-protected variables |
|
351 | 350 | self.thread_ready.release() |
|
352 | 351 | # This MUST return true for gtk threading to work |
|
353 | 352 | return True |
|
354 | 353 | |
|
355 | 354 | def kill (self): |
|
356 | 355 | """Kill the thread, returning when it has been shut down.""" |
|
357 | 356 | self.thread_ready.acquire() |
|
358 | 357 | self._kill = True |
|
359 | 358 | self.thread_ready.release() |
|
360 | 359 | |
|
361 | 360 | class MatplotlibShellBase: |
|
362 | 361 | """Mixin class to provide the necessary modifications to regular IPython |
|
363 | 362 | shell classes for matplotlib support. |
|
364 | 363 | |
|
365 | 364 | Given Python's MRO, this should be used as the FIRST class in the |
|
366 | 365 | inheritance hierarchy, so that it overrides the relevant methods.""" |
|
367 | 366 | |
|
368 | 367 | def _matplotlib_config(self,name): |
|
369 | 368 | """Return various items needed to setup the user's shell with matplotlib""" |
|
370 | 369 | |
|
371 | 370 | # Initialize matplotlib to interactive mode always |
|
372 | 371 | import matplotlib |
|
373 | 372 | from matplotlib import backends |
|
374 | 373 | matplotlib.interactive(True) |
|
375 | 374 | |
|
376 | 375 | def use(arg): |
|
377 | 376 | """IPython wrapper for matplotlib's backend switcher. |
|
378 | 377 | |
|
379 | 378 | In interactive use, we can not allow switching to a different |
|
380 | 379 | interactive backend, since thread conflicts will most likely crash |
|
381 | 380 | the python interpreter. This routine does a safety check first, |
|
382 | 381 | and refuses to perform a dangerous switch. It still allows |
|
383 | 382 | switching to non-interactive backends.""" |
|
384 | 383 | |
|
385 | 384 | if arg in backends.interactive_bk and arg != self.mpl_backend: |
|
386 | 385 | m=('invalid matplotlib backend switch.\n' |
|
387 | 386 | 'This script attempted to switch to the interactive ' |
|
388 | 387 | 'backend: `%s`\n' |
|
389 | 388 | 'Your current choice of interactive backend is: `%s`\n\n' |
|
390 | 389 | 'Switching interactive matplotlib backends at runtime\n' |
|
391 | 390 | 'would crash the python interpreter, ' |
|
392 | 391 | 'and IPython has blocked it.\n\n' |
|
393 | 392 | 'You need to either change your choice of matplotlib backend\n' |
|
394 | 393 | 'by editing your .matplotlibrc file, or run this script as a \n' |
|
395 | 394 | 'standalone file from the command line, not using IPython.\n' % |
|
396 | 395 | (arg,self.mpl_backend) ) |
|
397 | 396 | raise RuntimeError, m |
|
398 | 397 | else: |
|
399 | 398 | self.mpl_use(arg) |
|
400 | 399 | self.mpl_use._called = True |
|
401 | 400 | |
|
402 | 401 | self.matplotlib = matplotlib |
|
403 | 402 | self.mpl_backend = matplotlib.rcParams['backend'] |
|
404 | 403 | |
|
405 | 404 | # we also need to block switching of interactive backends by use() |
|
406 | 405 | self.mpl_use = matplotlib.use |
|
407 | 406 | self.mpl_use._called = False |
|
408 | 407 | # overwrite the original matplotlib.use with our wrapper |
|
409 | 408 | matplotlib.use = use |
|
410 | 409 | |
|
411 | 410 | |
|
412 | 411 | # This must be imported last in the matplotlib series, after |
|
413 | 412 | # backend/interactivity choices have been made |
|
414 | 413 | try: |
|
415 | 414 | import matplotlib.pylab as pylab |
|
416 | 415 | self.pylab = pylab |
|
417 | 416 | self.pylab_name = 'pylab' |
|
418 | 417 | except ImportError: |
|
419 | 418 | import matplotlib.matlab as matlab |
|
420 | 419 | self.pylab = matlab |
|
421 | 420 | self.pylab_name = 'matlab' |
|
422 | 421 | |
|
423 | 422 | self.pylab.show._needmain = False |
|
424 | 423 | # We need to detect at runtime whether show() is called by the user. |
|
425 | 424 | # For this, we wrap it into a decorator which adds a 'called' flag. |
|
426 | 425 | self.pylab.draw_if_interactive = flag_calls(self.pylab.draw_if_interactive) |
|
427 | 426 | |
|
428 | 427 | # Build a user namespace initialized with matplotlib/matlab features. |
|
429 | 428 | user_ns = {'__name__':'__main__', |
|
430 | 429 | '__builtins__' : __builtin__ } |
|
431 | 430 | |
|
432 | 431 | # Be careful not to remove the final \n in the code string below, or |
|
433 | 432 | # things will break badly with py22 (I think it's a python bug, 2.3 is |
|
434 | 433 | # OK). |
|
435 | 434 | pname = self.pylab_name # Python can't interpolate dotted var names |
|
436 | 435 | exec ("import matplotlib\n" |
|
437 | 436 | "import matplotlib.%(pname)s as %(pname)s\n" |
|
438 | 437 | "from matplotlib.%(pname)s import *\n" % locals()) in user_ns |
|
439 | 438 | |
|
440 | 439 | # Build matplotlib info banner |
|
441 | 440 | b=""" |
|
442 | 441 | Welcome to pylab, a matplotlib-based Python environment. |
|
443 | 442 | For more information, type 'help(pylab)'. |
|
444 | 443 | """ |
|
445 | 444 | return user_ns,b |
|
446 | 445 | |
|
447 | 446 | def mplot_exec(self,fname,*where,**kw): |
|
448 | 447 | """Execute a matplotlib script. |
|
449 | 448 | |
|
450 | 449 | This is a call to execfile(), but wrapped in safeties to properly |
|
451 | 450 | handle interactive rendering and backend switching.""" |
|
452 | 451 | |
|
453 | 452 | #print '*** Matplotlib runner ***' # dbg |
|
454 | 453 | # turn off rendering until end of script |
|
455 | 454 | isInteractive = self.matplotlib.rcParams['interactive'] |
|
456 | 455 | self.matplotlib.interactive(False) |
|
457 | 456 | self.safe_execfile(fname,*where,**kw) |
|
458 | 457 | self.matplotlib.interactive(isInteractive) |
|
459 | 458 | # make rendering call now, if the user tried to do it |
|
460 | 459 | if self.pylab.draw_if_interactive.called: |
|
461 | 460 | self.pylab.draw() |
|
462 | 461 | self.pylab.draw_if_interactive.called = False |
|
463 | 462 | |
|
464 | 463 | # if a backend switch was performed, reverse it now |
|
465 | 464 | if self.mpl_use._called: |
|
466 | 465 | self.matplotlib.rcParams['backend'] = self.mpl_backend |
|
467 | 466 | |
|
468 | 467 | def magic_run(self,parameter_s=''): |
|
469 | 468 | Magic.magic_run(self,parameter_s,runner=self.mplot_exec) |
|
470 | 469 | |
|
471 | 470 | # Fix the docstring so users see the original as well |
|
472 | 471 | magic_run.__doc__ = "%s\n%s" % (Magic.magic_run.__doc__, |
|
473 | 472 | "\n *** Modified %run for Matplotlib," |
|
474 | 473 | " with proper interactive handling ***") |
|
475 | 474 | |
|
476 | 475 | # Now we provide 2 versions of a matplotlib-aware IPython base shells, single |
|
477 | 476 | # and multithreaded. Note that these are meant for internal use, the IPShell* |
|
478 | 477 | # classes below are the ones meant for public consumption. |
|
479 | 478 | |
|
480 | 479 | class MatplotlibShell(MatplotlibShellBase,InteractiveShell): |
|
481 | 480 | """Single-threaded shell with matplotlib support.""" |
|
482 | 481 | |
|
483 | 482 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
484 | 483 | user_ns = None, **kw): |
|
485 | 484 | user_ns,b2 = self._matplotlib_config(name) |
|
486 | 485 | InteractiveShell.__init__(self,name,usage,rc,user_ns,banner2=b2,**kw) |
|
487 | 486 | |
|
488 | 487 | class MatplotlibMTShell(MatplotlibShellBase,MTInteractiveShell): |
|
489 | 488 | """Multi-threaded shell with matplotlib support.""" |
|
490 | 489 | |
|
491 | 490 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
492 | 491 | user_ns = None, **kw): |
|
493 | 492 | user_ns,b2 = self._matplotlib_config(name) |
|
494 | 493 | MTInteractiveShell.__init__(self,name,usage,rc,user_ns,banner2=b2,**kw) |
|
495 | 494 | |
|
496 | 495 | #----------------------------------------------------------------------------- |
|
497 | 496 | # Utility functions for the different GUI enabled IPShell* classes. |
|
498 | 497 | |
|
499 | 498 | def get_tk(): |
|
500 | 499 | """Tries to import Tkinter and returns a withdrawn Tkinter root |
|
501 | 500 | window. If Tkinter is already imported or not available, this |
|
502 | 501 | returns None. This function calls `hijack_tk` underneath. |
|
503 | 502 | """ |
|
504 | 503 | if not USE_TK or sys.modules.has_key('Tkinter'): |
|
505 | 504 | return None |
|
506 | 505 | else: |
|
507 | 506 | try: |
|
508 | 507 | import Tkinter |
|
509 | 508 | except ImportError: |
|
510 | 509 | return None |
|
511 | 510 | else: |
|
512 | 511 | hijack_tk() |
|
513 | 512 | r = Tkinter.Tk() |
|
514 | 513 | r.withdraw() |
|
515 | 514 | return r |
|
516 | 515 | |
|
517 | 516 | def hijack_tk(): |
|
518 | 517 | """Modifies Tkinter's mainloop with a dummy so when a module calls |
|
519 | 518 | mainloop, it does not block. |
|
520 | 519 | |
|
521 | 520 | """ |
|
522 | 521 | def misc_mainloop(self, n=0): |
|
523 | 522 | pass |
|
524 | 523 | def tkinter_mainloop(n=0): |
|
525 | 524 | pass |
|
526 | 525 | |
|
527 | 526 | import Tkinter |
|
528 | 527 | Tkinter.Misc.mainloop = misc_mainloop |
|
529 | 528 | Tkinter.mainloop = tkinter_mainloop |
|
530 | 529 | |
|
531 | 530 | def update_tk(tk): |
|
532 | 531 | """Updates the Tkinter event loop. This is typically called from |
|
533 | 532 | the respective WX or GTK mainloops. |
|
534 | 533 | """ |
|
535 | 534 | if tk: |
|
536 | 535 | tk.update() |
|
537 | 536 | |
|
538 | 537 | def hijack_wx(): |
|
539 | 538 | """Modifies wxPython's MainLoop with a dummy so user code does not |
|
540 | 539 | block IPython. The hijacked mainloop function is returned. |
|
541 | 540 | """ |
|
542 | 541 | def dummy_mainloop(*args, **kw): |
|
543 | 542 | pass |
|
544 | 543 | import wxPython |
|
545 | 544 | ver = wxPython.__version__ |
|
546 | 545 | orig_mainloop = None |
|
547 | 546 | if ver[:3] >= '2.5': |
|
548 | 547 | import wx |
|
549 | 548 | if hasattr(wx, '_core_'): core = getattr(wx, '_core_') |
|
550 | 549 | elif hasattr(wx, '_core'): core = getattr(wx, '_core') |
|
551 | 550 | else: raise AttributeError('Could not find wx core module') |
|
552 | 551 | orig_mainloop = core.PyApp_MainLoop |
|
553 | 552 | core.PyApp_MainLoop = dummy_mainloop |
|
554 | 553 | elif ver[:3] == '2.4': |
|
555 | 554 | orig_mainloop = wxPython.wxc.wxPyApp_MainLoop |
|
556 | 555 | wxPython.wxc.wxPyApp_MainLoop = dummy_mainloop |
|
557 | 556 | else: |
|
558 | 557 | warn("Unable to find either wxPython version 2.4 or >= 2.5.") |
|
559 | 558 | return orig_mainloop |
|
560 | 559 | |
|
561 | 560 | def hijack_gtk(): |
|
562 | 561 | """Modifies pyGTK's mainloop with a dummy so user code does not |
|
563 | 562 | block IPython. This function returns the original `gtk.mainloop` |
|
564 | 563 | function that has been hijacked. |
|
565 | 564 | |
|
566 | 565 | NOTE: Make sure you import this *AFTER* you call |
|
567 | 566 | pygtk.require(...). |
|
568 | 567 | """ |
|
569 | 568 | def dummy_mainloop(*args, **kw): |
|
570 | 569 | pass |
|
571 | 570 | import gtk |
|
572 | 571 | if gtk.pygtk_version >= (2,4,0): orig_mainloop = gtk.main |
|
573 | 572 | else: orig_mainloop = gtk.mainloop |
|
574 | 573 | gtk.mainloop = dummy_mainloop |
|
575 | 574 | gtk.main = dummy_mainloop |
|
576 | 575 | return orig_mainloop |
|
577 | 576 | |
|
578 | 577 | #----------------------------------------------------------------------------- |
|
579 | 578 | # The IPShell* classes below are the ones meant to be run by external code as |
|
580 | 579 | # IPython instances. Note that unless a specific threading strategy is |
|
581 | 580 | # desired, the factory function start() below should be used instead (it |
|
582 | 581 | # selects the proper threaded class). |
|
583 | 582 | |
|
584 | 583 | class IPShellGTK(threading.Thread): |
|
585 | 584 | """Run a gtk mainloop() in a separate thread. |
|
586 | 585 | |
|
587 | 586 | Python commands can be passed to the thread where they will be executed. |
|
588 | 587 | This is implemented by periodically checking for passed code using a |
|
589 | 588 | GTK timeout callback.""" |
|
590 | 589 | |
|
591 | 590 | TIMEOUT = 100 # Millisecond interval between timeouts. |
|
592 | 591 | |
|
593 | 592 | def __init__(self,argv=None,user_ns=None,debug=1, |
|
594 | 593 | shell_class=MTInteractiveShell): |
|
595 | 594 | |
|
596 | 595 | import pygtk |
|
597 | 596 | pygtk.require("2.0") |
|
598 | 597 | import gtk |
|
599 | 598 | |
|
600 | 599 | self.gtk = gtk |
|
601 | 600 | self.gtk_mainloop = hijack_gtk() |
|
602 | 601 | |
|
603 | 602 | # Allows us to use both Tk and GTK. |
|
604 | 603 | self.tk = get_tk() |
|
605 | 604 | |
|
606 | 605 | if gtk.pygtk_version >= (2,4,0): mainquit = self.gtk.main_quit |
|
607 | 606 | else: mainquit = self.gtk.mainquit |
|
608 | 607 | |
|
609 | 608 | self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, |
|
610 | 609 | shell_class=shell_class, |
|
611 | 610 | on_kill=[mainquit]) |
|
612 | 611 | threading.Thread.__init__(self) |
|
613 | 612 | |
|
614 | 613 | def run(self): |
|
615 | 614 | self.IP.mainloop() |
|
616 | 615 | self.IP.kill() |
|
617 | 616 | |
|
618 | 617 | def mainloop(self): |
|
619 | 618 | |
|
620 | 619 | if self.gtk.pygtk_version >= (2,4,0): |
|
621 | 620 | import gobject |
|
622 | 621 | gobject.timeout_add(self.TIMEOUT, self.on_timer) |
|
623 | 622 | else: |
|
624 | 623 | self.gtk.timeout_add(self.TIMEOUT, self.on_timer) |
|
625 | 624 | |
|
626 | 625 | if sys.platform != 'win32': |
|
627 | 626 | try: |
|
628 | 627 | if self.gtk.gtk_version[0] >= 2: |
|
629 | 628 | self.gtk.threads_init() |
|
630 | 629 | except AttributeError: |
|
631 | 630 | pass |
|
632 | 631 | except RuntimeError: |
|
633 | 632 | error('Your pyGTK likely has not been compiled with ' |
|
634 | 633 | 'threading support.\n' |
|
635 | 634 | 'The exception printout is below.\n' |
|
636 | 635 | 'You can either rebuild pyGTK with threads, or ' |
|
637 | 636 | 'try using \n' |
|
638 | 637 | 'matplotlib with a different backend (like Tk or WX).\n' |
|
639 | 638 | 'Note that matplotlib will most likely not work in its ' |
|
640 | 639 | 'current state!') |
|
641 | 640 | self.IP.InteractiveTB() |
|
642 | 641 | self.start() |
|
643 | 642 | self.gtk.threads_enter() |
|
644 | 643 | self.gtk_mainloop() |
|
645 | 644 | self.gtk.threads_leave() |
|
646 | 645 | self.join() |
|
647 | 646 | |
|
648 | 647 | def on_timer(self): |
|
649 | 648 | update_tk(self.tk) |
|
650 | 649 | return self.IP.runcode() |
|
651 | 650 | |
|
652 | 651 | |
|
653 | 652 | class IPShellWX(threading.Thread): |
|
654 | 653 | """Run a wx mainloop() in a separate thread. |
|
655 | 654 | |
|
656 | 655 | Python commands can be passed to the thread where they will be executed. |
|
657 | 656 | This is implemented by periodically checking for passed code using a |
|
658 | 657 | GTK timeout callback.""" |
|
659 | 658 | |
|
660 | 659 | TIMEOUT = 100 # Millisecond interval between timeouts. |
|
661 | 660 | |
|
662 | 661 | def __init__(self,argv=None,user_ns=None,debug=1, |
|
663 | 662 | shell_class=MTInteractiveShell): |
|
664 | 663 | |
|
665 | 664 | import wxPython.wx as wx |
|
666 | 665 | |
|
667 | 666 | threading.Thread.__init__(self) |
|
668 | 667 | self.wx = wx |
|
669 | 668 | self.wx_mainloop = hijack_wx() |
|
670 | 669 | |
|
671 | 670 | # Allows us to use both Tk and GTK. |
|
672 | 671 | self.tk = get_tk() |
|
673 | 672 | |
|
674 | 673 | self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, |
|
675 | 674 | shell_class=shell_class, |
|
676 | 675 | on_kill=[self.wxexit]) |
|
677 | 676 | self.app = None |
|
678 | 677 | |
|
679 | 678 | def wxexit(self, *args): |
|
680 | 679 | if self.app is not None: |
|
681 | 680 | self.app.agent.timer.Stop() |
|
682 | 681 | self.app.ExitMainLoop() |
|
683 | 682 | |
|
684 | 683 | def run(self): |
|
685 | 684 | self.IP.mainloop() |
|
686 | 685 | self.IP.kill() |
|
687 | 686 | |
|
688 | 687 | def mainloop(self): |
|
689 | 688 | |
|
690 | 689 | self.start() |
|
691 | 690 | |
|
692 | 691 | class TimerAgent(self.wx.wxMiniFrame): |
|
693 | 692 | wx = self.wx |
|
694 | 693 | IP = self.IP |
|
695 | 694 | tk = self.tk |
|
696 | 695 | def __init__(self, parent, interval): |
|
697 | 696 | style = self.wx.wxDEFAULT_FRAME_STYLE | self.wx.wxTINY_CAPTION_HORIZ |
|
698 | 697 | self.wx.wxMiniFrame.__init__(self, parent, -1, ' ', pos=(200, 200), |
|
699 | 698 | size=(100, 100),style=style) |
|
700 | 699 | self.Show(False) |
|
701 | 700 | self.interval = interval |
|
702 | 701 | self.timerId = self.wx.wxNewId() |
|
703 | 702 | |
|
704 | 703 | def StartWork(self): |
|
705 | 704 | self.timer = self.wx.wxTimer(self, self.timerId) |
|
706 | 705 | self.wx.EVT_TIMER(self, self.timerId, self.OnTimer) |
|
707 | 706 | self.timer.Start(self.interval) |
|
708 | 707 | |
|
709 | 708 | def OnTimer(self, event): |
|
710 | 709 | update_tk(self.tk) |
|
711 | 710 | self.IP.runcode() |
|
712 | 711 | |
|
713 | 712 | class App(self.wx.wxApp): |
|
714 | 713 | wx = self.wx |
|
715 | 714 | TIMEOUT = self.TIMEOUT |
|
716 | 715 | def OnInit(self): |
|
717 | 716 | 'Create the main window and insert the custom frame' |
|
718 | 717 | self.agent = TimerAgent(None, self.TIMEOUT) |
|
719 | 718 | self.agent.Show(self.wx.false) |
|
720 | 719 | self.agent.StartWork() |
|
721 | 720 | return self.wx.true |
|
722 | 721 | |
|
723 | 722 | self.app = App(redirect=False) |
|
724 | 723 | self.wx_mainloop(self.app) |
|
725 | 724 | self.join() |
|
726 | 725 | |
|
727 | 726 | |
|
728 | 727 | class IPShellQt(threading.Thread): |
|
729 | 728 | """Run a Qt event loop in a separate thread. |
|
730 | 729 | |
|
731 | 730 | Python commands can be passed to the thread where they will be executed. |
|
732 | 731 | This is implemented by periodically checking for passed code using a |
|
733 | 732 | Qt timer / slot.""" |
|
734 | 733 | |
|
735 | 734 | TIMEOUT = 100 # Millisecond interval between timeouts. |
|
736 | 735 | |
|
737 | 736 | def __init__(self,argv=None,user_ns=None,debug=0, |
|
738 | 737 | shell_class=MTInteractiveShell): |
|
739 | 738 | |
|
740 | 739 | import qt |
|
741 | 740 | |
|
742 | 741 | class newQApplication: |
|
743 | 742 | def __init__( self ): |
|
744 | 743 | self.QApplication = qt.QApplication |
|
745 | 744 | |
|
746 | 745 | def __call__( *args, **kwargs ): |
|
747 | 746 | return qt.qApp |
|
748 | 747 | |
|
749 | 748 | def exec_loop( *args, **kwargs ): |
|
750 | 749 | pass |
|
751 | 750 | |
|
752 | 751 | def __getattr__( self, name ): |
|
753 | 752 | return getattr( self.QApplication, name ) |
|
754 | 753 | |
|
755 | 754 | qt.QApplication = newQApplication() |
|
756 | 755 | |
|
757 | 756 | # Allows us to use both Tk and QT. |
|
758 | 757 | self.tk = get_tk() |
|
759 | 758 | |
|
760 | 759 | self.IP = make_IPython(argv,user_ns=user_ns,debug=debug, |
|
761 | 760 | shell_class=shell_class, |
|
762 | 761 | on_kill=[qt.qApp.exit]) |
|
763 | 762 | |
|
764 | 763 | threading.Thread.__init__(self) |
|
765 | 764 | |
|
766 | 765 | def run(self): |
|
767 | 766 | #sys.excepthook = self.IP.excepthook # dbg |
|
768 | 767 | self.IP.mainloop() |
|
769 | 768 | self.IP.kill() |
|
770 | 769 | |
|
771 | 770 | def mainloop(self): |
|
772 | 771 | import qt, sys |
|
773 | 772 | if qt.QApplication.startingUp(): |
|
774 | 773 | a = qt.QApplication.QApplication( sys.argv ) |
|
775 | 774 | self.timer = qt.QTimer() |
|
776 | 775 | qt.QObject.connect( self.timer, qt.SIGNAL( 'timeout()' ), self.on_timer ) |
|
777 | 776 | |
|
778 | 777 | self.start() |
|
779 | 778 | self.timer.start( self.TIMEOUT, True ) |
|
780 | 779 | while True: |
|
781 | 780 | if self.IP._kill: break |
|
782 | 781 | qt.qApp.exec_loop() |
|
783 | 782 | self.join() |
|
784 | 783 | |
|
785 | 784 | def on_timer(self): |
|
786 | 785 | update_tk(self.tk) |
|
787 | 786 | result = self.IP.runcode() |
|
788 | 787 | self.timer.start( self.TIMEOUT, True ) |
|
789 | 788 | return result |
|
790 | 789 | |
|
791 | 790 | # A set of matplotlib public IPython shell classes, for single-threaded |
|
792 | 791 | # (Tk* and FLTK* backends) and multithreaded (GTK* and WX* backends) use. |
|
793 | 792 | class IPShellMatplotlib(IPShell): |
|
794 | 793 | """Subclass IPShell with MatplotlibShell as the internal shell. |
|
795 | 794 | |
|
796 | 795 | Single-threaded class, meant for the Tk* and FLTK* backends. |
|
797 | 796 | |
|
798 | 797 | Having this on a separate class simplifies the external driver code.""" |
|
799 | 798 | |
|
800 | 799 | def __init__(self,argv=None,user_ns=None,debug=1): |
|
801 | 800 | IPShell.__init__(self,argv,user_ns,debug,shell_class=MatplotlibShell) |
|
802 | 801 | |
|
803 | 802 | class IPShellMatplotlibGTK(IPShellGTK): |
|
804 | 803 | """Subclass IPShellGTK with MatplotlibMTShell as the internal shell. |
|
805 | 804 | |
|
806 | 805 | Multi-threaded class, meant for the GTK* backends.""" |
|
807 | 806 | |
|
808 | 807 | def __init__(self,argv=None,user_ns=None,debug=1): |
|
809 | 808 | IPShellGTK.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell) |
|
810 | 809 | |
|
811 | 810 | class IPShellMatplotlibWX(IPShellWX): |
|
812 | 811 | """Subclass IPShellWX with MatplotlibMTShell as the internal shell. |
|
813 | 812 | |
|
814 | 813 | Multi-threaded class, meant for the WX* backends.""" |
|
815 | 814 | |
|
816 | 815 | def __init__(self,argv=None,user_ns=None,debug=1): |
|
817 | 816 | IPShellWX.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell) |
|
818 | 817 | |
|
819 | 818 | class IPShellMatplotlibQt(IPShellQt): |
|
820 | 819 | """Subclass IPShellQt with MatplotlibMTShell as the internal shell. |
|
821 | 820 | |
|
822 | 821 | Multi-threaded class, meant for the Qt* backends.""" |
|
823 | 822 | |
|
824 | 823 | def __init__(self,argv=None,user_ns=None,debug=1): |
|
825 | 824 | IPShellQt.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell) |
|
826 | 825 | |
|
827 | 826 | #----------------------------------------------------------------------------- |
|
828 | 827 | # Factory functions to actually start the proper thread-aware shell |
|
829 | 828 | |
|
830 | 829 | def _matplotlib_shell_class(): |
|
831 | 830 | """Factory function to handle shell class selection for matplotlib. |
|
832 | 831 | |
|
833 | 832 | The proper shell class to use depends on the matplotlib backend, since |
|
834 | 833 | each backend requires a different threading strategy.""" |
|
835 | 834 | |
|
836 | 835 | try: |
|
837 | 836 | import matplotlib |
|
838 | 837 | except ImportError: |
|
839 | 838 | error('matplotlib could NOT be imported! Starting normal IPython.') |
|
840 | 839 | sh_class = IPShell |
|
841 | 840 | else: |
|
842 | 841 | backend = matplotlib.rcParams['backend'] |
|
843 | 842 | if backend.startswith('GTK'): |
|
844 | 843 | sh_class = IPShellMatplotlibGTK |
|
845 | 844 | elif backend.startswith('WX'): |
|
846 | 845 | sh_class = IPShellMatplotlibWX |
|
847 | 846 | elif backend.startswith('Qt'): |
|
848 | 847 | sh_class = IPShellMatplotlibQt |
|
849 | 848 | else: |
|
850 | 849 | sh_class = IPShellMatplotlib |
|
851 | 850 | #print 'Using %s with the %s backend.' % (sh_class,backend) # dbg |
|
852 | 851 | return sh_class |
|
853 | 852 | |
|
854 | 853 | # This is the one which should be called by external code. |
|
855 | 854 | def start(): |
|
856 | 855 | """Return a running shell instance, dealing with threading options. |
|
857 | 856 | |
|
858 | 857 | This is a factory function which will instantiate the proper IPython shell |
|
859 | 858 | based on the user's threading choice. Such a selector is needed because |
|
860 | 859 | different GUI toolkits require different thread handling details.""" |
|
861 | 860 | |
|
862 | 861 | global USE_TK |
|
863 | 862 | # Crude sys.argv hack to extract the threading options. |
|
864 | 863 | if len(sys.argv) > 1: |
|
865 | 864 | if len(sys.argv) > 2: |
|
866 | 865 | arg2 = sys.argv[2] |
|
867 | 866 | if arg2.endswith('-tk'): |
|
868 | 867 | USE_TK = True |
|
869 | 868 | arg1 = sys.argv[1] |
|
870 | 869 | if arg1.endswith('-gthread'): |
|
871 | 870 | shell = IPShellGTK |
|
872 | 871 | elif arg1.endswith( '-qthread' ): |
|
873 | 872 | shell = IPShellQt |
|
874 | 873 | elif arg1.endswith('-wthread'): |
|
875 | 874 | shell = IPShellWX |
|
876 | 875 | elif arg1.endswith('-pylab'): |
|
877 | 876 | shell = _matplotlib_shell_class() |
|
878 | 877 | else: |
|
879 | 878 | shell = IPShell |
|
880 | 879 | else: |
|
881 | 880 | shell = IPShell |
|
882 | 881 | return shell() |
|
883 | 882 | |
|
884 | 883 | # Some aliases for backwards compatibility |
|
885 | 884 | IPythonShell = IPShell |
|
886 | 885 | IPythonShellEmbed = IPShellEmbed |
|
887 | 886 | #************************ End of file <Shell.py> *************************** |
@@ -1,1520 +1,1521 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | General purpose utilities. |
|
4 | 4 | |
|
5 | 5 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
|
6 | 6 | these things are also convenient when working at the command line. |
|
7 | 7 | |
|
8 |
$Id: genutils.py |
|
|
8 | $Id: genutils.py 703 2005-08-16 17:34:44Z fperez $""" | |
|
9 | 9 | |
|
10 | 10 | #***************************************************************************** |
|
11 | 11 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
12 | 12 | # |
|
13 | 13 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | 14 | # the file COPYING, distributed as part of this software. |
|
15 | 15 | #***************************************************************************** |
|
16 | 16 | |
|
17 | from __future__ import generators # 2.2 compatibility | |
|
18 | ||
|
17 | 19 | from IPython import Release |
|
18 | 20 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
19 | 21 | __license__ = Release.license |
|
20 | 22 | |
|
21 | 23 | #**************************************************************************** |
|
22 | 24 | # required modules |
|
23 | 25 | import __main__ |
|
24 | 26 | import types,commands,time,sys,os,re,shutil |
|
25 | 27 | import tempfile |
|
26 | import codecs | |
|
27 | 28 | from IPython.Itpl import Itpl,itpl,printpl |
|
28 | 29 | from IPython import DPyGetOpt |
|
29 | 30 | |
|
30 | 31 | # Build objects which appeared in Python 2.3 for 2.2, to make ipython |
|
31 | 32 | # 2.2-friendly |
|
32 | 33 | try: |
|
33 | 34 | basestring |
|
34 | 35 | except NameError: |
|
35 | 36 | import types |
|
36 | 37 | basestring = (types.StringType, types.UnicodeType) |
|
37 | 38 | True = 1==1 |
|
38 | 39 | False = 1==0 |
|
39 | 40 | |
|
40 | 41 | def enumerate(obj): |
|
41 | 42 | i = -1 |
|
42 | 43 | for item in obj: |
|
43 | 44 | i += 1 |
|
44 | 45 | yield i, item |
|
45 | 46 | |
|
46 | 47 | # add these to the builtin namespace, so that all modules find them |
|
47 | 48 | import __builtin__ |
|
48 | 49 | __builtin__.basestring = basestring |
|
49 | 50 | __builtin__.True = True |
|
50 | 51 | __builtin__.False = False |
|
51 | 52 | __builtin__.enumerate = enumerate |
|
52 | 53 | |
|
53 | 54 | #**************************************************************************** |
|
54 | 55 | # Exceptions |
|
55 | 56 | class Error(Exception): |
|
56 | 57 | """Base class for exceptions in this module.""" |
|
57 | 58 | pass |
|
58 | 59 | |
|
59 | 60 | #---------------------------------------------------------------------------- |
|
60 | 61 | class IOStream: |
|
61 | 62 | def __init__(self,stream,fallback): |
|
62 | 63 | if not hasattr(stream,'write') or not hasattr(stream,'flush'): |
|
63 | 64 | stream = fallback |
|
64 | 65 | self.stream = stream |
|
65 | 66 | self._swrite = stream.write |
|
66 | 67 | self.flush = stream.flush |
|
67 | 68 | |
|
68 | 69 | def write(self,data): |
|
69 | 70 | try: |
|
70 | 71 | self._swrite(data) |
|
71 | 72 | except: |
|
72 | 73 | try: |
|
73 | 74 | # print handles some unicode issues which may trip a plain |
|
74 | 75 | # write() call. Attempt to emulate write() by using a |
|
75 | 76 | # trailing comma |
|
76 | 77 | print >> self.stream, data, |
|
77 | 78 | except: |
|
78 | 79 | # if we get here, something is seriously broken. |
|
79 | 80 | print >> sys.stderr, \ |
|
80 | 81 | 'ERROR - failed to write data to stream:', stream |
|
81 | 82 | |
|
82 | 83 | class IOTerm: |
|
83 | 84 | """ Term holds the file or file-like objects for handling I/O operations. |
|
84 | 85 | |
|
85 | 86 | These are normally just sys.stdin, sys.stdout and sys.stderr but for |
|
86 | 87 | Windows they can can replaced to allow editing the strings before they are |
|
87 | 88 | displayed.""" |
|
88 | 89 | |
|
89 | 90 | # In the future, having IPython channel all its I/O operations through |
|
90 | 91 | # this class will make it easier to embed it into other environments which |
|
91 | 92 | # are not a normal terminal (such as a GUI-based shell) |
|
92 | 93 | def __init__(self,cin=None,cout=None,cerr=None): |
|
93 | 94 | self.cin = IOStream(cin,sys.stdin) |
|
94 | 95 | self.cout = IOStream(cout,sys.stdout) |
|
95 | 96 | self.cerr = IOStream(cerr,sys.stderr) |
|
96 | 97 | |
|
97 | 98 | # Global variable to be used for all I/O |
|
98 | 99 | Term = IOTerm() |
|
99 | 100 | |
|
100 | 101 | # Windows-specific code to load Gary Bishop's readline and configure it |
|
101 | 102 | # automatically for the users |
|
102 | 103 | # Note: os.name on cygwin returns posix, so this should only pick up 'native' |
|
103 | 104 | # windows. Cygwin returns 'cygwin' for sys.platform. |
|
104 | 105 | if os.name == 'nt': |
|
105 | 106 | try: |
|
106 | 107 | import readline |
|
107 | 108 | except ImportError: |
|
108 | 109 | pass |
|
109 | 110 | else: |
|
110 | 111 | try: |
|
111 | 112 | _out = readline.GetOutputFile() |
|
112 | 113 | except AttributeError: |
|
113 | 114 | pass |
|
114 | 115 | else: |
|
115 | 116 | # Remake Term to use the readline i/o facilities |
|
116 | 117 | Term = IOTerm(cout=_out,cerr=_out) |
|
117 | 118 | del _out |
|
118 | 119 | |
|
119 | 120 | #**************************************************************************** |
|
120 | 121 | # Generic warning/error printer, used by everything else |
|
121 | 122 | def warn(msg,level=2,exit_val=1): |
|
122 | 123 | """Standard warning printer. Gives formatting consistency. |
|
123 | 124 | |
|
124 | 125 | Output is sent to Term.cerr (sys.stderr by default). |
|
125 | 126 | |
|
126 | 127 | Options: |
|
127 | 128 | |
|
128 | 129 | -level(2): allows finer control: |
|
129 | 130 | 0 -> Do nothing, dummy function. |
|
130 | 131 | 1 -> Print message. |
|
131 | 132 | 2 -> Print 'WARNING:' + message. (Default level). |
|
132 | 133 | 3 -> Print 'ERROR:' + message. |
|
133 | 134 | 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val). |
|
134 | 135 | |
|
135 | 136 | -exit_val (1): exit value returned by sys.exit() for a level 4 |
|
136 | 137 | warning. Ignored for all other levels.""" |
|
137 | 138 | |
|
138 | 139 | if level>0: |
|
139 | 140 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
140 | 141 | print >> Term.cerr, '%s%s' % (header[level],msg) |
|
141 | 142 | if level == 4: |
|
142 | 143 | print >> Term.cerr,'Exiting.\n' |
|
143 | 144 | sys.exit(exit_val) |
|
144 | 145 | |
|
145 | 146 | def info(msg): |
|
146 | 147 | """Equivalent to warn(msg,level=1).""" |
|
147 | 148 | |
|
148 | 149 | warn(msg,level=1) |
|
149 | 150 | |
|
150 | 151 | def error(msg): |
|
151 | 152 | """Equivalent to warn(msg,level=3).""" |
|
152 | 153 | |
|
153 | 154 | warn(msg,level=3) |
|
154 | 155 | |
|
155 | 156 | def fatal(msg,exit_val=1): |
|
156 | 157 | """Equivalent to warn(msg,exit_val=exit_val,level=4).""" |
|
157 | 158 | |
|
158 | 159 | warn(msg,exit_val=exit_val,level=4) |
|
159 | 160 | |
|
160 | 161 | #---------------------------------------------------------------------------- |
|
161 | 162 | StringTypes = types.StringTypes |
|
162 | 163 | |
|
163 | 164 | # Basic timing functionality |
|
164 | 165 | |
|
165 | 166 | # If possible (Unix), use the resource module instead of time.clock() |
|
166 | 167 | try: |
|
167 | 168 | import resource |
|
168 | 169 | def clock(): |
|
169 | 170 | """clock() -> floating point number |
|
170 | 171 | |
|
171 | 172 | Return the CPU time in seconds (user time only, system time is |
|
172 | 173 | ignored) since the start of the process. This is done via a call to |
|
173 | 174 | resource.getrusage, so it avoids the wraparound problems in |
|
174 | 175 | time.clock().""" |
|
175 | 176 | |
|
176 | 177 | return resource.getrusage(resource.RUSAGE_SELF)[0] |
|
177 | 178 | |
|
178 | 179 | def clock2(): |
|
179 | 180 | """clock2() -> (t_user,t_system) |
|
180 | 181 | |
|
181 | 182 | Similar to clock(), but return a tuple of user/system times.""" |
|
182 | 183 | return resource.getrusage(resource.RUSAGE_SELF)[:2] |
|
183 | 184 | |
|
184 | 185 | except ImportError: |
|
185 | 186 | clock = time.clock |
|
186 | 187 | def clock2(): |
|
187 | 188 | """Under windows, system CPU time can't be measured. |
|
188 | 189 | |
|
189 | 190 | This just returns clock() and zero.""" |
|
190 | 191 | return time.clock(),0.0 |
|
191 | 192 | |
|
192 | 193 | def timings_out(reps,func,*args,**kw): |
|
193 | 194 | """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) |
|
194 | 195 | |
|
195 | 196 | Execute a function reps times, return a tuple with the elapsed total |
|
196 | 197 | CPU time in seconds, the time per call and the function's output. |
|
197 | 198 | |
|
198 | 199 | Under Unix, the return value is the sum of user+system time consumed by |
|
199 | 200 | the process, computed via the resource module. This prevents problems |
|
200 | 201 | related to the wraparound effect which the time.clock() function has. |
|
201 | 202 | |
|
202 | 203 | Under Windows the return value is in wall clock seconds. See the |
|
203 | 204 | documentation for the time module for more details.""" |
|
204 | 205 | |
|
205 | 206 | reps = int(reps) |
|
206 | 207 | assert reps >=1, 'reps must be >= 1' |
|
207 | 208 | if reps==1: |
|
208 | 209 | start = clock() |
|
209 | 210 | out = func(*args,**kw) |
|
210 | 211 | tot_time = clock()-start |
|
211 | 212 | else: |
|
212 | 213 | rng = xrange(reps-1) # the last time is executed separately to store output |
|
213 | 214 | start = clock() |
|
214 | 215 | for dummy in rng: func(*args,**kw) |
|
215 | 216 | out = func(*args,**kw) # one last time |
|
216 | 217 | tot_time = clock()-start |
|
217 | 218 | av_time = tot_time / reps |
|
218 | 219 | return tot_time,av_time,out |
|
219 | 220 | |
|
220 | 221 | def timings(reps,func,*args,**kw): |
|
221 | 222 | """timings(reps,func,*args,**kw) -> (t_total,t_per_call) |
|
222 | 223 | |
|
223 | 224 | Execute a function reps times, return a tuple with the elapsed total CPU |
|
224 | 225 | time in seconds and the time per call. These are just the first two values |
|
225 | 226 | in timings_out().""" |
|
226 | 227 | |
|
227 | 228 | return timings_out(reps,func,*args,**kw)[0:2] |
|
228 | 229 | |
|
229 | 230 | def timing(func,*args,**kw): |
|
230 | 231 | """timing(func,*args,**kw) -> t_total |
|
231 | 232 | |
|
232 | 233 | Execute a function once, return the elapsed total CPU time in |
|
233 | 234 | seconds. This is just the first value in timings_out().""" |
|
234 | 235 | |
|
235 | 236 | return timings_out(1,func,*args,**kw)[0] |
|
236 | 237 | |
|
237 | 238 | #**************************************************************************** |
|
238 | 239 | # file and system |
|
239 | 240 | |
|
240 | 241 | def system(cmd,verbose=0,debug=0,header=''): |
|
241 | 242 | """Execute a system command, return its exit status. |
|
242 | 243 | |
|
243 | 244 | Options: |
|
244 | 245 | |
|
245 | 246 | - verbose (0): print the command to be executed. |
|
246 | 247 | |
|
247 | 248 | - debug (0): only print, do not actually execute. |
|
248 | 249 | |
|
249 | 250 | - header (''): Header to print on screen prior to the executed command (it |
|
250 | 251 | is only prepended to the command, no newlines are added). |
|
251 | 252 | |
|
252 | 253 | Note: a stateful version of this function is available through the |
|
253 | 254 | SystemExec class.""" |
|
254 | 255 | |
|
255 | 256 | stat = 0 |
|
256 | 257 | if verbose or debug: print header+cmd |
|
257 | 258 | sys.stdout.flush() |
|
258 | 259 | if not debug: stat = os.system(cmd) |
|
259 | 260 | return stat |
|
260 | 261 | |
|
261 | 262 | def shell(cmd,verbose=0,debug=0,header=''): |
|
262 | 263 | """Execute a command in the system shell, always return None. |
|
263 | 264 | |
|
264 | 265 | Options: |
|
265 | 266 | |
|
266 | 267 | - verbose (0): print the command to be executed. |
|
267 | 268 | |
|
268 | 269 | - debug (0): only print, do not actually execute. |
|
269 | 270 | |
|
270 | 271 | - header (''): Header to print on screen prior to the executed command (it |
|
271 | 272 | is only prepended to the command, no newlines are added). |
|
272 | 273 | |
|
273 | 274 | Note: this is similar to genutils.system(), but it returns None so it can |
|
274 | 275 | be conveniently used in interactive loops without getting the return value |
|
275 | 276 | (typically 0) printed many times.""" |
|
276 | 277 | |
|
277 | 278 | stat = 0 |
|
278 | 279 | if verbose or debug: print header+cmd |
|
279 | 280 | # flush stdout so we don't mangle python's buffering |
|
280 | 281 | sys.stdout.flush() |
|
281 | 282 | if not debug: |
|
282 | 283 | os.system(cmd) |
|
283 | 284 | |
|
284 | 285 | def getoutput(cmd,verbose=0,debug=0,header='',split=0): |
|
285 | 286 | """Dummy substitute for perl's backquotes. |
|
286 | 287 | |
|
287 | 288 | Executes a command and returns the output. |
|
288 | 289 | |
|
289 | 290 | Accepts the same arguments as system(), plus: |
|
290 | 291 | |
|
291 | 292 | - split(0): if true, the output is returned as a list split on newlines. |
|
292 | 293 | |
|
293 | 294 | Note: a stateful version of this function is available through the |
|
294 | 295 | SystemExec class.""" |
|
295 | 296 | |
|
296 | 297 | if verbose or debug: print header+cmd |
|
297 | 298 | if not debug: |
|
298 | 299 | output = commands.getoutput(cmd) |
|
299 | 300 | if split: |
|
300 | 301 | return output.split('\n') |
|
301 | 302 | else: |
|
302 | 303 | return output |
|
303 | 304 | |
|
304 | 305 | def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): |
|
305 | 306 | """Return (standard output,standard error) of executing cmd in a shell. |
|
306 | 307 | |
|
307 | 308 | Accepts the same arguments as system(), plus: |
|
308 | 309 | |
|
309 | 310 | - split(0): if true, each of stdout/err is returned as a list split on |
|
310 | 311 | newlines. |
|
311 | 312 | |
|
312 | 313 | Note: a stateful version of this function is available through the |
|
313 | 314 | SystemExec class.""" |
|
314 | 315 | |
|
315 | 316 | if verbose or debug: print header+cmd |
|
316 | 317 | if not cmd: |
|
317 | 318 | if split: |
|
318 | 319 | return [],[] |
|
319 | 320 | else: |
|
320 | 321 | return '','' |
|
321 | 322 | if not debug: |
|
322 | 323 | pin,pout,perr = os.popen3(cmd) |
|
323 | 324 | tout = pout.read().rstrip() |
|
324 | 325 | terr = perr.read().rstrip() |
|
325 | 326 | pin.close() |
|
326 | 327 | pout.close() |
|
327 | 328 | perr.close() |
|
328 | 329 | if split: |
|
329 | 330 | return tout.split('\n'),terr.split('\n') |
|
330 | 331 | else: |
|
331 | 332 | return tout,terr |
|
332 | 333 | |
|
333 | 334 | # for compatibility with older naming conventions |
|
334 | 335 | xsys = system |
|
335 | 336 | bq = getoutput |
|
336 | 337 | |
|
337 | 338 | class SystemExec: |
|
338 | 339 | """Access the system and getoutput functions through a stateful interface. |
|
339 | 340 | |
|
340 | 341 | Note: here we refer to the system and getoutput functions from this |
|
341 | 342 | library, not the ones from the standard python library. |
|
342 | 343 | |
|
343 | 344 | This class offers the system and getoutput functions as methods, but the |
|
344 | 345 | verbose, debug and header parameters can be set for the instance (at |
|
345 | 346 | creation time or later) so that they don't need to be specified on each |
|
346 | 347 | call. |
|
347 | 348 | |
|
348 | 349 | For efficiency reasons, there's no way to override the parameters on a |
|
349 | 350 | per-call basis other than by setting instance attributes. If you need |
|
350 | 351 | local overrides, it's best to directly call system() or getoutput(). |
|
351 | 352 | |
|
352 | 353 | The following names are provided as alternate options: |
|
353 | 354 | - xsys: alias to system |
|
354 | 355 | - bq: alias to getoutput |
|
355 | 356 | |
|
356 | 357 | An instance can then be created as: |
|
357 | 358 | >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ') |
|
358 | 359 | |
|
359 | 360 | And used as: |
|
360 | 361 | >>> sysexec.xsys('pwd') |
|
361 | 362 | >>> dirlist = sysexec.bq('ls -l') |
|
362 | 363 | """ |
|
363 | 364 | |
|
364 | 365 | def __init__(self,verbose=0,debug=0,header='',split=0): |
|
365 | 366 | """Specify the instance's values for verbose, debug and header.""" |
|
366 | 367 | setattr_list(self,'verbose debug header split') |
|
367 | 368 | |
|
368 | 369 | def system(self,cmd): |
|
369 | 370 | """Stateful interface to system(), with the same keyword parameters.""" |
|
370 | 371 | |
|
371 | 372 | system(cmd,self.verbose,self.debug,self.header) |
|
372 | 373 | |
|
373 | 374 | def shell(self,cmd): |
|
374 | 375 | """Stateful interface to shell(), with the same keyword parameters.""" |
|
375 | 376 | |
|
376 | 377 | shell(cmd,self.verbose,self.debug,self.header) |
|
377 | 378 | |
|
378 | 379 | xsys = system # alias |
|
379 | 380 | |
|
380 | 381 | def getoutput(self,cmd): |
|
381 | 382 | """Stateful interface to getoutput().""" |
|
382 | 383 | |
|
383 | 384 | return getoutput(cmd,self.verbose,self.debug,self.header,self.split) |
|
384 | 385 | |
|
385 | 386 | def getoutputerror(self,cmd): |
|
386 | 387 | """Stateful interface to getoutputerror().""" |
|
387 | 388 | |
|
388 | 389 | return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split) |
|
389 | 390 | |
|
390 | 391 | bq = getoutput # alias |
|
391 | 392 | |
|
392 | 393 | #----------------------------------------------------------------------------- |
|
393 | 394 | def mutex_opts(dict,ex_op): |
|
394 | 395 | """Check for presence of mutually exclusive keys in a dict. |
|
395 | 396 | |
|
396 | 397 | Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]""" |
|
397 | 398 | for op1,op2 in ex_op: |
|
398 | 399 | if op1 in dict and op2 in dict: |
|
399 | 400 | raise ValueError,'\n*** ERROR in Arguments *** '\ |
|
400 | 401 | 'Options '+op1+' and '+op2+' are mutually exclusive.' |
|
401 | 402 | |
|
402 | 403 | #----------------------------------------------------------------------------- |
|
403 | 404 | def filefind(fname,alt_dirs = None): |
|
404 | 405 | """Return the given filename either in the current directory, if it |
|
405 | 406 | exists, or in a specified list of directories. |
|
406 | 407 | |
|
407 | 408 | ~ expansion is done on all file and directory names. |
|
408 | 409 | |
|
409 | 410 | Upon an unsuccessful search, raise an IOError exception.""" |
|
410 | 411 | |
|
411 | 412 | if alt_dirs is None: |
|
412 | 413 | try: |
|
413 | 414 | alt_dirs = get_home_dir() |
|
414 | 415 | except HomeDirError: |
|
415 | 416 | alt_dirs = os.getcwd() |
|
416 | 417 | search = [fname] + list_strings(alt_dirs) |
|
417 | 418 | search = map(os.path.expanduser,search) |
|
418 | 419 | #print 'search list for',fname,'list:',search # dbg |
|
419 | 420 | fname = search[0] |
|
420 | 421 | if os.path.isfile(fname): |
|
421 | 422 | return fname |
|
422 | 423 | for direc in search[1:]: |
|
423 | 424 | testname = os.path.join(direc,fname) |
|
424 | 425 | #print 'testname',testname # dbg |
|
425 | 426 | if os.path.isfile(testname): |
|
426 | 427 | return testname |
|
427 | 428 | raise IOError,'File' + `fname` + \ |
|
428 | 429 | ' not found in current or supplied directories:' + `alt_dirs` |
|
429 | 430 | |
|
430 | 431 | #---------------------------------------------------------------------------- |
|
431 | 432 | def target_outdated(target,deps): |
|
432 | 433 | """Determine whether a target is out of date. |
|
433 | 434 | |
|
434 | 435 | target_outdated(target,deps) -> 1/0 |
|
435 | 436 | |
|
436 | 437 | deps: list of filenames which MUST exist. |
|
437 | 438 | target: single filename which may or may not exist. |
|
438 | 439 | |
|
439 | 440 | If target doesn't exist or is older than any file listed in deps, return |
|
440 | 441 | true, otherwise return false. |
|
441 | 442 | """ |
|
442 | 443 | try: |
|
443 | 444 | target_time = os.path.getmtime(target) |
|
444 | 445 | except os.error: |
|
445 | 446 | return 1 |
|
446 | 447 | for dep in deps: |
|
447 | 448 | dep_time = os.path.getmtime(dep) |
|
448 | 449 | if dep_time > target_time: |
|
449 | 450 | #print "For target",target,"Dep failed:",dep # dbg |
|
450 | 451 | #print "times (dep,tar):",dep_time,target_time # dbg |
|
451 | 452 | return 1 |
|
452 | 453 | return 0 |
|
453 | 454 | |
|
454 | 455 | #----------------------------------------------------------------------------- |
|
455 | 456 | def target_update(target,deps,cmd): |
|
456 | 457 | """Update a target with a given command given a list of dependencies. |
|
457 | 458 | |
|
458 | 459 | target_update(target,deps,cmd) -> runs cmd if target is outdated. |
|
459 | 460 | |
|
460 | 461 | This is just a wrapper around target_outdated() which calls the given |
|
461 | 462 | command if target is outdated.""" |
|
462 | 463 | |
|
463 | 464 | if target_outdated(target,deps): |
|
464 | 465 | xsys(cmd) |
|
465 | 466 | |
|
466 | 467 | #---------------------------------------------------------------------------- |
|
467 | 468 | def unquote_ends(istr): |
|
468 | 469 | """Remove a single pair of quotes from the endpoints of a string.""" |
|
469 | 470 | |
|
470 | 471 | if not istr: |
|
471 | 472 | return istr |
|
472 | 473 | if (istr[0]=="'" and istr[-1]=="'") or \ |
|
473 | 474 | (istr[0]=='"' and istr[-1]=='"'): |
|
474 | 475 | return istr[1:-1] |
|
475 | 476 | else: |
|
476 | 477 | return istr |
|
477 | 478 | |
|
478 | 479 | #---------------------------------------------------------------------------- |
|
479 | 480 | def process_cmdline(argv,names=[],defaults={},usage=''): |
|
480 | 481 | """ Process command-line options and arguments. |
|
481 | 482 | |
|
482 | 483 | Arguments: |
|
483 | 484 | |
|
484 | 485 | - argv: list of arguments, typically sys.argv. |
|
485 | 486 | |
|
486 | 487 | - names: list of option names. See DPyGetOpt docs for details on options |
|
487 | 488 | syntax. |
|
488 | 489 | |
|
489 | 490 | - defaults: dict of default values. |
|
490 | 491 | |
|
491 | 492 | - usage: optional usage notice to print if a wrong argument is passed. |
|
492 | 493 | |
|
493 | 494 | Return a dict of options and a list of free arguments.""" |
|
494 | 495 | |
|
495 | 496 | getopt = DPyGetOpt.DPyGetOpt() |
|
496 | 497 | getopt.setIgnoreCase(0) |
|
497 | 498 | getopt.parseConfiguration(names) |
|
498 | 499 | |
|
499 | 500 | try: |
|
500 | 501 | getopt.processArguments(argv) |
|
501 | 502 | except: |
|
502 | 503 | print usage |
|
503 | 504 | warn(`sys.exc_value`,level=4) |
|
504 | 505 | |
|
505 | 506 | defaults.update(getopt.optionValues) |
|
506 | 507 | args = getopt.freeValues |
|
507 | 508 | |
|
508 | 509 | return defaults,args |
|
509 | 510 | |
|
510 | 511 | #---------------------------------------------------------------------------- |
|
511 | 512 | def optstr2types(ostr): |
|
512 | 513 | """Convert a string of option names to a dict of type mappings. |
|
513 | 514 | |
|
514 | 515 | optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'} |
|
515 | 516 | |
|
516 | 517 | This is used to get the types of all the options in a string formatted |
|
517 | 518 | with the conventions of DPyGetOpt. The 'type' None is used for options |
|
518 | 519 | which are strings (they need no further conversion). This function's main |
|
519 | 520 | use is to get a typemap for use with read_dict(). |
|
520 | 521 | """ |
|
521 | 522 | |
|
522 | 523 | typeconv = {None:'',int:'',float:''} |
|
523 | 524 | typemap = {'s':None,'i':int,'f':float} |
|
524 | 525 | opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)') |
|
525 | 526 | |
|
526 | 527 | for w in ostr.split(): |
|
527 | 528 | oname,alias,otype = opt_re.match(w).groups() |
|
528 | 529 | if otype == '' or alias == '!': # simple switches are integers too |
|
529 | 530 | otype = 'i' |
|
530 | 531 | typeconv[typemap[otype]] += oname + ' ' |
|
531 | 532 | return typeconv |
|
532 | 533 | |
|
533 | 534 | #---------------------------------------------------------------------------- |
|
534 | 535 | def read_dict(filename,type_conv=None,**opt): |
|
535 | 536 | |
|
536 | 537 | """Read a dictionary of key=value pairs from an input file, optionally |
|
537 | 538 | performing conversions on the resulting values. |
|
538 | 539 | |
|
539 | 540 | read_dict(filename,type_conv,**opt) -> dict |
|
540 | 541 | |
|
541 | 542 | Only one value per line is accepted, the format should be |
|
542 | 543 | # optional comments are ignored |
|
543 | 544 | key value\n |
|
544 | 545 | |
|
545 | 546 | Args: |
|
546 | 547 | |
|
547 | 548 | - type_conv: A dictionary specifying which keys need to be converted to |
|
548 | 549 | which types. By default all keys are read as strings. This dictionary |
|
549 | 550 | should have as its keys valid conversion functions for strings |
|
550 | 551 | (int,long,float,complex, or your own). The value for each key |
|
551 | 552 | (converter) should be a whitespace separated string containing the names |
|
552 | 553 | of all the entries in the file to be converted using that function. For |
|
553 | 554 | keys to be left alone, use None as the conversion function (only needed |
|
554 | 555 | with purge=1, see below). |
|
555 | 556 | |
|
556 | 557 | - opt: dictionary with extra options as below (default in parens) |
|
557 | 558 | |
|
558 | 559 | purge(0): if set to 1, all keys *not* listed in type_conv are purged out |
|
559 | 560 | of the dictionary to be returned. If purge is going to be used, the |
|
560 | 561 | set of keys to be left as strings also has to be explicitly specified |
|
561 | 562 | using the (non-existent) conversion function None. |
|
562 | 563 | |
|
563 | 564 | fs(None): field separator. This is the key/value separator to be used |
|
564 | 565 | when parsing the file. The None default means any whitespace [behavior |
|
565 | 566 | of string.split()]. |
|
566 | 567 | |
|
567 | 568 | strip(0): if 1, strip string values of leading/trailinig whitespace. |
|
568 | 569 | |
|
569 | 570 | warn(1): warning level if requested keys are not found in file. |
|
570 | 571 | - 0: silently ignore. |
|
571 | 572 | - 1: inform but proceed. |
|
572 | 573 | - 2: raise KeyError exception. |
|
573 | 574 | |
|
574 | 575 | no_empty(0): if 1, remove keys with whitespace strings as a value. |
|
575 | 576 | |
|
576 | 577 | unique([]): list of keys (or space separated string) which can't be |
|
577 | 578 | repeated. If one such key is found in the file, each new instance |
|
578 | 579 | overwrites the previous one. For keys not listed here, the behavior is |
|
579 | 580 | to make a list of all appearances. |
|
580 | 581 | |
|
581 | 582 | Example: |
|
582 | 583 | If the input file test.ini has: |
|
583 | 584 | i 3 |
|
584 | 585 | x 4.5 |
|
585 | 586 | y 5.5 |
|
586 | 587 | s hi ho |
|
587 | 588 | Then: |
|
588 | 589 | |
|
589 | 590 | >>> type_conv={int:'i',float:'x',None:'s'} |
|
590 | 591 | >>> read_dict('test.ini') |
|
591 | 592 | {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'} |
|
592 | 593 | >>> read_dict('test.ini',type_conv) |
|
593 | 594 | {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'} |
|
594 | 595 | >>> read_dict('test.ini',type_conv,purge=1) |
|
595 | 596 | {'i': 3, 's': 'hi ho', 'x': 4.5} |
|
596 | 597 | """ |
|
597 | 598 | |
|
598 | 599 | # starting config |
|
599 | 600 | opt.setdefault('purge',0) |
|
600 | 601 | opt.setdefault('fs',None) # field sep defaults to any whitespace |
|
601 | 602 | opt.setdefault('strip',0) |
|
602 | 603 | opt.setdefault('warn',1) |
|
603 | 604 | opt.setdefault('no_empty',0) |
|
604 | 605 | opt.setdefault('unique','') |
|
605 | 606 | if type(opt['unique']) in StringTypes: |
|
606 | 607 | unique_keys = qw(opt['unique']) |
|
607 | 608 | elif type(opt['unique']) in (types.TupleType,types.ListType): |
|
608 | 609 | unique_keys = opt['unique'] |
|
609 | 610 | else: |
|
610 | 611 | raise ValueError, 'Unique keys must be given as a string, List or Tuple' |
|
611 | 612 | |
|
612 | 613 | dict = {} |
|
613 | 614 | # first read in table of values as strings |
|
614 | 615 | file = open(filename,'r') |
|
615 | 616 | for line in file.readlines(): |
|
616 | 617 | line = line.strip() |
|
617 | 618 | if len(line) and line[0]=='#': continue |
|
618 | 619 | if len(line)>0: |
|
619 | 620 | lsplit = line.split(opt['fs'],1) |
|
620 | 621 | try: |
|
621 | 622 | key,val = lsplit |
|
622 | 623 | except ValueError: |
|
623 | 624 | key,val = lsplit[0],'' |
|
624 | 625 | key = key.strip() |
|
625 | 626 | if opt['strip']: val = val.strip() |
|
626 | 627 | if val == "''" or val == '""': val = '' |
|
627 | 628 | if opt['no_empty'] and (val=='' or val.isspace()): |
|
628 | 629 | continue |
|
629 | 630 | # if a key is found more than once in the file, build a list |
|
630 | 631 | # unless it's in the 'unique' list. In that case, last found in file |
|
631 | 632 | # takes precedence. User beware. |
|
632 | 633 | try: |
|
633 | 634 | if dict[key] and key in unique_keys: |
|
634 | 635 | dict[key] = val |
|
635 | 636 | elif type(dict[key]) is types.ListType: |
|
636 | 637 | dict[key].append(val) |
|
637 | 638 | else: |
|
638 | 639 | dict[key] = [dict[key],val] |
|
639 | 640 | except KeyError: |
|
640 | 641 | dict[key] = val |
|
641 | 642 | # purge if requested |
|
642 | 643 | if opt['purge']: |
|
643 | 644 | accepted_keys = qwflat(type_conv.values()) |
|
644 | 645 | for key in dict.keys(): |
|
645 | 646 | if key in accepted_keys: continue |
|
646 | 647 | del(dict[key]) |
|
647 | 648 | # now convert if requested |
|
648 | 649 | if type_conv==None: return dict |
|
649 | 650 | conversions = type_conv.keys() |
|
650 | 651 | try: conversions.remove(None) |
|
651 | 652 | except: pass |
|
652 | 653 | for convert in conversions: |
|
653 | 654 | for val in qw(type_conv[convert]): |
|
654 | 655 | try: |
|
655 | 656 | dict[val] = convert(dict[val]) |
|
656 | 657 | except KeyError,e: |
|
657 | 658 | if opt['warn'] == 0: |
|
658 | 659 | pass |
|
659 | 660 | elif opt['warn'] == 1: |
|
660 | 661 | print >>sys.stderr, 'Warning: key',val,\ |
|
661 | 662 | 'not found in file',filename |
|
662 | 663 | elif opt['warn'] == 2: |
|
663 | 664 | raise KeyError,e |
|
664 | 665 | else: |
|
665 | 666 | raise ValueError,'Warning level must be 0,1 or 2' |
|
666 | 667 | |
|
667 | 668 | return dict |
|
668 | 669 | |
|
669 | 670 | #---------------------------------------------------------------------------- |
|
670 | 671 | def flag_calls(func): |
|
671 | 672 | """Wrap a function to detect and flag when it gets called. |
|
672 | 673 | |
|
673 | 674 | This is a decorator which takes a function and wraps it in a function with |
|
674 | 675 | a 'called' attribute. wrapper.called is initialized to False. |
|
675 | 676 | |
|
676 | 677 | The wrapper.called attribute is set to False right before each call to the |
|
677 | 678 | wrapped function, so if the call fails it remains False. After the call |
|
678 | 679 | completes, wrapper.called is set to True and the output is returned. |
|
679 | 680 | |
|
680 | 681 | Testing for truth in wrapper.called allows you to determine if a call to |
|
681 | 682 | func() was attempted and succeeded.""" |
|
682 | 683 | |
|
683 | 684 | def wrapper(*args,**kw): |
|
684 | 685 | wrapper.called = False |
|
685 | 686 | out = func(*args,**kw) |
|
686 | 687 | wrapper.called = True |
|
687 | 688 | return out |
|
688 | 689 | |
|
689 | 690 | wrapper.called = False |
|
690 | 691 | wrapper.__doc__ = func.__doc__ |
|
691 | 692 | return wrapper |
|
692 | 693 | |
|
693 | 694 | #---------------------------------------------------------------------------- |
|
694 | 695 | class HomeDirError(Error): |
|
695 | 696 | pass |
|
696 | 697 | |
|
697 | 698 | def get_home_dir(): |
|
698 | 699 | """Return the closest possible equivalent to a 'home' directory. |
|
699 | 700 | |
|
700 | 701 | We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. |
|
701 | 702 | |
|
702 | 703 | Currently only Posix and NT are implemented, a HomeDirError exception is |
|
703 | 704 | raised for all other OSes. """ |
|
704 | 705 | |
|
705 | 706 | isdir = os.path.isdir |
|
706 | 707 | env = os.environ |
|
707 | 708 | try: |
|
708 | 709 | homedir = env['HOME'] |
|
709 | 710 | if not isdir(homedir): |
|
710 | 711 | # in case a user stuck some string which does NOT resolve to a |
|
711 | 712 | # valid path, it's as good as if we hadn't foud it |
|
712 | 713 | raise KeyError |
|
713 | 714 | return homedir |
|
714 | 715 | except KeyError: |
|
715 | 716 | if os.name == 'posix': |
|
716 | 717 | raise HomeDirError,'undefined $HOME, IPython can not proceed.' |
|
717 | 718 | elif os.name == 'nt': |
|
718 | 719 | # For some strange reason, win9x returns 'nt' for os.name. |
|
719 | 720 | try: |
|
720 | 721 | homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH']) |
|
721 | 722 | if not isdir(homedir): |
|
722 | 723 | homedir = os.path.join(env['USERPROFILE']) |
|
723 | 724 | if not isdir(homedir): |
|
724 | 725 | raise HomeDirError |
|
725 | 726 | return homedir |
|
726 | 727 | except: |
|
727 | 728 | try: |
|
728 | 729 | # Use the registry to get the 'My Documents' folder. |
|
729 | 730 | import _winreg as wreg |
|
730 | 731 | key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, |
|
731 | 732 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") |
|
732 | 733 | homedir = wreg.QueryValueEx(key,'Personal')[0] |
|
733 | 734 | key.Close() |
|
734 | 735 | return homedir |
|
735 | 736 | except: |
|
736 | 737 | return 'C:\\' |
|
737 | 738 | elif os.name == 'dos': |
|
738 | 739 | # Desperate, may do absurd things in classic MacOS. May work under DOS. |
|
739 | 740 | return 'C:\\' |
|
740 | 741 | else: |
|
741 | 742 | raise HomeDirError,'support for your operating system not implemented.' |
|
742 | 743 | |
|
743 | 744 | #**************************************************************************** |
|
744 | 745 | # strings and text |
|
745 | 746 | |
|
746 | 747 | class LSString(str): |
|
747 | 748 | """String derivative with a special access attributes. |
|
748 | 749 | |
|
749 | 750 | These are normal strings, but with the special attributes: |
|
750 | 751 | |
|
751 | 752 | .l (or .list) : value as list (split on newlines). |
|
752 | 753 | .n (or .nlstr): original value (the string itself). |
|
753 | 754 | .s (or .spstr): value as whitespace-separated string. |
|
754 | 755 | |
|
755 | 756 | Any values which require transformations are computed only once and |
|
756 | 757 | cached. |
|
757 | 758 | |
|
758 | 759 | Such strings are very useful to efficiently interact with the shell, which |
|
759 | 760 | typically only understands whitespace-separated options for commands.""" |
|
760 | 761 | |
|
761 | 762 | def get_list(self): |
|
762 | 763 | try: |
|
763 | 764 | return self.__list |
|
764 | 765 | except AttributeError: |
|
765 | 766 | self.__list = self.split('\n') |
|
766 | 767 | return self.__list |
|
767 | 768 | |
|
768 | 769 | l = list = property(get_list) |
|
769 | 770 | |
|
770 | 771 | def get_spstr(self): |
|
771 | 772 | try: |
|
772 | 773 | return self.__spstr |
|
773 | 774 | except AttributeError: |
|
774 | 775 | self.__spstr = self.replace('\n',' ') |
|
775 | 776 | return self.__spstr |
|
776 | 777 | |
|
777 | 778 | s = spstr = property(get_spstr) |
|
778 | 779 | |
|
779 | 780 | def get_nlstr(self): |
|
780 | 781 | return self |
|
781 | 782 | |
|
782 | 783 | n = nlstr = property(get_nlstr) |
|
783 | 784 | |
|
784 | 785 | class SList(list): |
|
785 | 786 | """List derivative with a special access attributes. |
|
786 | 787 | |
|
787 | 788 | These are normal lists, but with the special attributes: |
|
788 | 789 | |
|
789 | 790 | .l (or .list) : value as list (the list itself). |
|
790 | 791 | .n (or .nlstr): value as a string, joined on newlines. |
|
791 | 792 | .s (or .spstr): value as a string, joined on spaces. |
|
792 | 793 | |
|
793 | 794 | Any values which require transformations are computed only once and |
|
794 | 795 | cached.""" |
|
795 | 796 | |
|
796 | 797 | def get_list(self): |
|
797 | 798 | return self |
|
798 | 799 | |
|
799 | 800 | l = list = property(get_list) |
|
800 | 801 | |
|
801 | 802 | def get_spstr(self): |
|
802 | 803 | try: |
|
803 | 804 | return self.__spstr |
|
804 | 805 | except AttributeError: |
|
805 | 806 | self.__spstr = ' '.join(self) |
|
806 | 807 | return self.__spstr |
|
807 | 808 | |
|
808 | 809 | s = spstr = property(get_spstr) |
|
809 | 810 | |
|
810 | 811 | def get_nlstr(self): |
|
811 | 812 | try: |
|
812 | 813 | return self.__nlstr |
|
813 | 814 | except AttributeError: |
|
814 | 815 | self.__nlstr = '\n'.join(self) |
|
815 | 816 | return self.__nlstr |
|
816 | 817 | |
|
817 | 818 | n = nlstr = property(get_nlstr) |
|
818 | 819 | |
|
819 | 820 | def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'): |
|
820 | 821 | """Take multiple lines of input. |
|
821 | 822 | |
|
822 | 823 | A list with each line of input as a separate element is returned when a |
|
823 | 824 | termination string is entered (defaults to a single '.'). Input can also |
|
824 | 825 | terminate via EOF (^D in Unix, ^Z-RET in Windows). |
|
825 | 826 | |
|
826 | 827 | Lines of input which end in \\ are joined into single entries (and a |
|
827 | 828 | secondary continuation prompt is issued as long as the user terminates |
|
828 | 829 | lines with \\). This allows entering very long strings which are still |
|
829 | 830 | meant to be treated as single entities. |
|
830 | 831 | """ |
|
831 | 832 | |
|
832 | 833 | try: |
|
833 | 834 | if header: |
|
834 | 835 | header += '\n' |
|
835 | 836 | lines = [raw_input(header + ps1)] |
|
836 | 837 | except EOFError: |
|
837 | 838 | return [] |
|
838 | 839 | terminate = [terminate_str] |
|
839 | 840 | try: |
|
840 | 841 | while lines[-1:] != terminate: |
|
841 | 842 | new_line = raw_input(ps1) |
|
842 | 843 | while new_line.endswith('\\'): |
|
843 | 844 | new_line = new_line[:-1] + raw_input(ps2) |
|
844 | 845 | lines.append(new_line) |
|
845 | 846 | |
|
846 | 847 | return lines[:-1] # don't return the termination command |
|
847 | 848 | except EOFError: |
|
848 | 849 | |
|
849 | 850 | return lines |
|
850 | 851 | |
|
851 | 852 | #---------------------------------------------------------------------------- |
|
852 | 853 | def raw_input_ext(prompt='', ps2='... '): |
|
853 | 854 | """Similar to raw_input(), but accepts extended lines if input ends with \\.""" |
|
854 | 855 | |
|
855 | 856 | line = raw_input(prompt) |
|
856 | 857 | while line.endswith('\\'): |
|
857 | 858 | line = line[:-1] + raw_input(ps2) |
|
858 | 859 | return line |
|
859 | 860 | |
|
860 | 861 | #---------------------------------------------------------------------------- |
|
861 | 862 | def ask_yes_no(prompt,default=None): |
|
862 | 863 | """Asks a question and returns an integer 1/0 (y/n) answer. |
|
863 | 864 | |
|
864 | 865 | If default is given (one of 'y','n'), it is used if the user input is |
|
865 | 866 | empty. Otherwise the question is repeated until an answer is given. |
|
866 | 867 | If EOF occurs 20 times consecutively, the default answer is assumed, |
|
867 | 868 | or if there is no default, an exception is raised to prevent infinite |
|
868 | 869 | loops. |
|
869 | 870 | |
|
870 | 871 | Valid answers are: y/yes/n/no (match is not case sensitive).""" |
|
871 | 872 | |
|
872 | 873 | answers = {'y':1,'n':0,'yes':1,'no':0} |
|
873 | 874 | ans = None |
|
874 | 875 | eofs, max_eofs = 0, 20 |
|
875 | 876 | while ans not in answers.keys(): |
|
876 | 877 | try: |
|
877 | 878 | ans = raw_input(prompt+' ').lower() |
|
878 | 879 | if not ans: # response was an empty string |
|
879 | 880 | ans = default |
|
880 | 881 | eofs = 0 |
|
881 | 882 | except (EOFError,KeyboardInterrupt): |
|
882 | 883 | eofs = eofs + 1 |
|
883 | 884 | if eofs >= max_eofs: |
|
884 | 885 | if default in answers.keys(): |
|
885 | 886 | ans = default |
|
886 | 887 | else: |
|
887 | 888 | raise |
|
888 | 889 | |
|
889 | 890 | return answers[ans] |
|
890 | 891 | |
|
891 | 892 | #---------------------------------------------------------------------------- |
|
892 | 893 | class EvalDict: |
|
893 | 894 | """ |
|
894 | 895 | Emulate a dict which evaluates its contents in the caller's frame. |
|
895 | 896 | |
|
896 | 897 | Usage: |
|
897 | 898 | >>>number = 19 |
|
898 | 899 | >>>text = "python" |
|
899 | 900 | >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict() |
|
900 | 901 | """ |
|
901 | 902 | |
|
902 | 903 | # This version is due to sismex01@hebmex.com on c.l.py, and is basically a |
|
903 | 904 | # modified (shorter) version of: |
|
904 | 905 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by |
|
905 | 906 | # Skip Montanaro (skip@pobox.com). |
|
906 | 907 | |
|
907 | 908 | def __getitem__(self, name): |
|
908 | 909 | frame = sys._getframe(1) |
|
909 | 910 | return eval(name, frame.f_globals, frame.f_locals) |
|
910 | 911 | |
|
911 | 912 | EvalString = EvalDict # for backwards compatibility |
|
912 | 913 | #---------------------------------------------------------------------------- |
|
913 | 914 | def qw(words,flat=0,sep=None,maxsplit=-1): |
|
914 | 915 | """Similar to Perl's qw() operator, but with some more options. |
|
915 | 916 | |
|
916 | 917 | qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit) |
|
917 | 918 | |
|
918 | 919 | words can also be a list itself, and with flat=1, the output will be |
|
919 | 920 | recursively flattened. Examples: |
|
920 | 921 | |
|
921 | 922 | >>> qw('1 2') |
|
922 | 923 | ['1', '2'] |
|
923 | 924 | >>> qw(['a b','1 2',['m n','p q']]) |
|
924 | 925 | [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]] |
|
925 | 926 | >>> qw(['a b','1 2',['m n','p q']],flat=1) |
|
926 | 927 | ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """ |
|
927 | 928 | |
|
928 | 929 | if type(words) in StringTypes: |
|
929 | 930 | return [word.strip() for word in words.split(sep,maxsplit) |
|
930 | 931 | if word and not word.isspace() ] |
|
931 | 932 | if flat: |
|
932 | 933 | return flatten(map(qw,words,[1]*len(words))) |
|
933 | 934 | return map(qw,words) |
|
934 | 935 | |
|
935 | 936 | #---------------------------------------------------------------------------- |
|
936 | 937 | def qwflat(words,sep=None,maxsplit=-1): |
|
937 | 938 | """Calls qw(words) in flat mode. It's just a convenient shorthand.""" |
|
938 | 939 | return qw(words,1,sep,maxsplit) |
|
939 | 940 | |
|
940 | 941 | #----------------------------------------------------------------------------- |
|
941 | 942 | def list_strings(arg): |
|
942 | 943 | """Always return a list of strings, given a string or list of strings |
|
943 | 944 | as input.""" |
|
944 | 945 | |
|
945 | 946 | if type(arg) in StringTypes: return [arg] |
|
946 | 947 | else: return arg |
|
947 | 948 | |
|
948 | 949 | #---------------------------------------------------------------------------- |
|
949 | 950 | def grep(pat,list,case=1): |
|
950 | 951 | """Simple minded grep-like function. |
|
951 | 952 | grep(pat,list) returns occurrences of pat in list, None on failure. |
|
952 | 953 | |
|
953 | 954 | It only does simple string matching, with no support for regexps. Use the |
|
954 | 955 | option case=0 for case-insensitive matching.""" |
|
955 | 956 | |
|
956 | 957 | # This is pretty crude. At least it should implement copying only references |
|
957 | 958 | # to the original data in case it's big. Now it copies the data for output. |
|
958 | 959 | out=[] |
|
959 | 960 | if case: |
|
960 | 961 | for term in list: |
|
961 | 962 | if term.find(pat)>-1: out.append(term) |
|
962 | 963 | else: |
|
963 | 964 | lpat=pat.lower() |
|
964 | 965 | for term in list: |
|
965 | 966 | if term.lower().find(lpat)>-1: out.append(term) |
|
966 | 967 | |
|
967 | 968 | if len(out): return out |
|
968 | 969 | else: return None |
|
969 | 970 | |
|
970 | 971 | #---------------------------------------------------------------------------- |
|
971 | 972 | def dgrep(pat,*opts): |
|
972 | 973 | """Return grep() on dir()+dir(__builtins__). |
|
973 | 974 | |
|
974 | 975 | A very common use of grep() when working interactively.""" |
|
975 | 976 | |
|
976 | 977 | return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts) |
|
977 | 978 | |
|
978 | 979 | #---------------------------------------------------------------------------- |
|
979 | 980 | def idgrep(pat): |
|
980 | 981 | """Case-insensitive dgrep()""" |
|
981 | 982 | |
|
982 | 983 | return dgrep(pat,0) |
|
983 | 984 | |
|
984 | 985 | #---------------------------------------------------------------------------- |
|
985 | 986 | def igrep(pat,list): |
|
986 | 987 | """Synonym for case-insensitive grep.""" |
|
987 | 988 | |
|
988 | 989 | return grep(pat,list,case=0) |
|
989 | 990 | |
|
990 | 991 | #---------------------------------------------------------------------------- |
|
991 | 992 | def indent(str,nspaces=4,ntabs=0): |
|
992 | 993 | """Indent a string a given number of spaces or tabstops. |
|
993 | 994 | |
|
994 | 995 | indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces. |
|
995 | 996 | """ |
|
996 | 997 | if str is None: |
|
997 | 998 | return |
|
998 | 999 | ind = '\t'*ntabs+' '*nspaces |
|
999 | 1000 | outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind)) |
|
1000 | 1001 | if outstr.endswith(os.linesep+ind): |
|
1001 | 1002 | return outstr[:-len(ind)] |
|
1002 | 1003 | else: |
|
1003 | 1004 | return outstr |
|
1004 | 1005 | |
|
1005 | 1006 | #----------------------------------------------------------------------------- |
|
1006 | 1007 | def native_line_ends(filename,backup=1): |
|
1007 | 1008 | """Convert (in-place) a file to line-ends native to the current OS. |
|
1008 | 1009 | |
|
1009 | 1010 | If the optional backup argument is given as false, no backup of the |
|
1010 | 1011 | original file is left. """ |
|
1011 | 1012 | |
|
1012 | 1013 | backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'} |
|
1013 | 1014 | |
|
1014 | 1015 | bak_filename = filename + backup_suffixes[os.name] |
|
1015 | 1016 | |
|
1016 | 1017 | original = open(filename).read() |
|
1017 | 1018 | shutil.copy2(filename,bak_filename) |
|
1018 | 1019 | try: |
|
1019 | 1020 | new = open(filename,'wb') |
|
1020 | 1021 | new.write(os.linesep.join(original.splitlines())) |
|
1021 | 1022 | new.write(os.linesep) # ALWAYS put an eol at the end of the file |
|
1022 | 1023 | new.close() |
|
1023 | 1024 | except: |
|
1024 | 1025 | os.rename(bak_filename,filename) |
|
1025 | 1026 | if not backup: |
|
1026 | 1027 | try: |
|
1027 | 1028 | os.remove(bak_filename) |
|
1028 | 1029 | except: |
|
1029 | 1030 | pass |
|
1030 | 1031 | |
|
1031 | 1032 | #---------------------------------------------------------------------------- |
|
1032 | 1033 | def get_pager_cmd(pager_cmd = None): |
|
1033 | 1034 | """Return a pager command. |
|
1034 | 1035 | |
|
1035 | 1036 | Makes some attempts at finding an OS-correct one.""" |
|
1036 | 1037 | |
|
1037 | 1038 | if os.name == 'posix': |
|
1038 | 1039 | default_pager_cmd = 'less -r' # -r for color control sequences |
|
1039 | 1040 | elif os.name in ['nt','dos']: |
|
1040 | 1041 | default_pager_cmd = 'type' |
|
1041 | 1042 | |
|
1042 | 1043 | if pager_cmd is None: |
|
1043 | 1044 | try: |
|
1044 | 1045 | pager_cmd = os.environ['PAGER'] |
|
1045 | 1046 | except: |
|
1046 | 1047 | pager_cmd = default_pager_cmd |
|
1047 | 1048 | return pager_cmd |
|
1048 | 1049 | |
|
1049 | 1050 | #----------------------------------------------------------------------------- |
|
1050 | 1051 | def get_pager_start(pager,start): |
|
1051 | 1052 | """Return the string for paging files with an offset. |
|
1052 | 1053 | |
|
1053 | 1054 | This is the '+N' argument which less and more (under Unix) accept. |
|
1054 | 1055 | """ |
|
1055 | 1056 | |
|
1056 | 1057 | if pager in ['less','more']: |
|
1057 | 1058 | if start: |
|
1058 | 1059 | start_string = '+' + str(start) |
|
1059 | 1060 | else: |
|
1060 | 1061 | start_string = '' |
|
1061 | 1062 | else: |
|
1062 | 1063 | start_string = '' |
|
1063 | 1064 | return start_string |
|
1064 | 1065 | |
|
1065 | 1066 | #---------------------------------------------------------------------------- |
|
1066 | 1067 | def page_dumb(strng,start=0,screen_lines=25): |
|
1067 | 1068 | """Very dumb 'pager' in Python, for when nothing else works. |
|
1068 | 1069 | |
|
1069 | 1070 | Only moves forward, same interface as page(), except for pager_cmd and |
|
1070 | 1071 | mode.""" |
|
1071 | 1072 | |
|
1072 | 1073 | out_ln = strng.splitlines()[start:] |
|
1073 | 1074 | screens = chop(out_ln,screen_lines-1) |
|
1074 | 1075 | if len(screens) == 1: |
|
1075 | 1076 | print >>Term.cout, os.linesep.join(screens[0]) |
|
1076 | 1077 | else: |
|
1077 | 1078 | for scr in screens[0:-1]: |
|
1078 | 1079 | print >>Term.cout, os.linesep.join(scr) |
|
1079 | 1080 | ans = raw_input('---Return to continue, q to quit--- ') |
|
1080 | 1081 | if ans.lower().startswith('q'): |
|
1081 | 1082 | return |
|
1082 | 1083 | print >>Term.cout, os.linesep.join(screens[-1]) |
|
1083 | 1084 | |
|
1084 | 1085 | #---------------------------------------------------------------------------- |
|
1085 | 1086 | def page(strng,start=0,screen_lines=0,pager_cmd = None): |
|
1086 | 1087 | """Print a string, piping through a pager after a certain length. |
|
1087 | 1088 | |
|
1088 | 1089 | The screen_lines parameter specifies the number of *usable* lines of your |
|
1089 | 1090 | terminal screen (total lines minus lines you need to reserve to show other |
|
1090 | 1091 | information). |
|
1091 | 1092 | |
|
1092 | 1093 | If you set screen_lines to a number <=0, page() will try to auto-determine |
|
1093 | 1094 | your screen size and will only use up to (screen_size+screen_lines) for |
|
1094 | 1095 | printing, paging after that. That is, if you want auto-detection but need |
|
1095 | 1096 | to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for |
|
1096 | 1097 | auto-detection without any lines reserved simply use screen_lines = 0. |
|
1097 | 1098 | |
|
1098 | 1099 | If a string won't fit in the allowed lines, it is sent through the |
|
1099 | 1100 | specified pager command. If none given, look for PAGER in the environment, |
|
1100 | 1101 | and ultimately default to less. |
|
1101 | 1102 | |
|
1102 | 1103 | If no system pager works, the string is sent through a 'dumb pager' |
|
1103 | 1104 | written in python, very simplistic. |
|
1104 | 1105 | """ |
|
1105 | 1106 | |
|
1106 | 1107 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs |
|
1107 | 1108 | TERM = os.environ.get('TERM','dumb') |
|
1108 | 1109 | if TERM in ['dumb','emacs'] and os.name != 'nt': |
|
1109 | 1110 | print strng |
|
1110 | 1111 | return |
|
1111 | 1112 | # chop off the topmost part of the string we don't want to see |
|
1112 | 1113 | str_lines = strng.split(os.linesep)[start:] |
|
1113 | 1114 | str_toprint = os.linesep.join(str_lines) |
|
1114 | 1115 | num_newlines = len(str_lines) |
|
1115 | 1116 | len_str = len(str_toprint) |
|
1116 | 1117 | |
|
1117 | 1118 | # Dumb heuristics to guesstimate number of on-screen lines the string |
|
1118 | 1119 | # takes. Very basic, but good enough for docstrings in reasonable |
|
1119 | 1120 | # terminals. If someone later feels like refining it, it's not hard. |
|
1120 | 1121 | numlines = max(num_newlines,int(len_str/80)+1) |
|
1121 | 1122 | |
|
1122 | 1123 | screen_lines_def = 25 # default value if we can't auto-determine |
|
1123 | 1124 | |
|
1124 | 1125 | # auto-determine screen size |
|
1125 | 1126 | if screen_lines <= 0: |
|
1126 | 1127 | if TERM=='xterm': |
|
1127 | 1128 | try: |
|
1128 | 1129 | import curses |
|
1129 | 1130 | if hasattr(curses,'initscr'): |
|
1130 | 1131 | use_curses = 1 |
|
1131 | 1132 | else: |
|
1132 | 1133 | use_curses = 0 |
|
1133 | 1134 | except ImportError: |
|
1134 | 1135 | use_curses = 0 |
|
1135 | 1136 | else: |
|
1136 | 1137 | # curses causes problems on many terminals other than xterm. |
|
1137 | 1138 | use_curses = 0 |
|
1138 | 1139 | if use_curses: |
|
1139 | 1140 | scr = curses.initscr() |
|
1140 | 1141 | screen_lines_real,screen_cols = scr.getmaxyx() |
|
1141 | 1142 | curses.endwin() |
|
1142 | 1143 | screen_lines += screen_lines_real |
|
1143 | 1144 | #print '***Screen size:',screen_lines_real,'lines x',\ |
|
1144 | 1145 | #screen_cols,'columns.' # dbg |
|
1145 | 1146 | else: |
|
1146 | 1147 | screen_lines += screen_lines_def |
|
1147 | 1148 | |
|
1148 | 1149 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
1149 | 1150 | if numlines <= screen_lines : |
|
1150 | 1151 | #print '*** normal print' # dbg |
|
1151 | 1152 | print >>Term.cout, str_toprint |
|
1152 | 1153 | else: |
|
1153 | 1154 | # Try to open pager and default to internal one if that fails. |
|
1154 | 1155 | # All failure modes are tagged as 'retval=1', to match the return |
|
1155 | 1156 | # value of a failed system command. If any intermediate attempt |
|
1156 | 1157 | # sets retval to 1, at the end we resort to our own page_dumb() pager. |
|
1157 | 1158 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1158 | 1159 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1159 | 1160 | if os.name == 'nt': |
|
1160 | 1161 | if pager_cmd.startswith('type'): |
|
1161 | 1162 | # The default WinXP 'type' command is failing on complex strings. |
|
1162 | 1163 | retval = 1 |
|
1163 | 1164 | else: |
|
1164 | 1165 | tmpname = tempfile.mktemp('.txt') |
|
1165 | 1166 | tmpfile = file(tmpname,'wt') |
|
1166 | 1167 | tmpfile.write(strng) |
|
1167 | 1168 | tmpfile.close() |
|
1168 | 1169 | cmd = "%s < %s" % (pager_cmd,tmpname) |
|
1169 | 1170 | if os.system(cmd): |
|
1170 | 1171 | retval = 1 |
|
1171 | 1172 | else: |
|
1172 | 1173 | retval = None |
|
1173 | 1174 | os.remove(tmpname) |
|
1174 | 1175 | else: |
|
1175 | 1176 | try: |
|
1176 | 1177 | retval = None |
|
1177 | 1178 | # if I use popen4, things hang. No idea why. |
|
1178 | 1179 | #pager,shell_out = os.popen4(pager_cmd) |
|
1179 | 1180 | pager = os.popen(pager_cmd,'w') |
|
1180 | 1181 | pager.write(strng) |
|
1181 | 1182 | pager.close() |
|
1182 | 1183 | retval = pager.close() # success returns None |
|
1183 | 1184 | except IOError,msg: # broken pipe when user quits |
|
1184 | 1185 | if msg.args == (32,'Broken pipe'): |
|
1185 | 1186 | retval = None |
|
1186 | 1187 | else: |
|
1187 | 1188 | retval = 1 |
|
1188 | 1189 | except OSError: |
|
1189 | 1190 | # Other strange problems, sometimes seen in Win2k/cygwin |
|
1190 | 1191 | retval = 1 |
|
1191 | 1192 | if retval is not None: |
|
1192 | 1193 | page_dumb(strng,screen_lines=screen_lines) |
|
1193 | 1194 | |
|
1194 | 1195 | #---------------------------------------------------------------------------- |
|
1195 | 1196 | def page_file(fname,start = 0, pager_cmd = None): |
|
1196 | 1197 | """Page a file, using an optional pager command and starting line. |
|
1197 | 1198 | """ |
|
1198 | 1199 | |
|
1199 | 1200 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1200 | 1201 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1201 | 1202 | |
|
1202 | 1203 | try: |
|
1203 | 1204 | if os.environ['TERM'] in ['emacs','dumb']: |
|
1204 | 1205 | raise EnvironmentError |
|
1205 | 1206 | xsys(pager_cmd + ' ' + fname) |
|
1206 | 1207 | except: |
|
1207 | 1208 | try: |
|
1208 | 1209 | if start > 0: |
|
1209 | 1210 | start -= 1 |
|
1210 | 1211 | page(open(fname).read(),start) |
|
1211 | 1212 | except: |
|
1212 | 1213 | print 'Unable to show file',`fname` |
|
1213 | 1214 | |
|
1214 | 1215 | #---------------------------------------------------------------------------- |
|
1215 | 1216 | def snip_print(str,width = 75,print_full = 0,header = ''): |
|
1216 | 1217 | """Print a string snipping the midsection to fit in width. |
|
1217 | 1218 | |
|
1218 | 1219 | print_full: mode control: |
|
1219 | 1220 | - 0: only snip long strings |
|
1220 | 1221 | - 1: send to page() directly. |
|
1221 | 1222 | - 2: snip long strings and ask for full length viewing with page() |
|
1222 | 1223 | Return 1 if snipping was necessary, 0 otherwise.""" |
|
1223 | 1224 | |
|
1224 | 1225 | if print_full == 1: |
|
1225 | 1226 | page(header+str) |
|
1226 | 1227 | return 0 |
|
1227 | 1228 | |
|
1228 | 1229 | print header, |
|
1229 | 1230 | if len(str) < width: |
|
1230 | 1231 | print str |
|
1231 | 1232 | snip = 0 |
|
1232 | 1233 | else: |
|
1233 | 1234 | whalf = int((width -5)/2) |
|
1234 | 1235 | print str[:whalf] + ' <...> ' + str[-whalf:] |
|
1235 | 1236 | snip = 1 |
|
1236 | 1237 | if snip and print_full == 2: |
|
1237 | 1238 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
|
1238 | 1239 | page(str) |
|
1239 | 1240 | return snip |
|
1240 | 1241 | |
|
1241 | 1242 | #**************************************************************************** |
|
1242 | 1243 | # lists, dicts and structures |
|
1243 | 1244 | |
|
1244 | 1245 | def belong(candidates,checklist): |
|
1245 | 1246 | """Check whether a list of items appear in a given list of options. |
|
1246 | 1247 | |
|
1247 | 1248 | Returns a list of 1 and 0, one for each candidate given.""" |
|
1248 | 1249 | |
|
1249 | 1250 | return [x in checklist for x in candidates] |
|
1250 | 1251 | |
|
1251 | 1252 | #---------------------------------------------------------------------------- |
|
1252 | 1253 | def uniq_stable(elems): |
|
1253 | 1254 | """uniq_stable(elems) -> list |
|
1254 | 1255 | |
|
1255 | 1256 | Return from an iterable, a list of all the unique elements in the input, |
|
1256 | 1257 | but maintaining the order in which they first appear. |
|
1257 | 1258 | |
|
1258 | 1259 | A naive solution to this problem which just makes a dictionary with the |
|
1259 | 1260 | elements as keys fails to respect the stability condition, since |
|
1260 | 1261 | dictionaries are unsorted by nature. |
|
1261 | 1262 | |
|
1262 | 1263 | Note: All elements in the input must be valid dictionary keys for this |
|
1263 | 1264 | routine to work, as it internally uses a dictionary for efficiency |
|
1264 | 1265 | reasons.""" |
|
1265 | 1266 | |
|
1266 | 1267 | unique = [] |
|
1267 | 1268 | unique_dict = {} |
|
1268 | 1269 | for nn in elems: |
|
1269 | 1270 | if nn not in unique_dict: |
|
1270 | 1271 | unique.append(nn) |
|
1271 | 1272 | unique_dict[nn] = None |
|
1272 | 1273 | return unique |
|
1273 | 1274 | |
|
1274 | 1275 | #---------------------------------------------------------------------------- |
|
1275 | 1276 | class NLprinter: |
|
1276 | 1277 | """Print an arbitrarily nested list, indicating index numbers. |
|
1277 | 1278 | |
|
1278 | 1279 | An instance of this class called nlprint is available and callable as a |
|
1279 | 1280 | function. |
|
1280 | 1281 | |
|
1281 | 1282 | nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent' |
|
1282 | 1283 | and using 'sep' to separate the index from the value. """ |
|
1283 | 1284 | |
|
1284 | 1285 | def __init__(self): |
|
1285 | 1286 | self.depth = 0 |
|
1286 | 1287 | |
|
1287 | 1288 | def __call__(self,lst,pos='',**kw): |
|
1288 | 1289 | """Prints the nested list numbering levels.""" |
|
1289 | 1290 | kw.setdefault('indent',' ') |
|
1290 | 1291 | kw.setdefault('sep',': ') |
|
1291 | 1292 | kw.setdefault('start',0) |
|
1292 | 1293 | kw.setdefault('stop',len(lst)) |
|
1293 | 1294 | # we need to remove start and stop from kw so they don't propagate |
|
1294 | 1295 | # into a recursive call for a nested list. |
|
1295 | 1296 | start = kw['start']; del kw['start'] |
|
1296 | 1297 | stop = kw['stop']; del kw['stop'] |
|
1297 | 1298 | if self.depth == 0 and 'header' in kw.keys(): |
|
1298 | 1299 | print kw['header'] |
|
1299 | 1300 | |
|
1300 | 1301 | for idx in range(start,stop): |
|
1301 | 1302 | elem = lst[idx] |
|
1302 | 1303 | if type(elem)==type([]): |
|
1303 | 1304 | self.depth += 1 |
|
1304 | 1305 | self.__call__(elem,itpl('$pos$idx,'),**kw) |
|
1305 | 1306 | self.depth -= 1 |
|
1306 | 1307 | else: |
|
1307 | 1308 | printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem') |
|
1308 | 1309 | |
|
1309 | 1310 | nlprint = NLprinter() |
|
1310 | 1311 | #---------------------------------------------------------------------------- |
|
1311 | 1312 | def all_belong(candidates,checklist): |
|
1312 | 1313 | """Check whether a list of items ALL appear in a given list of options. |
|
1313 | 1314 | |
|
1314 | 1315 | Returns a single 1 or 0 value.""" |
|
1315 | 1316 | |
|
1316 | 1317 | return 1-(0 in [x in checklist for x in candidates]) |
|
1317 | 1318 | |
|
1318 | 1319 | #---------------------------------------------------------------------------- |
|
1319 | 1320 | def sort_compare(lst1,lst2,inplace = 1): |
|
1320 | 1321 | """Sort and compare two lists. |
|
1321 | 1322 | |
|
1322 | 1323 | By default it does it in place, thus modifying the lists. Use inplace = 0 |
|
1323 | 1324 | to avoid that (at the cost of temporary copy creation).""" |
|
1324 | 1325 | if not inplace: |
|
1325 | 1326 | lst1 = lst1[:] |
|
1326 | 1327 | lst2 = lst2[:] |
|
1327 | 1328 | lst1.sort(); lst2.sort() |
|
1328 | 1329 | return lst1 == lst2 |
|
1329 | 1330 | |
|
1330 | 1331 | #---------------------------------------------------------------------------- |
|
1331 | 1332 | def mkdict(**kwargs): |
|
1332 | 1333 | """Return a dict from a keyword list. |
|
1333 | 1334 | |
|
1334 | 1335 | It's just syntactic sugar for making ditcionary creation more convenient: |
|
1335 | 1336 | # the standard way |
|
1336 | 1337 | >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 } |
|
1337 | 1338 | # a cleaner way |
|
1338 | 1339 | >>>data = dict(red=1, green=2, blue=3) |
|
1339 | 1340 | |
|
1340 | 1341 | If you need more than this, look at the Struct() class.""" |
|
1341 | 1342 | |
|
1342 | 1343 | return kwargs |
|
1343 | 1344 | |
|
1344 | 1345 | #---------------------------------------------------------------------------- |
|
1345 | 1346 | def list2dict(lst): |
|
1346 | 1347 | """Takes a list of (key,value) pairs and turns it into a dict.""" |
|
1347 | 1348 | |
|
1348 | 1349 | dic = {} |
|
1349 | 1350 | for k,v in lst: dic[k] = v |
|
1350 | 1351 | return dic |
|
1351 | 1352 | |
|
1352 | 1353 | #---------------------------------------------------------------------------- |
|
1353 | 1354 | def list2dict2(lst,default=''): |
|
1354 | 1355 | """Takes a list and turns it into a dict. |
|
1355 | 1356 | Much slower than list2dict, but more versatile. This version can take |
|
1356 | 1357 | lists with sublists of arbitrary length (including sclars).""" |
|
1357 | 1358 | |
|
1358 | 1359 | dic = {} |
|
1359 | 1360 | for elem in lst: |
|
1360 | 1361 | if type(elem) in (types.ListType,types.TupleType): |
|
1361 | 1362 | size = len(elem) |
|
1362 | 1363 | if size == 0: |
|
1363 | 1364 | pass |
|
1364 | 1365 | elif size == 1: |
|
1365 | 1366 | dic[elem] = default |
|
1366 | 1367 | else: |
|
1367 | 1368 | k,v = elem[0], elem[1:] |
|
1368 | 1369 | if len(v) == 1: v = v[0] |
|
1369 | 1370 | dic[k] = v |
|
1370 | 1371 | else: |
|
1371 | 1372 | dic[elem] = default |
|
1372 | 1373 | return dic |
|
1373 | 1374 | |
|
1374 | 1375 | #---------------------------------------------------------------------------- |
|
1375 | 1376 | def flatten(seq): |
|
1376 | 1377 | """Flatten a list of lists (NOT recursive, only works for 2d lists).""" |
|
1377 | 1378 | |
|
1378 | 1379 | # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in). |
|
1379 | 1380 | |
|
1380 | 1381 | # if the x=0 isn't made, a *global* variable x is left over after calling |
|
1381 | 1382 | # this function, with the value of the last element in the return |
|
1382 | 1383 | # list. This does seem like a bug big time to me. |
|
1383 | 1384 | |
|
1384 | 1385 | # the problem is fixed with the x=0, which seems to force the creation of |
|
1385 | 1386 | # a local name |
|
1386 | 1387 | |
|
1387 | 1388 | x = 0 |
|
1388 | 1389 | return [x for subseq in seq for x in subseq] |
|
1389 | 1390 | |
|
1390 | 1391 | #---------------------------------------------------------------------------- |
|
1391 | 1392 | def get_slice(seq,start=0,stop=None,step=1): |
|
1392 | 1393 | """Get a slice of a sequence with variable step. Specify start,stop,step.""" |
|
1393 | 1394 | if stop == None: |
|
1394 | 1395 | stop = len(seq) |
|
1395 | 1396 | item = lambda i: seq[i] |
|
1396 | 1397 | return map(item,xrange(start,stop,step)) |
|
1397 | 1398 | |
|
1398 | 1399 | #---------------------------------------------------------------------------- |
|
1399 | 1400 | def chop(seq,size): |
|
1400 | 1401 | """Chop a sequence into chunks of the given size.""" |
|
1401 | 1402 | chunk = lambda i: seq[i:i+size] |
|
1402 | 1403 | return map(chunk,xrange(0,len(seq),size)) |
|
1403 | 1404 | |
|
1404 | 1405 | #---------------------------------------------------------------------------- |
|
1405 | 1406 | def with(object, **args): |
|
1406 | 1407 | """Set multiple attributes for an object, similar to Pascal's with. |
|
1407 | 1408 | |
|
1408 | 1409 | Example: |
|
1409 | 1410 | with(jim, |
|
1410 | 1411 | born = 1960, |
|
1411 | 1412 | haircolour = 'Brown', |
|
1412 | 1413 | eyecolour = 'Green') |
|
1413 | 1414 | |
|
1414 | 1415 | Credit: Greg Ewing, in |
|
1415 | 1416 | http://mail.python.org/pipermail/python-list/2001-May/040703.html""" |
|
1416 | 1417 | |
|
1417 | 1418 | object.__dict__.update(args) |
|
1418 | 1419 | |
|
1419 | 1420 | #---------------------------------------------------------------------------- |
|
1420 | 1421 | def setattr_list(obj,alist,nspace = None): |
|
1421 | 1422 | """Set a list of attributes for an object taken from a namespace. |
|
1422 | 1423 | |
|
1423 | 1424 | setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in |
|
1424 | 1425 | alist with their values taken from nspace, which must be a dict (something |
|
1425 | 1426 | like locals() will often do) If nspace isn't given, locals() of the |
|
1426 | 1427 | *caller* is used, so in most cases you can omit it. |
|
1427 | 1428 | |
|
1428 | 1429 | Note that alist can be given as a string, which will be automatically |
|
1429 | 1430 | split into a list on whitespace. If given as a list, it must be a list of |
|
1430 | 1431 | *strings* (the variable names themselves), not of variables.""" |
|
1431 | 1432 | |
|
1432 | 1433 | # this grabs the local variables from the *previous* call frame -- that is |
|
1433 | 1434 | # the locals from the function that called setattr_list(). |
|
1434 | 1435 | # - snipped from weave.inline() |
|
1435 | 1436 | if nspace is None: |
|
1436 | 1437 | call_frame = sys._getframe().f_back |
|
1437 | 1438 | nspace = call_frame.f_locals |
|
1438 | 1439 | |
|
1439 | 1440 | if type(alist) in StringTypes: |
|
1440 | 1441 | alist = alist.split() |
|
1441 | 1442 | for attr in alist: |
|
1442 | 1443 | val = eval(attr,nspace) |
|
1443 | 1444 | setattr(obj,attr,val) |
|
1444 | 1445 | |
|
1445 | 1446 | #---------------------------------------------------------------------------- |
|
1446 | 1447 | def getattr_list(obj,alist,*args): |
|
1447 | 1448 | """getattr_list(obj,alist[, default]) -> attribute list. |
|
1448 | 1449 | |
|
1449 | 1450 | Get a list of named attributes for an object. When a default argument is |
|
1450 | 1451 | given, it is returned when the attribute doesn't exist; without it, an |
|
1451 | 1452 | exception is raised in that case. |
|
1452 | 1453 | |
|
1453 | 1454 | Note that alist can be given as a string, which will be automatically |
|
1454 | 1455 | split into a list on whitespace. If given as a list, it must be a list of |
|
1455 | 1456 | *strings* (the variable names themselves), not of variables.""" |
|
1456 | 1457 | |
|
1457 | 1458 | if type(alist) in StringTypes: |
|
1458 | 1459 | alist = alist.split() |
|
1459 | 1460 | if args: |
|
1460 | 1461 | if len(args)==1: |
|
1461 | 1462 | default = args[0] |
|
1462 | 1463 | return map(lambda attr: getattr(obj,attr,default),alist) |
|
1463 | 1464 | else: |
|
1464 | 1465 | raise ValueError,'getattr_list() takes only one optional argument' |
|
1465 | 1466 | else: |
|
1466 | 1467 | return map(lambda attr: getattr(obj,attr),alist) |
|
1467 | 1468 | |
|
1468 | 1469 | #---------------------------------------------------------------------------- |
|
1469 | 1470 | def map_method(method,object_list,*argseq,**kw): |
|
1470 | 1471 | """map_method(method,object_list,*args,**kw) -> list |
|
1471 | 1472 | |
|
1472 | 1473 | Return a list of the results of applying the methods to the items of the |
|
1473 | 1474 | argument sequence(s). If more than one sequence is given, the method is |
|
1474 | 1475 | called with an argument list consisting of the corresponding item of each |
|
1475 | 1476 | sequence. All sequences must be of the same length. |
|
1476 | 1477 | |
|
1477 | 1478 | Keyword arguments are passed verbatim to all objects called. |
|
1478 | 1479 | |
|
1479 | 1480 | This is Python code, so it's not nearly as fast as the builtin map().""" |
|
1480 | 1481 | |
|
1481 | 1482 | out_list = [] |
|
1482 | 1483 | idx = 0 |
|
1483 | 1484 | for object in object_list: |
|
1484 | 1485 | try: |
|
1485 | 1486 | handler = getattr(object, method) |
|
1486 | 1487 | except AttributeError: |
|
1487 | 1488 | out_list.append(None) |
|
1488 | 1489 | else: |
|
1489 | 1490 | if argseq: |
|
1490 | 1491 | args = map(lambda lst:lst[idx],argseq) |
|
1491 | 1492 | #print 'ob',object,'hand',handler,'ar',args # dbg |
|
1492 | 1493 | out_list.append(handler(args,**kw)) |
|
1493 | 1494 | else: |
|
1494 | 1495 | out_list.append(handler(**kw)) |
|
1495 | 1496 | idx += 1 |
|
1496 | 1497 | return out_list |
|
1497 | 1498 | |
|
1498 | 1499 | #---------------------------------------------------------------------------- |
|
1499 | 1500 | # Proposed popitem() extension, written as a method |
|
1500 | 1501 | |
|
1501 | 1502 | class NotGiven: pass |
|
1502 | 1503 | |
|
1503 | 1504 | def popkey(dct,key,default=NotGiven): |
|
1504 | 1505 | """Return dct[key] and delete dct[key]. |
|
1505 | 1506 | |
|
1506 | 1507 | If default is given, return it if dct[key] doesn't exist, otherwise raise |
|
1507 | 1508 | KeyError. """ |
|
1508 | 1509 | |
|
1509 | 1510 | try: |
|
1510 | 1511 | val = dct[key] |
|
1511 | 1512 | except KeyError: |
|
1512 | 1513 | if default is NotGiven: |
|
1513 | 1514 | raise |
|
1514 | 1515 | else: |
|
1515 | 1516 | return default |
|
1516 | 1517 | else: |
|
1517 | 1518 | del dct[key] |
|
1518 | 1519 | return val |
|
1519 | 1520 | #*************************** end of file <genutils.py> ********************** |
|
1520 | 1521 |
@@ -1,1999 +1,2004 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | IPython -- An enhanced Interactive Python |
|
4 | 4 | |
|
5 | 5 | Requires Python 2.1 or newer. |
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py |
|
|
9 | $Id: iplib.py 703 2005-08-16 17:34:44Z fperez $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
|
13 | 13 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
14 | 14 | # Copyright (C) 2001-2004 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, much of that class has been copied |
|
21 | 21 | # verbatim here for modifications which could not be accomplished by |
|
22 | 22 | # subclassing. The Python License (sec. 2) allows for this, but it's always |
|
23 | 23 | # nice to acknowledge credit where credit is due. |
|
24 | 24 | #***************************************************************************** |
|
25 | 25 | |
|
26 | 26 | #**************************************************************************** |
|
27 | 27 | # Modules and globals |
|
28 | 28 | |
|
29 | 29 | from __future__ import generators # for 2.2 backwards-compatibility |
|
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 exceptions |
|
41 | 41 | import keyword |
|
42 | 42 | import new |
|
43 | 43 | import os, sys, shutil |
|
44 | 44 | import code, glob, types, re |
|
45 | 45 | import string, StringIO |
|
46 | 46 | import inspect, pydoc |
|
47 | 47 | import bdb, pdb |
|
48 | 48 | import UserList # don't subclass list so this works with Python2.1 |
|
49 | 49 | from pprint import pprint, pformat |
|
50 | 50 | import cPickle as pickle |
|
51 | 51 | import traceback |
|
52 | 52 | |
|
53 | 53 | # IPython's own modules |
|
54 | 54 | import IPython |
|
55 | 55 | from IPython import OInspect,PyColorize,ultraTB |
|
56 | 56 | from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names |
|
57 | 57 | from IPython.Logger import Logger |
|
58 | 58 | from IPython.Magic import Magic,magic2python,shlex_split |
|
59 | 59 | from IPython.usage import cmd_line_usage,interactive_usage |
|
60 | 60 | from IPython.Struct import Struct |
|
61 | 61 | from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns |
|
62 | 62 | from IPython.FakeModule import FakeModule |
|
63 | 63 | from IPython.background_jobs import BackgroundJobManager |
|
64 | 64 | from IPython.genutils import * |
|
65 | 65 | |
|
66 | 66 | # Global pointer to the running |
|
67 | 67 | |
|
68 | 68 | # store the builtin raw_input globally, and use this always, in case user code |
|
69 | 69 | # overwrites it (like wx.py.PyShell does) |
|
70 | 70 | raw_input_original = raw_input |
|
71 | 71 | |
|
72 | 72 | #**************************************************************************** |
|
73 | 73 | # Some utility function definitions |
|
74 | 74 | |
|
75 | 75 | class Bunch: pass |
|
76 | 76 | |
|
77 | 77 | def esc_quotes(strng): |
|
78 | 78 | """Return the input string with single and double quotes escaped out""" |
|
79 | 79 | |
|
80 | 80 | return strng.replace('"','\\"').replace("'","\\'") |
|
81 | 81 | |
|
82 | 82 | def import_fail_info(mod_name,fns=None): |
|
83 | 83 | """Inform load failure for a module.""" |
|
84 | 84 | |
|
85 | 85 | if fns == None: |
|
86 | 86 | warn("Loading of %s failed.\n" % (mod_name,)) |
|
87 | 87 | else: |
|
88 | 88 | warn("Loading of %s from %s failed.\n" % (fns,mod_name)) |
|
89 | 89 | |
|
90 | 90 | def qw_lol(indata): |
|
91 | 91 | """qw_lol('a b') -> [['a','b']], |
|
92 | 92 | otherwise it's just a call to qw(). |
|
93 | 93 | |
|
94 | 94 | We need this to make sure the modules_some keys *always* end up as a |
|
95 | 95 | list of lists.""" |
|
96 | 96 | |
|
97 | 97 | if type(indata) in StringTypes: |
|
98 | 98 | return [qw(indata)] |
|
99 | 99 | else: |
|
100 | 100 | return qw(indata) |
|
101 | 101 | |
|
102 | 102 | def ipmagic(arg_s): |
|
103 | 103 | """Call a magic function by name. |
|
104 | 104 | |
|
105 | 105 | Input: a string containing the name of the magic function to call and any |
|
106 | 106 | additional arguments to be passed to the magic. |
|
107 | 107 | |
|
108 | 108 | ipmagic('name -opt foo bar') is equivalent to typing at the ipython |
|
109 | 109 | prompt: |
|
110 | 110 | |
|
111 | 111 | In[1]: %name -opt foo bar |
|
112 | 112 | |
|
113 | 113 | To call a magic without arguments, simply use ipmagic('name'). |
|
114 | 114 | |
|
115 | 115 | This provides a proper Python function to call IPython's magics in any |
|
116 | 116 | valid Python code you can type at the interpreter, including loops and |
|
117 | 117 | compound statements. It is added by IPython to the Python builtin |
|
118 | 118 | namespace upon initialization.""" |
|
119 | 119 | |
|
120 | 120 | args = arg_s.split(' ',1) |
|
121 | 121 | magic_name = args[0] |
|
122 | 122 | if magic_name.startswith(__IPYTHON__.ESC_MAGIC): |
|
123 | 123 | magic_name = magic_name[1:] |
|
124 | 124 | try: |
|
125 | 125 | magic_args = args[1] |
|
126 | 126 | except IndexError: |
|
127 | 127 | magic_args = '' |
|
128 | 128 | fn = getattr(__IPYTHON__,'magic_'+magic_name,None) |
|
129 | 129 | if fn is None: |
|
130 | 130 | error("Magic function `%s` not found." % magic_name) |
|
131 | 131 | else: |
|
132 | 132 | magic_args = __IPYTHON__.var_expand(magic_args) |
|
133 | 133 | return fn(magic_args) |
|
134 | 134 | |
|
135 | 135 | def ipalias(arg_s): |
|
136 | 136 | """Call an alias by name. |
|
137 | 137 | |
|
138 | 138 | Input: a string containing the name of the alias to call and any |
|
139 | 139 | additional arguments to be passed to the magic. |
|
140 | 140 | |
|
141 | 141 | ipalias('name -opt foo bar') is equivalent to typing at the ipython |
|
142 | 142 | prompt: |
|
143 | 143 | |
|
144 | 144 | In[1]: name -opt foo bar |
|
145 | 145 | |
|
146 | 146 | To call an alias without arguments, simply use ipalias('name'). |
|
147 | 147 | |
|
148 | 148 | This provides a proper Python function to call IPython's aliases in any |
|
149 | 149 | valid Python code you can type at the interpreter, including loops and |
|
150 | 150 | compound statements. It is added by IPython to the Python builtin |
|
151 | 151 | namespace upon initialization.""" |
|
152 | 152 | |
|
153 | 153 | args = arg_s.split(' ',1) |
|
154 | 154 | alias_name = args[0] |
|
155 | 155 | try: |
|
156 | 156 | alias_args = args[1] |
|
157 | 157 | except IndexError: |
|
158 | 158 | alias_args = '' |
|
159 | 159 | if alias_name in __IPYTHON__.alias_table: |
|
160 | 160 | __IPYTHON__.call_alias(alias_name,alias_args) |
|
161 | 161 | else: |
|
162 | 162 | error("Alias `%s` not found." % alias_name) |
|
163 | 163 | |
|
164 | 164 | #----------------------------------------------------------------------------- |
|
165 | 165 | # Local use classes |
|
166 | 166 | try: |
|
167 | 167 | from IPython import FlexCompleter |
|
168 | 168 | |
|
169 | 169 | class MagicCompleter(FlexCompleter.Completer): |
|
170 | 170 | """Extension of the completer class to work on %-prefixed lines.""" |
|
171 | 171 | |
|
172 | 172 | def __init__(self,shell,namespace=None,omit__names=0,alias_table=None): |
|
173 | 173 | """MagicCompleter() -> completer |
|
174 | 174 | |
|
175 | 175 | Return a completer object suitable for use by the readline library |
|
176 | 176 | via readline.set_completer(). |
|
177 | 177 | |
|
178 | 178 | Inputs: |
|
179 | 179 | |
|
180 | 180 | - shell: a pointer to the ipython shell itself. This is needed |
|
181 | 181 | because this completer knows about magic functions, and those can |
|
182 | 182 | only be accessed via the ipython instance. |
|
183 | 183 | |
|
184 | 184 | - namespace: an optional dict where completions are performed. |
|
185 | 185 | |
|
186 | 186 | - The optional omit__names parameter sets the completer to omit the |
|
187 | 187 | 'magic' names (__magicname__) for python objects unless the text |
|
188 | 188 | to be completed explicitly starts with one or more underscores. |
|
189 | 189 | |
|
190 | 190 | - If alias_table is supplied, it should be a dictionary of aliases |
|
191 | 191 | to complete. """ |
|
192 | 192 | |
|
193 | 193 | FlexCompleter.Completer.__init__(self,namespace) |
|
194 | 194 | self.magic_prefix = shell.name+'.magic_' |
|
195 | 195 | self.magic_escape = shell.ESC_MAGIC |
|
196 | 196 | self.readline = FlexCompleter.readline |
|
197 | 197 | delims = self.readline.get_completer_delims() |
|
198 | 198 | delims = delims.replace(self.magic_escape,'') |
|
199 | 199 | self.readline.set_completer_delims(delims) |
|
200 | 200 | self.get_line_buffer = self.readline.get_line_buffer |
|
201 | 201 | self.omit__names = omit__names |
|
202 | 202 | self.merge_completions = shell.rc.readline_merge_completions |
|
203 | 203 | |
|
204 | 204 | if alias_table is None: |
|
205 | 205 | alias_table = {} |
|
206 | 206 | self.alias_table = alias_table |
|
207 | 207 | # Regexp to split filenames with spaces in them |
|
208 | 208 | self.space_name_re = re.compile(r'([^\\] )') |
|
209 | 209 | # Hold a local ref. to glob.glob for speed |
|
210 | 210 | self.glob = glob.glob |
|
211 | 211 | # Special handling of backslashes needed in win32 platforms |
|
212 | 212 | if sys.platform == "win32": |
|
213 | 213 | self.clean_glob = self._clean_glob_win32 |
|
214 | 214 | else: |
|
215 | 215 | self.clean_glob = self._clean_glob |
|
216 | 216 | self.matchers = [self.python_matches, |
|
217 | 217 | self.file_matches, |
|
218 | 218 | self.alias_matches, |
|
219 | 219 | self.python_func_kw_matches] |
|
220 | 220 | |
|
221 | 221 | # Code contributed by Alex Schmolck, for ipython/emacs integration |
|
222 | 222 | def all_completions(self, text): |
|
223 | 223 | """Return all possible completions for the benefit of emacs.""" |
|
224 | 224 | |
|
225 | 225 | completions = [] |
|
226 | 226 | try: |
|
227 | 227 | for i in xrange(sys.maxint): |
|
228 | 228 | res = self.complete(text, i) |
|
229 | 229 | |
|
230 | 230 | if not res: break |
|
231 | 231 | |
|
232 | 232 | completions.append(res) |
|
233 | 233 | #XXX workaround for ``notDefined.<tab>`` |
|
234 | 234 | except NameError: |
|
235 | 235 | pass |
|
236 | 236 | return completions |
|
237 | 237 | # /end Alex Schmolck code. |
|
238 | 238 | |
|
239 | 239 | def _clean_glob(self,text): |
|
240 | 240 | return self.glob("%s*" % text) |
|
241 | 241 | |
|
242 | 242 | def _clean_glob_win32(self,text): |
|
243 | 243 | return [f.replace("\\","/") |
|
244 | 244 | for f in self.glob("%s*" % text)] |
|
245 | 245 | |
|
246 | 246 | def file_matches(self, text): |
|
247 | 247 | """Match filneames, expanding ~USER type strings. |
|
248 | 248 | |
|
249 | 249 | Most of the seemingly convoluted logic in this completer is an |
|
250 | 250 | attempt to handle filenames with spaces in them. And yet it's not |
|
251 | 251 | quite perfect, because Python's readline doesn't expose all of the |
|
252 | 252 | GNU readline details needed for this to be done correctly. |
|
253 | 253 | |
|
254 | 254 | For a filename with a space in it, the printed completions will be |
|
255 | 255 | only the parts after what's already been typed (instead of the |
|
256 | 256 | full completions, as is normally done). I don't think with the |
|
257 | 257 | current (as of Python 2.3) Python readline it's possible to do |
|
258 | 258 | better.""" |
|
259 | 259 | |
|
260 | 260 | #print 'Completer->file_matches: <%s>' % text # dbg |
|
261 | 261 | |
|
262 | 262 | # chars that require escaping with backslash - i.e. chars |
|
263 | 263 | # that readline treats incorrectly as delimiters, but we |
|
264 | 264 | # don't want to treat as delimiters in filename matching |
|
265 | 265 | # when escaped with backslash |
|
266 | 266 | |
|
267 | 267 | protectables = ' ()[]{}' |
|
268 | 268 | |
|
269 | 269 | def protect_filename(s): |
|
270 | 270 | return "".join([(ch in protectables and '\\' + ch or ch) |
|
271 | 271 | for ch in s]) |
|
272 | 272 | |
|
273 | 273 | lbuf = self.get_line_buffer()[:self.readline.get_endidx()] |
|
274 | 274 | open_quotes = 0 # track strings with open quotes |
|
275 | 275 | try: |
|
276 | 276 | lsplit = shlex_split(lbuf)[-1] |
|
277 | 277 | except ValueError: |
|
278 | 278 | # typically an unmatched ", or backslash without escaped char. |
|
279 | 279 | if lbuf.count('"')==1: |
|
280 | 280 | open_quotes = 1 |
|
281 | 281 | lsplit = lbuf.split('"')[-1] |
|
282 | 282 | elif lbuf.count("'")==1: |
|
283 | 283 | open_quotes = 1 |
|
284 | 284 | lsplit = lbuf.split("'")[-1] |
|
285 | 285 | else: |
|
286 | 286 | return None |
|
287 | 287 | except IndexError: |
|
288 | 288 | # tab pressed on empty line |
|
289 | 289 | lsplit = "" |
|
290 | 290 | |
|
291 | 291 | if lsplit != protect_filename(lsplit): |
|
292 | 292 | # if protectables are found, do matching on the whole escaped |
|
293 | 293 | # name |
|
294 | 294 | has_protectables = 1 |
|
295 | 295 | text0,text = text,lsplit |
|
296 | 296 | else: |
|
297 | 297 | has_protectables = 0 |
|
298 | 298 | text = os.path.expanduser(text) |
|
299 | 299 | |
|
300 | 300 | if text == "": |
|
301 | 301 | return [protect_filename(f) for f in self.glob("*")] |
|
302 | 302 | |
|
303 | 303 | m0 = self.clean_glob(text.replace('\\','')) |
|
304 | 304 | if has_protectables: |
|
305 | 305 | # If we had protectables, we need to revert our changes to the |
|
306 | 306 | # beginning of filename so that we don't double-write the part |
|
307 | 307 | # of the filename we have so far |
|
308 | 308 | len_lsplit = len(lsplit) |
|
309 | 309 | matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0] |
|
310 | 310 | else: |
|
311 | 311 | if open_quotes: |
|
312 | 312 | # if we have a string with an open quote, we don't need to |
|
313 | 313 | # protect the names at all (and we _shouldn't_, as it |
|
314 | 314 | # would cause bugs when the filesystem call is made). |
|
315 | 315 | matches = m0 |
|
316 | 316 | else: |
|
317 | 317 | matches = [protect_filename(f) for f in m0] |
|
318 | 318 | if len(matches) == 1 and os.path.isdir(matches[0]): |
|
319 | 319 | # Takes care of links to directories also. Use '/' |
|
320 | 320 | # explicitly, even under Windows, so that name completions |
|
321 | 321 | # don't end up escaped. |
|
322 | 322 | matches[0] += '/' |
|
323 | 323 | return matches |
|
324 | 324 | |
|
325 | 325 | def alias_matches(self, text): |
|
326 | 326 | """Match internal system aliases""" |
|
327 | 327 | #print 'Completer->alias_matches:',text # dbg |
|
328 | 328 | text = os.path.expanduser(text) |
|
329 | 329 | aliases = self.alias_table.keys() |
|
330 | 330 | if text == "": |
|
331 | 331 | return aliases |
|
332 | 332 | else: |
|
333 | 333 | return [alias for alias in aliases if alias.startswith(text)] |
|
334 | 334 | |
|
335 | 335 | def python_matches(self,text): |
|
336 | 336 | """Match attributes or global python names""" |
|
337 | 337 | #print 'Completer->python_matches' # dbg |
|
338 | 338 | if "." in text: |
|
339 | 339 | try: |
|
340 | 340 | matches = self.attr_matches(text) |
|
341 | 341 | if text.endswith('.') and self.omit__names: |
|
342 | 342 | if self.omit__names == 1: |
|
343 | 343 | # true if txt is _not_ a __ name, false otherwise: |
|
344 | 344 | no__name = (lambda txt: |
|
345 | 345 | re.match(r'.*\.__.*?__',txt) is None) |
|
346 | 346 | else: |
|
347 | 347 | # true if txt is _not_ a _ name, false otherwise: |
|
348 | 348 | no__name = (lambda txt: |
|
349 | 349 | re.match(r'.*\._.*?',txt) is None) |
|
350 | 350 | matches = filter(no__name, matches) |
|
351 | 351 | except NameError: |
|
352 | 352 | # catches <undefined attributes>.<tab> |
|
353 | 353 | matches = [] |
|
354 | 354 | else: |
|
355 | 355 | matches = self.global_matches(text) |
|
356 | 356 | # this is so completion finds magics when automagic is on: |
|
357 | 357 | if matches == [] and not text.startswith(os.sep): |
|
358 | 358 | matches = self.attr_matches(self.magic_prefix+text) |
|
359 | 359 | return matches |
|
360 | 360 | |
|
361 | 361 | def _default_arguments(self, obj): |
|
362 | 362 | """Return the list of default arguments of obj if it is callable, |
|
363 | 363 | or empty list otherwise.""" |
|
364 | 364 | |
|
365 | 365 | if not (inspect.isfunction(obj) or inspect.ismethod(obj)): |
|
366 | 366 | # for classes, check for __init__,__new__ |
|
367 | 367 | if inspect.isclass(obj): |
|
368 | 368 | obj = (getattr(obj,'__init__',None) or |
|
369 | 369 | getattr(obj,'__new__',None)) |
|
370 | 370 | # for all others, check if they are __call__able |
|
371 | 371 | elif hasattr(obj, '__call__'): |
|
372 | 372 | obj = obj.__call__ |
|
373 | 373 | # XXX: is there a way to handle the builtins ? |
|
374 | 374 | try: |
|
375 | 375 | args,_,_1,defaults = inspect.getargspec(obj) |
|
376 | 376 | if defaults: |
|
377 | 377 | return args[-len(defaults):] |
|
378 | 378 | except TypeError: pass |
|
379 | 379 | return [] |
|
380 | 380 | |
|
381 | 381 | def python_func_kw_matches(self,text): |
|
382 | 382 | """Match named parameters (kwargs) of the last open function""" |
|
383 | 383 | |
|
384 | 384 | if "." in text: # a parameter cannot be dotted |
|
385 | 385 | return [] |
|
386 | 386 | try: regexp = self.__funcParamsRegex |
|
387 | 387 | except AttributeError: |
|
388 | 388 | regexp = self.__funcParamsRegex = re.compile(r''' |
|
389 | 389 | '.*?' | # single quoted strings or |
|
390 | 390 | ".*?" | # double quoted strings or |
|
391 | 391 | \w+ | # identifier |
|
392 | 392 | \S # other characters |
|
393 | 393 | ''', re.VERBOSE | re.DOTALL) |
|
394 | 394 | # 1. find the nearest identifier that comes before an unclosed |
|
395 | 395 | # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo" |
|
396 | 396 | tokens = regexp.findall(self.get_line_buffer()) |
|
397 | 397 | tokens.reverse() |
|
398 | 398 | iterTokens = iter(tokens); openPar = 0 |
|
399 | 399 | for token in iterTokens: |
|
400 | 400 | if token == ')': |
|
401 | 401 | openPar -= 1 |
|
402 | 402 | elif token == '(': |
|
403 | 403 | openPar += 1 |
|
404 | 404 | if openPar > 0: |
|
405 | 405 | # found the last unclosed parenthesis |
|
406 | 406 | break |
|
407 | 407 | else: |
|
408 | 408 | return [] |
|
409 | 409 | # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" ) |
|
410 | 410 | ids = [] |
|
411 | 411 | isId = re.compile(r'\w+$').match |
|
412 | 412 | while True: |
|
413 | 413 | try: |
|
414 | 414 | ids.append(iterTokens.next()) |
|
415 | 415 | if not isId(ids[-1]): |
|
416 | 416 | ids.pop(); break |
|
417 | 417 | if not iterTokens.next() == '.': |
|
418 | 418 | break |
|
419 | 419 | except StopIteration: |
|
420 | 420 | break |
|
421 | 421 | # lookup the candidate callable matches either using global_matches |
|
422 | 422 | # or attr_matches for dotted names |
|
423 | 423 | if len(ids) == 1: |
|
424 | 424 | callableMatches = self.global_matches(ids[0]) |
|
425 | 425 | else: |
|
426 | 426 | callableMatches = self.attr_matches('.'.join(ids[::-1])) |
|
427 | 427 | argMatches = [] |
|
428 | 428 | for callableMatch in callableMatches: |
|
429 | 429 | try: namedArgs = self._default_arguments(eval(callableMatch, |
|
430 | 430 | self.namespace)) |
|
431 | 431 | except: continue |
|
432 | 432 | for namedArg in namedArgs: |
|
433 | 433 | if namedArg.startswith(text): |
|
434 | 434 | argMatches.append("%s=" %namedArg) |
|
435 | 435 | return argMatches |
|
436 | 436 | |
|
437 | 437 | def complete(self, text, state): |
|
438 | 438 | """Return the next possible completion for 'text'. |
|
439 | 439 | |
|
440 | 440 | This is called successively with state == 0, 1, 2, ... until it |
|
441 | 441 | returns None. The completion should begin with 'text'. """ |
|
442 | 442 | |
|
443 | 443 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg |
|
444 | 444 | magic_escape = self.magic_escape |
|
445 | 445 | magic_prefix = self.magic_prefix |
|
446 | 446 | |
|
447 | 447 | try: |
|
448 | 448 | if text.startswith(magic_escape): |
|
449 | 449 | text = text.replace(magic_escape,magic_prefix) |
|
450 | 450 | elif text.startswith('~'): |
|
451 | 451 | text = os.path.expanduser(text) |
|
452 | 452 | if state == 0: |
|
453 | 453 | # Extend the list of completions with the results of each |
|
454 | 454 | # matcher, so we return results to the user from all |
|
455 | 455 | # namespaces. |
|
456 | 456 | if self.merge_completions: |
|
457 | 457 | self.matches = [] |
|
458 | 458 | for matcher in self.matchers: |
|
459 | 459 | self.matches.extend(matcher(text)) |
|
460 | 460 | else: |
|
461 | 461 | for matcher in self.matchers: |
|
462 | 462 | self.matches = matcher(text) |
|
463 | 463 | if self.matches: |
|
464 | 464 | break |
|
465 | 465 | |
|
466 | 466 | try: |
|
467 | 467 | return self.matches[state].replace(magic_prefix,magic_escape) |
|
468 | 468 | except IndexError: |
|
469 | 469 | return None |
|
470 | 470 | except: |
|
471 | 471 | # If completion fails, don't annoy the user. |
|
472 | 472 | pass |
|
473 | 473 | |
|
474 | 474 | except ImportError: |
|
475 | 475 | pass # no readline support |
|
476 | 476 | |
|
477 | 477 | except KeyError: |
|
478 | 478 | pass # Windows doesn't set TERM, it doesn't matter |
|
479 | 479 | |
|
480 | 480 | |
|
481 | 481 | class InputList(UserList.UserList): |
|
482 | 482 | """Class to store user input. |
|
483 | 483 | |
|
484 | 484 | It's basically a list, but slices return a string instead of a list, thus |
|
485 | 485 | allowing things like (assuming 'In' is an instance): |
|
486 | 486 | |
|
487 | 487 | exec In[4:7] |
|
488 | 488 | |
|
489 | 489 | or |
|
490 | 490 | |
|
491 | 491 | exec In[5:9] + In[14] + In[21:25]""" |
|
492 | 492 | |
|
493 | 493 | def __getslice__(self,i,j): |
|
494 | 494 | return ''.join(UserList.UserList.__getslice__(self,i,j)) |
|
495 | 495 | |
|
496 | 496 | #**************************************************************************** |
|
497 | 497 | # Local use exceptions |
|
498 | 498 | class SpaceInInput(exceptions.Exception): |
|
499 | 499 | pass |
|
500 | 500 | |
|
501 | 501 | #**************************************************************************** |
|
502 | 502 | # Main IPython class |
|
503 | 503 | |
|
504 | 504 | class InteractiveShell(code.InteractiveConsole, Logger, Magic): |
|
505 | 505 | """An enhanced console for Python.""" |
|
506 | 506 | |
|
507 | 507 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
508 | 508 | user_ns = None,banner2='', |
|
509 | 509 | custom_exceptions=((),None)): |
|
510 | 510 | |
|
511 | 511 | # Put a reference to self in builtins so that any form of embedded or |
|
512 | 512 | # imported code can test for being inside IPython. |
|
513 | 513 | __builtin__.__IPYTHON__ = self |
|
514 | 514 | |
|
515 | 515 | # And load into builtins ipmagic/ipalias as well |
|
516 | 516 | __builtin__.ipmagic = ipmagic |
|
517 | 517 | __builtin__.ipalias = ipalias |
|
518 | 518 | |
|
519 | 519 | # Add to __builtin__ other parts of IPython's public API |
|
520 | 520 | __builtin__.ip_set_hook = self.set_hook |
|
521 | 521 | |
|
522 | 522 | # Keep in the builtins a flag for when IPython is active. We set it |
|
523 | 523 | # with setdefault so that multiple nested IPythons don't clobber one |
|
524 | 524 | # another. Each will increase its value by one upon being activated, |
|
525 | 525 | # which also gives us a way to determine the nesting level. |
|
526 | 526 | __builtin__.__dict__.setdefault('__IPYTHON__active',0) |
|
527 | 527 | |
|
528 | 528 | # Inform the user of ipython's fast exit magics. |
|
529 | 529 | _exit = ' Use %Exit or %Quit to exit without confirmation.' |
|
530 | 530 | __builtin__.exit += _exit |
|
531 | 531 | __builtin__.quit += _exit |
|
532 | 532 | |
|
533 | 533 | # Create the namespace where the user will operate: |
|
534 | 534 | |
|
535 | 535 | # FIXME. For some strange reason, __builtins__ is showing up at user |
|
536 | 536 | # level as a dict instead of a module. This is a manual fix, but I |
|
537 | 537 | # should really track down where the problem is coming from. Alex |
|
538 | 538 | # Schmolck reported this problem first. |
|
539 | 539 | |
|
540 | 540 | # A useful post by Alex Martelli on this topic: |
|
541 | 541 | # Re: inconsistent value from __builtins__ |
|
542 | 542 | # Von: Alex Martelli <aleaxit@yahoo.com> |
|
543 | 543 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends |
|
544 | 544 | # Gruppen: comp.lang.python |
|
545 | 545 | # Referenzen: 1 |
|
546 | 546 | |
|
547 | 547 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: |
|
548 | 548 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) |
|
549 | 549 | # > <type 'dict'> |
|
550 | 550 | # > >>> print type(__builtins__) |
|
551 | 551 | # > <type 'module'> |
|
552 | 552 | # > Is this difference in return value intentional? |
|
553 | 553 | |
|
554 | 554 | # Well, it's documented that '__builtins__' can be either a dictionary |
|
555 | 555 | # or a module, and it's been that way for a long time. Whether it's |
|
556 | 556 | # intentional (or sensible), I don't know. In any case, the idea is that |
|
557 | 557 | # if you need to access the built-in namespace directly, you should start |
|
558 | 558 | # with "import __builtin__" (note, no 's') which will definitely give you |
|
559 | 559 | # a module. Yeah, it's somewhatΒ confusing:-(. |
|
560 | 560 | |
|
561 | 561 | if user_ns is None: |
|
562 | 562 | # Set __name__ to __main__ to better match the behavior of the |
|
563 | 563 | # normal interpreter. |
|
564 | 564 | self.user_ns = {'__name__' :'__main__', |
|
565 | 565 | '__builtins__' : __builtin__, |
|
566 | 566 | } |
|
567 | 567 | else: |
|
568 | 568 | self.user_ns = user_ns |
|
569 | 569 | |
|
570 | 570 | # The user namespace MUST have a pointer to the shell itself. |
|
571 | 571 | self.user_ns[name] = self |
|
572 | 572 | |
|
573 | 573 | # We need to insert into sys.modules something that looks like a |
|
574 | 574 | # module but which accesses the IPython namespace, for shelve and |
|
575 | 575 | # pickle to work interactively. Normally they rely on getting |
|
576 | 576 | # everything out of __main__, but for embedding purposes each IPython |
|
577 | 577 | # instance has its own private namespace, so we can't go shoving |
|
578 | 578 | # everything into __main__. |
|
579 | 579 | |
|
580 | 580 | try: |
|
581 | 581 | main_name = self.user_ns['__name__'] |
|
582 | 582 | except KeyError: |
|
583 | 583 | raise KeyError,'user_ns dictionary MUST have a "__name__" key' |
|
584 | 584 | else: |
|
585 | 585 | #print "pickle hack in place" # dbg |
|
586 | 586 | sys.modules[main_name] = FakeModule(self.user_ns) |
|
587 | 587 | |
|
588 | 588 | # List of input with multi-line handling. |
|
589 | 589 | # Fill its zero entry, user counter starts at 1 |
|
590 | 590 | self.input_hist = InputList(['\n']) |
|
591 | 591 | |
|
592 | 592 | # list of visited directories |
|
593 | 593 | self.dir_hist = [os.getcwd()] |
|
594 | 594 | |
|
595 | 595 | # dict of output history |
|
596 | 596 | self.output_hist = {} |
|
597 | 597 | |
|
598 | 598 | # dict of names to be treated as system aliases. Each entry in the |
|
599 | 599 | # alias table must be a 2-tuple of the form (N,name), where N is the |
|
600 | 600 | # number of positional arguments of the alias. |
|
601 | 601 | self.alias_table = {} |
|
602 | 602 | |
|
603 | 603 | # dict of things NOT to alias (keywords and builtins) |
|
604 | 604 | self.no_alias = {} |
|
605 | 605 | for key in keyword.kwlist: |
|
606 | 606 | self.no_alias[key] = 1 |
|
607 | 607 | self.no_alias.update(__builtin__.__dict__) |
|
608 | 608 | |
|
609 | 609 | # make global variables for user access to these |
|
610 | 610 | self.user_ns['_ih'] = self.input_hist |
|
611 | 611 | self.user_ns['_oh'] = self.output_hist |
|
612 | 612 | self.user_ns['_dh'] = self.dir_hist |
|
613 | 613 | |
|
614 | 614 | # user aliases to input and output histories |
|
615 | 615 | self.user_ns['In'] = self.input_hist |
|
616 | 616 | self.user_ns['Out'] = self.output_hist |
|
617 | 617 | |
|
618 | 618 | # Store the actual shell's name |
|
619 | 619 | self.name = name |
|
620 | 620 | |
|
621 | 621 | # Object variable to store code object waiting execution. This is |
|
622 | 622 | # used mainly by the multithreaded shells, but it can come in handy in |
|
623 | 623 | # other situations. No need to use a Queue here, since it's a single |
|
624 | 624 | # item which gets cleared once run. |
|
625 | 625 | self.code_to_run = None |
|
626 | self.code_to_run_src = '' # corresponding source | |
|
627 | 626 | |
|
628 | 627 | # Job manager (for jobs run as background threads) |
|
629 | 628 | self.jobs = BackgroundJobManager() |
|
630 | 629 | # Put the job manager into builtins so it's always there. |
|
631 | 630 | __builtin__.jobs = self.jobs |
|
632 | 631 | |
|
633 | 632 | # escapes for automatic behavior on the command line |
|
634 | 633 | self.ESC_SHELL = '!' |
|
635 | 634 | self.ESC_HELP = '?' |
|
636 | 635 | self.ESC_MAGIC = '%' |
|
637 | 636 | self.ESC_QUOTE = ',' |
|
638 | 637 | self.ESC_QUOTE2 = ';' |
|
639 | 638 | self.ESC_PAREN = '/' |
|
640 | 639 | |
|
641 | 640 | # And their associated handlers |
|
642 | 641 | self.esc_handlers = {self.ESC_PAREN:self.handle_auto, |
|
643 | 642 | self.ESC_QUOTE:self.handle_auto, |
|
644 | 643 | self.ESC_QUOTE2:self.handle_auto, |
|
645 | 644 | self.ESC_MAGIC:self.handle_magic, |
|
646 | 645 | self.ESC_HELP:self.handle_help, |
|
647 | 646 | self.ESC_SHELL:self.handle_shell_escape, |
|
648 | 647 | } |
|
649 | 648 | |
|
650 | 649 | # class initializations |
|
651 | 650 | code.InteractiveConsole.__init__(self,locals = self.user_ns) |
|
652 | 651 | Logger.__init__(self,log_ns = self.user_ns) |
|
653 | 652 | Magic.__init__(self,self) |
|
654 | 653 | |
|
655 | 654 | # an ugly hack to get a pointer to the shell, so I can start writing |
|
656 | 655 | # magic code via this pointer instead of the current mixin salad. |
|
657 | 656 | Magic.set_shell(self,self) |
|
658 | 657 | |
|
659 | 658 | # hooks holds pointers used for user-side customizations |
|
660 | 659 | self.hooks = Struct() |
|
661 | 660 | |
|
662 | 661 | # Set all default hooks, defined in the IPython.hooks module. |
|
663 | 662 | hooks = IPython.hooks |
|
664 | 663 | for hook_name in hooks.__all__: |
|
665 | 664 | self.set_hook(hook_name,getattr(hooks,hook_name)) |
|
666 | 665 | |
|
667 | 666 | # Flag to mark unconditional exit |
|
668 | 667 | self.exit_now = False |
|
669 | 668 | |
|
670 | 669 | self.usage_min = """\ |
|
671 | 670 | An enhanced console for Python. |
|
672 | 671 | Some of its features are: |
|
673 | 672 | - Readline support if the readline library is present. |
|
674 | 673 | - Tab completion in the local namespace. |
|
675 | 674 | - Logging of input, see command-line options. |
|
676 | 675 | - System shell escape via ! , eg !ls. |
|
677 | 676 | - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.) |
|
678 | 677 | - Keeps track of locally defined variables via %who, %whos. |
|
679 | 678 | - Show object information with a ? eg ?x or x? (use ?? for more info). |
|
680 | 679 | """ |
|
681 | 680 | if usage: self.usage = usage |
|
682 | 681 | else: self.usage = self.usage_min |
|
683 | 682 | |
|
684 | 683 | # Storage |
|
685 | 684 | self.rc = rc # This will hold all configuration information |
|
686 | 685 | self.inputcache = [] |
|
687 | 686 | self._boundcache = [] |
|
688 | 687 | self.pager = 'less' |
|
689 | 688 | # temporary files used for various purposes. Deleted at exit. |
|
690 | 689 | self.tempfiles = [] |
|
691 | 690 | |
|
692 | 691 | # for pushd/popd management |
|
693 | 692 | try: |
|
694 | 693 | self.home_dir = get_home_dir() |
|
695 | 694 | except HomeDirError,msg: |
|
696 | 695 | fatal(msg) |
|
697 | 696 | |
|
698 | 697 | self.dir_stack = [os.getcwd().replace(self.home_dir,'~')] |
|
699 | 698 | |
|
700 | 699 | # Functions to call the underlying shell. |
|
701 | 700 | |
|
702 | 701 | # utility to expand user variables via Itpl |
|
703 | 702 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), |
|
704 | 703 | self.user_ns)) |
|
705 | 704 | # The first is similar to os.system, but it doesn't return a value, |
|
706 | 705 | # and it allows interpolation of variables in the user's namespace. |
|
707 | 706 | self.system = lambda cmd: shell(self.var_expand(cmd), |
|
708 | 707 | header='IPython system call: ', |
|
709 | 708 | verbose=self.rc.system_verbose) |
|
710 | 709 | # These are for getoutput and getoutputerror: |
|
711 | 710 | self.getoutput = lambda cmd: \ |
|
712 | 711 | getoutput(self.var_expand(cmd), |
|
713 | 712 | header='IPython system call: ', |
|
714 | 713 | verbose=self.rc.system_verbose) |
|
715 | 714 | self.getoutputerror = lambda cmd: \ |
|
716 | 715 | getoutputerror(str(ItplNS(cmd.replace('#','\#'), |
|
717 | 716 | self.user_ns)), |
|
718 | 717 | header='IPython system call: ', |
|
719 | 718 | verbose=self.rc.system_verbose) |
|
720 | 719 | |
|
721 | 720 | # RegExp for splitting line contents into pre-char//first |
|
722 | 721 | # word-method//rest. For clarity, each group in on one line. |
|
723 | 722 | |
|
724 | 723 | # WARNING: update the regexp if the above escapes are changed, as they |
|
725 | 724 | # are hardwired in. |
|
726 | 725 | |
|
727 | 726 | # Don't get carried away with trying to make the autocalling catch too |
|
728 | 727 | # much: it's better to be conservative rather than to trigger hidden |
|
729 | 728 | # evals() somewhere and end up causing side effects. |
|
730 | 729 | |
|
731 | 730 | self.line_split = re.compile(r'^([\s*,;/])' |
|
732 | 731 | r'([\?\w\.]+\w*\s*)' |
|
733 | 732 | r'(\(?.*$)') |
|
734 | 733 | |
|
735 | 734 | # Original re, keep around for a while in case changes break something |
|
736 | 735 | #self.line_split = re.compile(r'(^[\s*!\?%,/]?)' |
|
737 | 736 | # r'(\s*[\?\w\.]+\w*\s*)' |
|
738 | 737 | # r'(\(?.*$)') |
|
739 | 738 | |
|
740 | 739 | # RegExp to identify potential function names |
|
741 | 740 | self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') |
|
742 | 741 | # RegExp to exclude strings with this start from autocalling |
|
743 | 742 | self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ') |
|
744 | 743 | # try to catch also methods for stuff in lists/tuples/dicts: off |
|
745 | 744 | # (experimental). For this to work, the line_split regexp would need |
|
746 | 745 | # to be modified so it wouldn't break things at '['. That line is |
|
747 | 746 | # nasty enough that I shouldn't change it until I can test it _well_. |
|
748 | 747 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') |
|
749 | 748 | |
|
750 | 749 | # keep track of where we started running (mainly for crash post-mortem) |
|
751 | 750 | self.starting_dir = os.getcwd() |
|
752 | 751 | |
|
753 | 752 | # Attributes for Logger mixin class, make defaults here |
|
754 | 753 | self._dolog = 0 |
|
755 | 754 | self.LOG = '' |
|
756 | 755 | self.LOGDEF = '.InteractiveShell.log' |
|
757 | 756 | self.LOGMODE = 'over' |
|
758 | 757 | self.LOGHEAD = Itpl( |
|
759 | 758 | """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE *** |
|
760 | 759 | #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW |
|
761 | 760 | #log# opts = $self.rc.opts |
|
762 | 761 | #log# args = $self.rc.args |
|
763 | 762 | #log# It is safe to make manual edits below here. |
|
764 | 763 | #log#----------------------------------------------------------------------- |
|
765 | 764 | """) |
|
766 | 765 | # Various switches which can be set |
|
767 | 766 | self.CACHELENGTH = 5000 # this is cheap, it's just text |
|
768 | 767 | self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__ |
|
769 | 768 | self.banner2 = banner2 |
|
770 | 769 | |
|
771 | 770 | # TraceBack handlers: |
|
772 | 771 | # Need two, one for syntax errors and one for other exceptions. |
|
773 | 772 | self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor') |
|
774 | 773 | # This one is initialized with an offset, meaning we always want to |
|
775 | 774 | # remove the topmost item in the traceback, which is our own internal |
|
776 | 775 | # code. Valid modes: ['Plain','Context','Verbose'] |
|
777 | 776 | self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain', |
|
778 | 777 | color_scheme='NoColor', |
|
779 | 778 | tb_offset = 1) |
|
780 | 779 | # and add any custom exception handlers the user may have specified |
|
781 | 780 | self.set_custom_exc(*custom_exceptions) |
|
782 | 781 | |
|
783 | 782 | # Object inspector |
|
784 | 783 | ins_colors = OInspect.InspectColors |
|
785 | 784 | code_colors = PyColorize.ANSICodeColors |
|
786 | 785 | self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor') |
|
787 | 786 | self.autoindent = 0 |
|
788 | 787 | |
|
789 | 788 | # Make some aliases automatically |
|
790 | 789 | # Prepare list of shell aliases to auto-define |
|
791 | 790 | if os.name == 'posix': |
|
792 | 791 | auto_alias = ('mkdir mkdir', 'rmdir rmdir', |
|
793 | 792 | 'mv mv -i','rm rm -i','cp cp -i', |
|
794 | 793 | 'cat cat','less less','clear clear', |
|
795 | 794 | # a better ls |
|
796 | 795 | 'ls ls -F', |
|
797 | 796 | # long ls |
|
798 | 797 | 'll ls -lF', |
|
799 | 798 | # color ls |
|
800 | 799 | 'lc ls -F -o --color', |
|
801 | 800 | # ls normal files only |
|
802 | 801 | 'lf ls -F -o --color %l | grep ^-', |
|
803 | 802 | # ls symbolic links |
|
804 | 803 | 'lk ls -F -o --color %l | grep ^l', |
|
805 | 804 | # directories or links to directories, |
|
806 | 805 | 'ldir ls -F -o --color %l | grep /$', |
|
807 | 806 | # things which are executable |
|
808 | 807 | 'lx ls -F -o --color %l | grep ^-..x', |
|
809 | 808 | ) |
|
810 | 809 | elif os.name in ['nt','dos']: |
|
811 | 810 | auto_alias = ('dir dir /on', 'ls dir /on', |
|
812 | 811 | 'ddir dir /ad /on', 'ldir dir /ad /on', |
|
813 | 812 | 'mkdir mkdir','rmdir rmdir','echo echo', |
|
814 | 813 | 'ren ren','cls cls','copy copy') |
|
815 | 814 | else: |
|
816 | 815 | auto_alias = () |
|
817 | 816 | self.auto_alias = map(lambda s:s.split(None,1),auto_alias) |
|
818 | 817 | # Call the actual (public) initializer |
|
819 | 818 | self.init_auto_alias() |
|
820 | 819 | # end __init__ |
|
821 | 820 | |
|
822 | 821 | def set_hook(self,name,hook): |
|
823 | 822 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
824 | 823 | |
|
825 | 824 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
826 | 825 | resetting one of these hooks, you can modify IPython's behavior to |
|
827 | 826 | call at runtime your own routines.""" |
|
828 | 827 | |
|
829 | 828 | # At some point in the future, this should validate the hook before it |
|
830 | 829 | # accepts it. Probably at least check that the hook takes the number |
|
831 | 830 | # of args it's supposed to. |
|
832 | 831 | setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__)) |
|
833 | 832 | |
|
834 | 833 | def set_custom_exc(self,exc_tuple,handler): |
|
835 | 834 | """set_custom_exc(exc_tuple,handler) |
|
836 | 835 | |
|
837 | 836 | Set a custom exception handler, which will be called if any of the |
|
838 | 837 | exceptions in exc_tuple occur in the mainloop (specifically, in the |
|
839 | 838 | runcode() method. |
|
840 | 839 | |
|
841 | 840 | Inputs: |
|
842 | 841 | |
|
843 | 842 | - exc_tuple: a *tuple* of valid exceptions to call the defined |
|
844 | 843 | handler for. It is very important that you use a tuple, and NOT A |
|
845 | 844 | LIST here, because of the way Python's except statement works. If |
|
846 | 845 | you only want to trap a single exception, use a singleton tuple: |
|
847 | 846 | |
|
848 | 847 | exc_tuple == (MyCustomException,) |
|
849 | 848 | |
|
850 | 849 | - handler: this must be defined as a function with the following |
|
851 | 850 | basic interface: def my_handler(self,etype,value,tb). |
|
852 | 851 | |
|
853 | 852 | This will be made into an instance method (via new.instancemethod) |
|
854 | 853 | of IPython itself, and it will be called if any of the exceptions |
|
855 | 854 | listed in the exc_tuple are caught. If the handler is None, an |
|
856 | 855 | internal basic one is used, which just prints basic info. |
|
857 | 856 | |
|
858 | 857 | WARNING: by putting in your own exception handler into IPython's main |
|
859 | 858 | execution loop, you run a very good chance of nasty crashes. This |
|
860 | 859 | facility should only be used if you really know what you are doing.""" |
|
861 | 860 | |
|
862 | 861 | assert type(exc_tuple)==type(()) , \ |
|
863 | 862 | "The custom exceptions must be given AS A TUPLE." |
|
864 | 863 | |
|
865 | 864 | def dummy_handler(self,etype,value,tb): |
|
866 | 865 | print '*** Simple custom exception handler ***' |
|
867 | 866 | print 'Exception type :',etype |
|
868 | 867 | print 'Exception value:',value |
|
869 | 868 | print 'Traceback :',tb |
|
870 |
print 'Source code :',self. |
|
|
869 | print 'Source code :','\n'.join(self.buffer) | |
|
871 | 870 | |
|
872 | 871 | if handler is None: handler = dummy_handler |
|
873 | 872 | |
|
874 | 873 | self.CustomTB = new.instancemethod(handler,self,self.__class__) |
|
875 | 874 | self.custom_exceptions = exc_tuple |
|
876 | 875 | |
|
877 | 876 | def set_custom_completer(self,completer,pos=0): |
|
878 | 877 | """set_custom_completer(completer,pos=0) |
|
879 | 878 | |
|
880 | 879 | Adds a new custom completer function. |
|
881 | 880 | |
|
882 | 881 | The position argument (defaults to 0) is the index in the completers |
|
883 | 882 | list where you want the completer to be inserted.""" |
|
884 | 883 | |
|
885 | 884 | newcomp = new.instancemethod(completer,self.Completer, |
|
886 | 885 | self.Completer.__class__) |
|
887 | 886 | self.Completer.matchers.insert(pos,newcomp) |
|
888 | 887 | |
|
889 | 888 | def post_config_initialization(self): |
|
890 | 889 | """Post configuration init method |
|
891 | 890 | |
|
892 | 891 | This is called after the configuration files have been processed to |
|
893 | 892 | 'finalize' the initialization.""" |
|
894 | 893 | |
|
895 | 894 | # dynamic data that survives through sessions |
|
896 | 895 | # XXX make the filename a config option? |
|
897 | 896 | persist_base = 'persist' |
|
898 | 897 | if self.rc.profile: |
|
899 | 898 | persist_base += '_%s' % self.rc.profile |
|
900 | 899 | self.persist_fname = os.path.join(self.rc.ipythondir,persist_base) |
|
901 | 900 | |
|
902 | 901 | try: |
|
903 | 902 | self.persist = pickle.load(file(self.persist_fname)) |
|
904 | 903 | except: |
|
905 | 904 | self.persist = {} |
|
906 | 905 | |
|
907 | 906 | def init_auto_alias(self): |
|
908 | 907 | """Define some aliases automatically. |
|
909 | 908 | |
|
910 | 909 | These are ALL parameter-less aliases""" |
|
911 | 910 | for alias,cmd in self.auto_alias: |
|
912 | 911 | self.alias_table[alias] = (0,cmd) |
|
913 | 912 | |
|
914 | 913 | def alias_table_validate(self,verbose=0): |
|
915 | 914 | """Update information about the alias table. |
|
916 | 915 | |
|
917 | 916 | In particular, make sure no Python keywords/builtins are in it.""" |
|
918 | 917 | |
|
919 | 918 | no_alias = self.no_alias |
|
920 | 919 | for k in self.alias_table.keys(): |
|
921 | 920 | if k in no_alias: |
|
922 | 921 | del self.alias_table[k] |
|
923 | 922 | if verbose: |
|
924 | 923 | print ("Deleting alias <%s>, it's a Python " |
|
925 | 924 | "keyword or builtin." % k) |
|
926 | 925 | |
|
927 | 926 | def set_autoindent(self,value=None): |
|
928 | 927 | """Set the autoindent flag, checking for readline support. |
|
929 | 928 | |
|
930 | 929 | If called with no arguments, it acts as a toggle.""" |
|
931 | 930 | |
|
932 | 931 | if not self.has_readline: |
|
933 | 932 | if os.name == 'posix': |
|
934 | 933 | warn("The auto-indent feature requires the readline library") |
|
935 | 934 | self.autoindent = 0 |
|
936 | 935 | return |
|
937 | 936 | if value is None: |
|
938 | 937 | self.autoindent = not self.autoindent |
|
939 | 938 | else: |
|
940 | 939 | self.autoindent = value |
|
941 | 940 | |
|
942 | 941 | def rc_set_toggle(self,rc_field,value=None): |
|
943 | 942 | """Set or toggle a field in IPython's rc config. structure. |
|
944 | 943 | |
|
945 | 944 | If called with no arguments, it acts as a toggle. |
|
946 | 945 | |
|
947 | 946 | If called with a non-existent field, the resulting AttributeError |
|
948 | 947 | exception will propagate out.""" |
|
949 | 948 | |
|
950 | 949 | rc_val = getattr(self.rc,rc_field) |
|
951 | 950 | if value is None: |
|
952 | 951 | value = not rc_val |
|
953 | 952 | setattr(self.rc,rc_field,value) |
|
954 | 953 | |
|
955 | 954 | def user_setup(self,ipythondir,rc_suffix,mode='install'): |
|
956 | 955 | """Install the user configuration directory. |
|
957 | 956 | |
|
958 | 957 | Can be called when running for the first time or to upgrade the user's |
|
959 | 958 | .ipython/ directory with the mode parameter. Valid modes are 'install' |
|
960 | 959 | and 'upgrade'.""" |
|
961 | 960 | |
|
962 | 961 | def wait(): |
|
963 | 962 | try: |
|
964 | 963 | raw_input("Please press <RETURN> to start IPython.") |
|
965 | 964 | except EOFError: |
|
966 | 965 | print >> Term.cout |
|
967 | 966 | print '*'*70 |
|
968 | 967 | |
|
969 | 968 | cwd = os.getcwd() # remember where we started |
|
970 | 969 | glb = glob.glob |
|
971 | 970 | print '*'*70 |
|
972 | 971 | if mode == 'install': |
|
973 | 972 | print \ |
|
974 | 973 | """Welcome to IPython. I will try to create a personal configuration directory |
|
975 | 974 | where you can customize many aspects of IPython's functionality in:\n""" |
|
976 | 975 | else: |
|
977 | 976 | print 'I am going to upgrade your configuration in:' |
|
978 | 977 | |
|
979 | 978 | print ipythondir |
|
980 | 979 | |
|
981 | 980 | rcdirend = os.path.join('IPython','UserConfig') |
|
982 | 981 | cfg = lambda d: os.path.join(d,rcdirend) |
|
983 | 982 | try: |
|
984 | 983 | rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] |
|
985 | 984 | except IOError: |
|
986 | 985 | warning = """ |
|
987 | 986 | Installation error. IPython's directory was not found. |
|
988 | 987 | |
|
989 | 988 | Check the following: |
|
990 | 989 | |
|
991 | 990 | The ipython/IPython directory should be in a directory belonging to your |
|
992 | 991 | PYTHONPATH environment variable (that is, it should be in a directory |
|
993 | 992 | belonging to sys.path). You can copy it explicitly there or just link to it. |
|
994 | 993 | |
|
995 | 994 | IPython will proceed with builtin defaults. |
|
996 | 995 | """ |
|
997 | 996 | warn(warning) |
|
998 | 997 | wait() |
|
999 | 998 | return |
|
1000 | 999 | |
|
1001 | 1000 | if mode == 'install': |
|
1002 | 1001 | try: |
|
1003 | 1002 | shutil.copytree(rcdir,ipythondir) |
|
1004 | 1003 | os.chdir(ipythondir) |
|
1005 | 1004 | rc_files = glb("ipythonrc*") |
|
1006 | 1005 | for rc_file in rc_files: |
|
1007 | 1006 | os.rename(rc_file,rc_file+rc_suffix) |
|
1008 | 1007 | except: |
|
1009 | 1008 | warning = """ |
|
1010 | 1009 | |
|
1011 | 1010 | There was a problem with the installation: |
|
1012 | 1011 | %s |
|
1013 | 1012 | Try to correct it or contact the developers if you think it's a bug. |
|
1014 | 1013 | IPython will proceed with builtin defaults.""" % sys.exc_info()[1] |
|
1015 | 1014 | warn(warning) |
|
1016 | 1015 | wait() |
|
1017 | 1016 | return |
|
1018 | 1017 | |
|
1019 | 1018 | elif mode == 'upgrade': |
|
1020 | 1019 | try: |
|
1021 | 1020 | os.chdir(ipythondir) |
|
1022 | 1021 | except: |
|
1023 | 1022 | print """ |
|
1024 | 1023 | Can not upgrade: changing to directory %s failed. Details: |
|
1025 | 1024 | %s |
|
1026 | 1025 | """ % (ipythondir,sys.exc_info()[1]) |
|
1027 | 1026 | wait() |
|
1028 | 1027 | return |
|
1029 | 1028 | else: |
|
1030 | 1029 | sources = glb(os.path.join(rcdir,'[A-Za-z]*')) |
|
1031 | 1030 | for new_full_path in sources: |
|
1032 | 1031 | new_filename = os.path.basename(new_full_path) |
|
1033 | 1032 | if new_filename.startswith('ipythonrc'): |
|
1034 | 1033 | new_filename = new_filename + rc_suffix |
|
1035 | 1034 | # The config directory should only contain files, skip any |
|
1036 | 1035 | # directories which may be there (like CVS) |
|
1037 | 1036 | if os.path.isdir(new_full_path): |
|
1038 | 1037 | continue |
|
1039 | 1038 | if os.path.exists(new_filename): |
|
1040 | 1039 | old_file = new_filename+'.old' |
|
1041 | 1040 | if os.path.exists(old_file): |
|
1042 | 1041 | os.remove(old_file) |
|
1043 | 1042 | os.rename(new_filename,old_file) |
|
1044 | 1043 | shutil.copy(new_full_path,new_filename) |
|
1045 | 1044 | else: |
|
1046 | 1045 | raise ValueError,'unrecognized mode for install:',`mode` |
|
1047 | 1046 | |
|
1048 | 1047 | # Fix line-endings to those native to each platform in the config |
|
1049 | 1048 | # directory. |
|
1050 | 1049 | try: |
|
1051 | 1050 | os.chdir(ipythondir) |
|
1052 | 1051 | except: |
|
1053 | 1052 | print """ |
|
1054 | 1053 | Problem: changing to directory %s failed. |
|
1055 | 1054 | Details: |
|
1056 | 1055 | %s |
|
1057 | 1056 | |
|
1058 | 1057 | Some configuration files may have incorrect line endings. This should not |
|
1059 | 1058 | cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) |
|
1060 | 1059 | wait() |
|
1061 | 1060 | else: |
|
1062 | 1061 | for fname in glb('ipythonrc*'): |
|
1063 | 1062 | try: |
|
1064 | 1063 | native_line_ends(fname,backup=0) |
|
1065 | 1064 | except IOError: |
|
1066 | 1065 | pass |
|
1067 | 1066 | |
|
1068 | 1067 | if mode == 'install': |
|
1069 | 1068 | print """ |
|
1070 | 1069 | Successful installation! |
|
1071 | 1070 | |
|
1072 | 1071 | Please read the sections 'Initial Configuration' and 'Quick Tips' in the |
|
1073 | 1072 | IPython manual (there are both HTML and PDF versions supplied with the |
|
1074 | 1073 | distribution) to make sure that your system environment is properly configured |
|
1075 | 1074 | to take advantage of IPython's features.""" |
|
1076 | 1075 | else: |
|
1077 | 1076 | print """ |
|
1078 | 1077 | Successful upgrade! |
|
1079 | 1078 | |
|
1080 | 1079 | All files in your directory: |
|
1081 | 1080 | %(ipythondir)s |
|
1082 | 1081 | which would have been overwritten by the upgrade were backed up with a .old |
|
1083 | 1082 | extension. If you had made particular customizations in those files you may |
|
1084 | 1083 | want to merge them back into the new files.""" % locals() |
|
1085 | 1084 | wait() |
|
1086 | 1085 | os.chdir(cwd) |
|
1087 | 1086 | # end user_setup() |
|
1088 | 1087 | |
|
1089 | 1088 | def atexit_operations(self): |
|
1090 | 1089 | """This will be executed at the time of exit. |
|
1091 | 1090 | |
|
1092 | 1091 | Saving of persistent data should be performed here. """ |
|
1093 | 1092 | |
|
1094 | 1093 | # input history |
|
1095 | 1094 | self.savehist() |
|
1096 | 1095 | |
|
1097 | 1096 | # Cleanup all tempfiles left around |
|
1098 | 1097 | for tfile in self.tempfiles: |
|
1099 | 1098 | try: |
|
1100 | 1099 | os.unlink(tfile) |
|
1101 | 1100 | except OSError: |
|
1102 | 1101 | pass |
|
1103 | 1102 | |
|
1104 | 1103 | # save the "persistent data" catch-all dictionary |
|
1105 | 1104 | try: |
|
1106 | 1105 | pickle.dump(self.persist, open(self.persist_fname,"w")) |
|
1107 | 1106 | except: |
|
1108 | 1107 | print "*** ERROR *** persistent data saving failed." |
|
1109 | 1108 | |
|
1110 | 1109 | def savehist(self): |
|
1111 | 1110 | """Save input history to a file (via readline library).""" |
|
1112 | 1111 | try: |
|
1113 | 1112 | self.readline.write_history_file(self.histfile) |
|
1114 | 1113 | except: |
|
1115 | 1114 | print 'Unable to save IPython command history to file: ' + \ |
|
1116 | 1115 | `self.histfile` |
|
1117 | 1116 | |
|
1118 | 1117 | def pre_readline(self): |
|
1119 | 1118 | """readline hook to be used at the start of each line. |
|
1120 | 1119 | |
|
1121 | 1120 | Currently it handles auto-indent only.""" |
|
1122 | 1121 | |
|
1123 | 1122 | self.readline.insert_text(' '* self.readline_indent) |
|
1124 | 1123 | |
|
1125 | 1124 | def init_readline(self): |
|
1126 | 1125 | """Command history completion/saving/reloading.""" |
|
1127 | 1126 | try: |
|
1128 | 1127 | import readline |
|
1129 | 1128 | self.Completer = MagicCompleter(self, |
|
1130 | 1129 | self.user_ns, |
|
1131 | 1130 | self.rc.readline_omit__names, |
|
1132 | 1131 | self.alias_table) |
|
1133 | 1132 | except ImportError,NameError: |
|
1134 | 1133 | # If FlexCompleter failed to import, MagicCompleter won't be |
|
1135 | 1134 | # defined. This can happen because of a problem with readline |
|
1136 | 1135 | self.has_readline = 0 |
|
1137 | 1136 | # no point in bugging windows users with this every time: |
|
1138 | 1137 | if os.name == 'posix': |
|
1139 | 1138 | warn('Readline services not available on this platform.') |
|
1140 | 1139 | else: |
|
1141 | 1140 | import atexit |
|
1142 | 1141 | |
|
1143 | 1142 | # Platform-specific configuration |
|
1144 | 1143 | if os.name == 'nt': |
|
1145 | 1144 | # readline under Windows modifies the default exit behavior |
|
1146 | 1145 | # from being Ctrl-Z/Return to the Unix Ctrl-D one. |
|
1147 | 1146 | __builtin__.exit = __builtin__.quit = \ |
|
1148 | 1147 | ('Use Ctrl-D (i.e. EOF) to exit. ' |
|
1149 | 1148 | 'Use %Exit or %Quit to exit without confirmation.') |
|
1150 | 1149 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1151 | 1150 | else: |
|
1152 | 1151 | self.readline_startup_hook = readline.set_startup_hook |
|
1153 | 1152 | |
|
1154 | 1153 | # Load user's initrc file (readline config) |
|
1155 | 1154 | inputrc_name = os.environ.get('INPUTRC') |
|
1156 | 1155 | if inputrc_name is None: |
|
1157 | 1156 | home_dir = get_home_dir() |
|
1158 | 1157 | if home_dir is not None: |
|
1159 | 1158 | inputrc_name = os.path.join(home_dir,'.inputrc') |
|
1160 | 1159 | if os.path.isfile(inputrc_name): |
|
1161 | 1160 | try: |
|
1162 | 1161 | readline.read_init_file(inputrc_name) |
|
1163 | 1162 | except: |
|
1164 | 1163 | warn('Problems reading readline initialization file <%s>' |
|
1165 | 1164 | % inputrc_name) |
|
1166 | 1165 | |
|
1167 | 1166 | self.has_readline = 1 |
|
1168 | 1167 | self.readline = readline |
|
1169 | 1168 | self.readline_indent = 0 # for auto-indenting via readline |
|
1170 | 1169 | # save this in sys so embedded copies can restore it properly |
|
1171 | 1170 | sys.ipcompleter = self.Completer.complete |
|
1172 | 1171 | readline.set_completer(self.Completer.complete) |
|
1173 | 1172 | |
|
1174 | 1173 | # Configure readline according to user's prefs |
|
1175 | 1174 | for rlcommand in self.rc.readline_parse_and_bind: |
|
1176 | 1175 | readline.parse_and_bind(rlcommand) |
|
1177 | 1176 | |
|
1178 | 1177 | # remove some chars from the delimiters list |
|
1179 | 1178 | delims = readline.get_completer_delims() |
|
1180 | 1179 | delims = delims.translate(string._idmap, |
|
1181 | 1180 | self.rc.readline_remove_delims) |
|
1182 | 1181 | readline.set_completer_delims(delims) |
|
1183 | 1182 | # otherwise we end up with a monster history after a while: |
|
1184 | 1183 | readline.set_history_length(1000) |
|
1185 | 1184 | try: |
|
1186 | 1185 | #print '*** Reading readline history' # dbg |
|
1187 | 1186 | readline.read_history_file(self.histfile) |
|
1188 | 1187 | except IOError: |
|
1189 | 1188 | pass # It doesn't exist yet. |
|
1190 | 1189 | |
|
1191 | 1190 | atexit.register(self.atexit_operations) |
|
1192 | 1191 | del atexit |
|
1193 | 1192 | |
|
1194 | 1193 | # Configure auto-indent for all platforms |
|
1195 | 1194 | self.set_autoindent(self.rc.autoindent) |
|
1196 | 1195 | |
|
1197 | 1196 | def showsyntaxerror(self, filename=None): |
|
1198 | 1197 | """Display the syntax error that just occurred. |
|
1199 | 1198 | |
|
1200 | 1199 | This doesn't display a stack trace because there isn't one. |
|
1201 | 1200 | |
|
1202 | 1201 | If a filename is given, it is stuffed in the exception instead |
|
1203 | 1202 | of what was there before (because Python's parser always uses |
|
1204 | 1203 | "<string>" when reading from a string). |
|
1205 | 1204 | """ |
|
1206 | 1205 | type, value, sys.last_traceback = sys.exc_info() |
|
1207 | 1206 | sys.last_type = type |
|
1208 | 1207 | sys.last_value = value |
|
1209 | 1208 | if filename and type is SyntaxError: |
|
1210 | 1209 | # Work hard to stuff the correct filename in the exception |
|
1211 | 1210 | try: |
|
1212 | 1211 | msg, (dummy_filename, lineno, offset, line) = value |
|
1213 | 1212 | except: |
|
1214 | 1213 | # Not the format we expect; leave it alone |
|
1215 | 1214 | pass |
|
1216 | 1215 | else: |
|
1217 | 1216 | # Stuff in the right filename |
|
1218 | 1217 | try: |
|
1219 | 1218 | # Assume SyntaxError is a class exception |
|
1220 | 1219 | value = SyntaxError(msg, (filename, lineno, offset, line)) |
|
1221 | 1220 | except: |
|
1222 | 1221 | # If that failed, assume SyntaxError is a string |
|
1223 | 1222 | value = msg, (filename, lineno, offset, line) |
|
1224 | 1223 | self.SyntaxTB(type,value,[]) |
|
1225 | 1224 | |
|
1226 | 1225 | def debugger(self): |
|
1227 | 1226 | """Call the pdb debugger.""" |
|
1228 | 1227 | |
|
1229 | 1228 | if not self.rc.pdb: |
|
1230 | 1229 | return |
|
1231 | 1230 | pdb.pm() |
|
1232 | 1231 | |
|
1233 | 1232 | def showtraceback(self,exc_tuple = None): |
|
1234 | 1233 | """Display the exception that just occurred.""" |
|
1235 | 1234 | |
|
1236 | 1235 | # Though this won't be called by syntax errors in the input line, |
|
1237 | 1236 | # there may be SyntaxError cases whith imported code. |
|
1238 | 1237 | if exc_tuple is None: |
|
1239 | 1238 | type, value, tb = sys.exc_info() |
|
1240 | 1239 | else: |
|
1241 | 1240 | type, value, tb = exc_tuple |
|
1242 | 1241 | if type is SyntaxError: |
|
1243 | 1242 | self.showsyntaxerror() |
|
1244 | 1243 | else: |
|
1245 | 1244 | sys.last_type = type |
|
1246 | 1245 | sys.last_value = value |
|
1247 | 1246 | sys.last_traceback = tb |
|
1248 | 1247 | self.InteractiveTB() |
|
1249 | 1248 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1250 | 1249 | # pdb mucks up readline, fix it back |
|
1251 | 1250 | self.readline.set_completer(self.Completer.complete) |
|
1252 | 1251 | |
|
1253 | 1252 | def update_cache(self, line): |
|
1254 | 1253 | """puts line into cache""" |
|
1255 | 1254 | self.inputcache.insert(0, line) # This copies the cache every time ... :-( |
|
1256 | 1255 | if len(self.inputcache) >= self.CACHELENGTH: |
|
1257 | 1256 | self.inputcache.pop() # This not :-) |
|
1258 | 1257 | |
|
1259 | 1258 | def name_space_init(self): |
|
1260 | 1259 | """Create local namespace.""" |
|
1261 | 1260 | # We want this to be a method to facilitate embedded initialization. |
|
1262 | 1261 | code.InteractiveConsole.__init__(self,self.user_ns) |
|
1263 | 1262 | |
|
1264 | 1263 | def mainloop(self,banner=None): |
|
1265 | 1264 | """Creates the local namespace and starts the mainloop. |
|
1266 | 1265 | |
|
1267 | 1266 | If an optional banner argument is given, it will override the |
|
1268 | 1267 | internally created default banner.""" |
|
1269 | 1268 | |
|
1270 | 1269 | self.name_space_init() |
|
1271 | 1270 | if self.rc.c: # Emulate Python's -c option |
|
1272 | 1271 | self.exec_init_cmd() |
|
1273 | 1272 | if banner is None: |
|
1274 | 1273 | if self.rc.banner: |
|
1275 | 1274 | banner = self.BANNER+self.banner2 |
|
1276 | 1275 | else: |
|
1277 | 1276 | banner = '' |
|
1278 | 1277 | self.interact(banner) |
|
1279 | 1278 | |
|
1280 | 1279 | def exec_init_cmd(self): |
|
1281 | 1280 | """Execute a command given at the command line. |
|
1282 | 1281 | |
|
1283 | 1282 | This emulates Python's -c option.""" |
|
1284 | 1283 | |
|
1285 | 1284 | sys.argv = ['-c'] |
|
1286 | 1285 | self.push(self.rc.c) |
|
1287 | 1286 | |
|
1288 | 1287 | def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): |
|
1289 | 1288 | """Embeds IPython into a running python program. |
|
1290 | 1289 | |
|
1291 | 1290 | Input: |
|
1292 | 1291 | |
|
1293 | 1292 | - header: An optional header message can be specified. |
|
1294 | 1293 | |
|
1295 | 1294 | - local_ns, global_ns: working namespaces. If given as None, the |
|
1296 | 1295 | IPython-initialized one is updated with __main__.__dict__, so that |
|
1297 | 1296 | program variables become visible but user-specific configuration |
|
1298 | 1297 | remains possible. |
|
1299 | 1298 | |
|
1300 | 1299 | - stack_depth: specifies how many levels in the stack to go to |
|
1301 | 1300 | looking for namespaces (when local_ns and global_ns are None). This |
|
1302 | 1301 | allows an intermediate caller to make sure that this function gets |
|
1303 | 1302 | the namespace from the intended level in the stack. By default (0) |
|
1304 | 1303 | it will get its locals and globals from the immediate caller. |
|
1305 | 1304 | |
|
1306 | 1305 | Warning: it's possible to use this in a program which is being run by |
|
1307 | 1306 | IPython itself (via %run), but some funny things will happen (a few |
|
1308 | 1307 | globals get overwritten). In the future this will be cleaned up, as |
|
1309 | 1308 | there is no fundamental reason why it can't work perfectly.""" |
|
1310 | 1309 | |
|
1311 | 1310 | # Patch for global embedding to make sure that things don't overwrite |
|
1312 | 1311 | # user globals accidentally. Thanks to Richard <rxe@renre-europe.com> |
|
1313 | 1312 | # FIXME. Test this a bit more carefully (the if.. is new) |
|
1314 | 1313 | if local_ns is None and global_ns is None: |
|
1315 | 1314 | self.user_ns.update(__main__.__dict__) |
|
1316 | 1315 | |
|
1317 | 1316 | # Get locals and globals from caller |
|
1318 | 1317 | if local_ns is None or global_ns is None: |
|
1319 | 1318 | call_frame = sys._getframe(stack_depth).f_back |
|
1320 | 1319 | |
|
1321 | 1320 | if local_ns is None: |
|
1322 | 1321 | local_ns = call_frame.f_locals |
|
1323 | 1322 | if global_ns is None: |
|
1324 | 1323 | global_ns = call_frame.f_globals |
|
1325 | 1324 | |
|
1326 | 1325 | # Update namespaces and fire up interpreter |
|
1327 | 1326 | self.user_ns.update(local_ns) |
|
1328 | 1327 | self.interact(header) |
|
1329 | 1328 | |
|
1330 | 1329 | # Remove locals from namespace |
|
1331 | 1330 | for k in local_ns: |
|
1332 | 1331 | del self.user_ns[k] |
|
1333 | 1332 | |
|
1334 | 1333 | def interact(self, banner=None): |
|
1335 | 1334 | """Closely emulate the interactive Python console. |
|
1336 | 1335 | |
|
1337 | 1336 | The optional banner argument specify the banner to print |
|
1338 | 1337 | before the first interaction; by default it prints a banner |
|
1339 | 1338 | similar to the one printed by the real Python interpreter, |
|
1340 | 1339 | followed by the current class name in parentheses (so as not |
|
1341 | 1340 | to confuse this with the real interpreter -- since it's so |
|
1342 | 1341 | close!). |
|
1343 | 1342 | |
|
1344 | 1343 | """ |
|
1345 | 1344 | cprt = 'Type "copyright", "credits" or "license" for more information.' |
|
1346 | 1345 | if banner is None: |
|
1347 | 1346 | self.write("Python %s on %s\n%s\n(%s)\n" % |
|
1348 | 1347 | (sys.version, sys.platform, cprt, |
|
1349 | 1348 | self.__class__.__name__)) |
|
1350 | 1349 | else: |
|
1351 | 1350 | self.write(banner) |
|
1352 | 1351 | |
|
1353 | 1352 | more = 0 |
|
1354 | 1353 | |
|
1355 | 1354 | # Mark activity in the builtins |
|
1356 | 1355 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1357 | 1356 | |
|
1358 | 1357 | # exit_now is set by a call to %Exit or %Quit |
|
1359 | 1358 | while not self.exit_now: |
|
1360 | 1359 | try: |
|
1361 | 1360 | if more: |
|
1362 | 1361 | prompt = self.outputcache.prompt2 |
|
1363 | 1362 | if self.autoindent: |
|
1364 | 1363 | self.readline_startup_hook(self.pre_readline) |
|
1365 | 1364 | else: |
|
1366 | 1365 | prompt = self.outputcache.prompt1 |
|
1367 | 1366 | try: |
|
1368 | 1367 | line = self.raw_input(prompt) |
|
1369 | 1368 | if self.autoindent: |
|
1370 | 1369 | self.readline_startup_hook(None) |
|
1371 | 1370 | except EOFError: |
|
1372 | 1371 | if self.autoindent: |
|
1373 | 1372 | self.readline_startup_hook(None) |
|
1374 | 1373 | self.write("\n") |
|
1375 | 1374 | if self.rc.confirm_exit: |
|
1376 | 1375 | if ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
1377 | 1376 | break |
|
1378 | 1377 | else: |
|
1379 | 1378 | break |
|
1380 | 1379 | else: |
|
1381 | 1380 | more = self.push(line) |
|
1382 | 1381 | # Auto-indent management |
|
1383 | 1382 | if self.autoindent: |
|
1384 | 1383 | if line: |
|
1385 | 1384 | ini_spaces = re.match('^(\s+)',line) |
|
1386 | 1385 | if ini_spaces: |
|
1387 | 1386 | nspaces = ini_spaces.end() |
|
1388 | 1387 | else: |
|
1389 | 1388 | nspaces = 0 |
|
1390 | 1389 | self.readline_indent = nspaces |
|
1391 | 1390 | |
|
1392 | 1391 | if line[-1] == ':': |
|
1393 | 1392 | self.readline_indent += 4 |
|
1394 | 1393 | elif re.match(r'^\s+raise|^\s+return',line): |
|
1395 | 1394 | self.readline_indent -= 4 |
|
1396 | 1395 | else: |
|
1397 | 1396 | self.readline_indent = 0 |
|
1398 | 1397 | |
|
1399 | 1398 | except KeyboardInterrupt: |
|
1400 | 1399 | self.write("\nKeyboardInterrupt\n") |
|
1401 | 1400 | self.resetbuffer() |
|
1402 | 1401 | more = 0 |
|
1403 | 1402 | # keep cache in sync with the prompt counter: |
|
1404 | 1403 | self.outputcache.prompt_count -= 1 |
|
1405 | 1404 | |
|
1406 | 1405 | if self.autoindent: |
|
1407 | 1406 | self.readline_indent = 0 |
|
1408 | 1407 | |
|
1409 | 1408 | except bdb.BdbQuit: |
|
1410 | 1409 | warn("The Python debugger has exited with a BdbQuit exception.\n" |
|
1411 | 1410 | "Because of how pdb handles the stack, it is impossible\n" |
|
1412 | 1411 | "for IPython to properly format this particular exception.\n" |
|
1413 | 1412 | "IPython will resume normal operation.") |
|
1414 | 1413 | |
|
1415 | 1414 | # We are off again... |
|
1416 | 1415 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
|
1417 | 1416 | |
|
1418 | 1417 | def excepthook(self, type, value, tb): |
|
1419 | 1418 | """One more defense for GUI apps that call sys.excepthook. |
|
1420 | 1419 | |
|
1421 | 1420 | GUI frameworks like wxPython trap exceptions and call |
|
1422 | 1421 | sys.excepthook themselves. I guess this is a feature that |
|
1423 | 1422 | enables them to keep running after exceptions that would |
|
1424 | 1423 | otherwise kill their mainloop. This is a bother for IPython |
|
1425 | 1424 | which excepts to catch all of the program exceptions with a try: |
|
1426 | 1425 | except: statement. |
|
1427 | 1426 | |
|
1428 | 1427 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if |
|
1429 | 1428 | any app directly invokes sys.excepthook, it will look to the user like |
|
1430 | 1429 | IPython crashed. In order to work around this, we can disable the |
|
1431 | 1430 | CrashHandler and replace it with this excepthook instead, which prints a |
|
1432 | 1431 | regular traceback using our InteractiveTB. In this fashion, apps which |
|
1433 | 1432 | call sys.excepthook will generate a regular-looking exception from |
|
1434 | 1433 | IPython, and the CrashHandler will only be triggered by real IPython |
|
1435 | 1434 | crashes. |
|
1436 | 1435 | |
|
1437 | 1436 | This hook should be used sparingly, only in places which are not likely |
|
1438 | 1437 | to be true IPython errors. |
|
1439 | 1438 | """ |
|
1440 | 1439 | |
|
1441 | 1440 | self.InteractiveTB(type, value, tb, tb_offset=0) |
|
1442 | 1441 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1443 | 1442 | self.readline.set_completer(self.Completer.complete) |
|
1444 | 1443 | |
|
1445 | 1444 | def call_alias(self,alias,rest=''): |
|
1446 | 1445 | """Call an alias given its name and the rest of the line. |
|
1447 | 1446 | |
|
1448 | 1447 | This function MUST be given a proper alias, because it doesn't make |
|
1449 | 1448 | any checks when looking up into the alias table. The caller is |
|
1450 | 1449 | responsible for invoking it only with a valid alias.""" |
|
1451 | 1450 | |
|
1452 | 1451 | #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg |
|
1453 | 1452 | nargs,cmd = self.alias_table[alias] |
|
1454 | 1453 | # Expand the %l special to be the user's input line |
|
1455 | 1454 | if cmd.find('%l') >= 0: |
|
1456 | 1455 | cmd = cmd.replace('%l',rest) |
|
1457 | 1456 | rest = '' |
|
1458 | 1457 | if nargs==0: |
|
1459 | 1458 | # Simple, argument-less aliases |
|
1460 | 1459 | cmd = '%s %s' % (cmd,rest) |
|
1461 | 1460 | else: |
|
1462 | 1461 | # Handle aliases with positional arguments |
|
1463 | 1462 | args = rest.split(None,nargs) |
|
1464 | 1463 | if len(args)< nargs: |
|
1465 | 1464 | error('Alias <%s> requires %s arguments, %s given.' % |
|
1466 | 1465 | (alias,nargs,len(args))) |
|
1467 | 1466 | return |
|
1468 | 1467 | cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) |
|
1469 | 1468 | # Now call the macro, evaluating in the user's namespace |
|
1470 | 1469 | try: |
|
1471 | 1470 | self.system(cmd) |
|
1472 | 1471 | except: |
|
1473 | 1472 | self.showtraceback() |
|
1474 | 1473 | |
|
1475 | 1474 | def runlines(self,lines): |
|
1476 | 1475 | """Run a string of one or more lines of source. |
|
1477 | 1476 | |
|
1478 | 1477 | This method is capable of running a string containing multiple source |
|
1479 | 1478 | lines, as if they had been entered at the IPython prompt. Since it |
|
1480 | 1479 | exposes IPython's processing machinery, the given strings can contain |
|
1481 | 1480 | magic calls (%magic), special shell access (!cmd), etc.""" |
|
1482 | 1481 | |
|
1483 | 1482 | # We must start with a clean buffer, in case this is run from an |
|
1484 | 1483 | # interactive IPython session (via a magic, for example). |
|
1485 | 1484 | self.resetbuffer() |
|
1486 | 1485 | lines = lines.split('\n') |
|
1487 | 1486 | more = 0 |
|
1488 | 1487 | for line in lines: |
|
1489 | 1488 | # skip blank lines so we don't mess up the prompt counter, but do |
|
1490 | 1489 | # NOT skip even a blank line if we are in a code block (more is |
|
1491 | 1490 | # true) |
|
1492 | 1491 | if line or more: |
|
1493 | 1492 | more = self.push((self.prefilter(line,more))) |
|
1494 | 1493 | # IPython's runsource returns None if there was an error |
|
1495 | 1494 | # compiling the code. This allows us to stop processing right |
|
1496 | 1495 | # away, so the user gets the error message at the right place. |
|
1497 | 1496 | if more is None: |
|
1498 | 1497 | break |
|
1499 | 1498 | # final newline in case the input didn't have it, so that the code |
|
1500 | 1499 | # actually does get executed |
|
1501 | 1500 | if more: |
|
1502 | 1501 | self.push('\n') |
|
1503 | 1502 | |
|
1504 | 1503 | def runsource(self, source, filename="<input>", symbol="single"): |
|
1505 | 1504 | """Compile and run some source in the interpreter. |
|
1506 | 1505 | |
|
1507 | 1506 | Arguments are as for compile_command(). |
|
1508 | 1507 | |
|
1509 | 1508 | One several things can happen: |
|
1510 | 1509 | |
|
1511 | 1510 | 1) The input is incorrect; compile_command() raised an |
|
1512 | 1511 | exception (SyntaxError or OverflowError). A syntax traceback |
|
1513 | 1512 | will be printed by calling the showsyntaxerror() method. |
|
1514 | 1513 | |
|
1515 | 1514 | 2) The input is incomplete, and more input is required; |
|
1516 | 1515 | compile_command() returned None. Nothing happens. |
|
1517 | 1516 | |
|
1518 | 1517 | 3) The input is complete; compile_command() returned a code |
|
1519 | 1518 | object. The code is executed by calling self.runcode() (which |
|
1520 | 1519 | also handles run-time exceptions, except for SystemExit). |
|
1521 | 1520 | |
|
1522 | 1521 | The return value is: |
|
1523 | 1522 | |
|
1524 | 1523 | - True in case 2 |
|
1525 | 1524 | |
|
1526 | 1525 | - False in the other cases, unless an exception is raised, where |
|
1527 | 1526 | None is returned instead. This can be used by external callers to |
|
1528 | 1527 | know whether to continue feeding input or not. |
|
1529 | 1528 | |
|
1530 | 1529 | The return value can be used to decide whether to use sys.ps1 or |
|
1531 | 1530 | sys.ps2 to prompt the next line.""" |
|
1531 | ||
|
1532 | 1532 | try: |
|
1533 | 1533 | code = self.compile(source, filename, symbol) |
|
1534 | 1534 | except (OverflowError, SyntaxError, ValueError): |
|
1535 | 1535 | # Case 1 |
|
1536 | 1536 | self.showsyntaxerror(filename) |
|
1537 | 1537 | return None |
|
1538 | 1538 | |
|
1539 | 1539 | if code is None: |
|
1540 | 1540 | # Case 2 |
|
1541 | 1541 | return True |
|
1542 | 1542 | |
|
1543 | 1543 | # Case 3 |
|
1544 |
# We store the code |
|
|
1544 | # We store the code object so that threaded shells and | |
|
1545 | 1545 | # custom exception handlers can access all this info if needed. |
|
1546 | self.code_to_run_src = source | |
|
1546 | # The source corresponding to this can be obtained from the | |
|
1547 | # buffer attribute as '\n'.join(self.buffer). | |
|
1547 | 1548 | self.code_to_run = code |
|
1548 | 1549 | # now actually execute the code object |
|
1549 | 1550 | if self.runcode(code) == 0: |
|
1550 | 1551 | return False |
|
1551 | 1552 | else: |
|
1552 | 1553 | return None |
|
1553 | 1554 | |
|
1554 | 1555 | def runcode(self,code_obj): |
|
1555 | 1556 | """Execute a code object. |
|
1556 | 1557 | |
|
1557 | 1558 | When an exception occurs, self.showtraceback() is called to display a |
|
1558 | 1559 | traceback. |
|
1559 | 1560 | |
|
1560 | 1561 | Return value: a flag indicating whether the code to be run completed |
|
1561 | 1562 | successfully: |
|
1562 | 1563 | |
|
1563 | 1564 | - 0: successful execution. |
|
1564 | 1565 | - 1: an error occurred. |
|
1565 | 1566 | """ |
|
1566 | 1567 | |
|
1567 | 1568 | # Set our own excepthook in case the user code tries to call it |
|
1568 | 1569 | # directly, so that the IPython crash handler doesn't get triggered |
|
1569 | 1570 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
1570 | 1571 | outflag = 1 # happens in more places, so it's easier as default |
|
1571 | 1572 | try: |
|
1572 | 1573 | try: |
|
1573 | 1574 | exec code_obj in self.locals |
|
1574 | 1575 | finally: |
|
1575 | 1576 | # Reset our crash handler in place |
|
1576 | 1577 | sys.excepthook = old_excepthook |
|
1577 | 1578 | except SystemExit: |
|
1578 | 1579 | self.resetbuffer() |
|
1579 | 1580 | self.showtraceback() |
|
1580 | 1581 | warn( __builtin__.exit,level=1) |
|
1581 | 1582 | except self.custom_exceptions: |
|
1582 | 1583 | etype,value,tb = sys.exc_info() |
|
1583 | 1584 | self.CustomTB(etype,value,tb) |
|
1584 | 1585 | except: |
|
1585 | 1586 | self.showtraceback() |
|
1586 | 1587 | else: |
|
1587 | 1588 | outflag = 0 |
|
1588 | 1589 | if code.softspace(sys.stdout, 0): |
|
1589 | 1590 | |
|
1590 | 1591 | # Flush out code object which has been run (and source) |
|
1591 | 1592 | self.code_to_run = None |
|
1592 | self.code_to_run_src = '' | |
|
1593 | 1593 | return outflag |
|
1594 | 1594 | |
|
1595 | 1595 | def raw_input(self, prompt=""): |
|
1596 | 1596 | """Write a prompt and read a line. |
|
1597 | 1597 | |
|
1598 | 1598 | The returned line does not include the trailing newline. |
|
1599 | 1599 | When the user enters the EOF key sequence, EOFError is raised. |
|
1600 | 1600 | |
|
1601 | 1601 | The base implementation uses the built-in function |
|
1602 | 1602 | raw_input(); a subclass may replace this with a different |
|
1603 | 1603 | implementation. |
|
1604 | 1604 | """ |
|
1605 | 1605 | return self.prefilter(raw_input_original(prompt), |
|
1606 | 1606 | prompt==self.outputcache.prompt2) |
|
1607 | 1607 | |
|
1608 | 1608 | def split_user_input(self,line): |
|
1609 | 1609 | """Split user input into pre-char, function part and rest.""" |
|
1610 | 1610 | |
|
1611 | 1611 | lsplit = self.line_split.match(line) |
|
1612 | 1612 | if lsplit is None: # no regexp match returns None |
|
1613 | 1613 | try: |
|
1614 | 1614 | iFun,theRest = line.split(None,1) |
|
1615 | 1615 | except ValueError: |
|
1616 | 1616 | iFun,theRest = line,'' |
|
1617 | 1617 | pre = re.match('^(\s*)(.*)',line).groups()[0] |
|
1618 | 1618 | else: |
|
1619 | 1619 | pre,iFun,theRest = lsplit.groups() |
|
1620 | 1620 | |
|
1621 | 1621 | #print 'line:<%s>' % line # dbg |
|
1622 | 1622 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg |
|
1623 | 1623 | return pre,iFun.strip(),theRest |
|
1624 | 1624 | |
|
1625 | 1625 | def _prefilter(self, line, continue_prompt): |
|
1626 | 1626 | """Calls different preprocessors, depending on the form of line.""" |
|
1627 | 1627 | |
|
1628 | 1628 | # All handlers *must* return a value, even if it's blank (''). |
|
1629 | 1629 | |
|
1630 | 1630 | # Lines are NOT logged here. Handlers should process the line as |
|
1631 | 1631 | # needed, update the cache AND log it (so that the input cache array |
|
1632 | 1632 | # stays synced). |
|
1633 | 1633 | |
|
1634 | 1634 | # This function is _very_ delicate, and since it's also the one which |
|
1635 | 1635 | # determines IPython's response to user input, it must be as efficient |
|
1636 | 1636 | # as possible. For this reason it has _many_ returns in it, trying |
|
1637 | 1637 | # always to exit as quickly as it can figure out what it needs to do. |
|
1638 | 1638 | |
|
1639 | 1639 | # This function is the main responsible for maintaining IPython's |
|
1640 | 1640 | # behavior respectful of Python's semantics. So be _very_ careful if |
|
1641 | 1641 | # making changes to anything here. |
|
1642 | 1642 | |
|
1643 | 1643 | #..................................................................... |
|
1644 | 1644 | # Code begins |
|
1645 | 1645 | |
|
1646 | 1646 | #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg |
|
1647 | 1647 | |
|
1648 | 1648 | # save the line away in case we crash, so the post-mortem handler can |
|
1649 | 1649 | # record it |
|
1650 | 1650 | self._last_input_line = line |
|
1651 | 1651 | |
|
1652 | 1652 | #print '***line: <%s>' % line # dbg |
|
1653 | 1653 | |
|
1654 | 1654 | # the input history needs to track even empty lines |
|
1655 | 1655 | if not line.strip(): |
|
1656 | 1656 | if not continue_prompt: |
|
1657 | 1657 | self.outputcache.prompt_count -= 1 |
|
1658 | 1658 | return self.handle_normal('',continue_prompt) |
|
1659 | 1659 | |
|
1660 | 1660 | # print '***cont',continue_prompt # dbg |
|
1661 | 1661 | # special handlers are only allowed for single line statements |
|
1662 | 1662 | if continue_prompt and not self.rc.multi_line_specials: |
|
1663 | 1663 | return self.handle_normal(line,continue_prompt) |
|
1664 | 1664 | |
|
1665 | 1665 | # For the rest, we need the structure of the input |
|
1666 | 1666 | pre,iFun,theRest = self.split_user_input(line) |
|
1667 | 1667 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1668 | 1668 | |
|
1669 | 1669 | # First check for explicit escapes in the last/first character |
|
1670 | 1670 | handler = None |
|
1671 | 1671 | if line[-1] == self.ESC_HELP: |
|
1672 | 1672 | handler = self.esc_handlers.get(line[-1]) # the ? can be at the end |
|
1673 | 1673 | if handler is None: |
|
1674 | 1674 | # look at the first character of iFun, NOT of line, so we skip |
|
1675 | 1675 | # leading whitespace in multiline input |
|
1676 | 1676 | handler = self.esc_handlers.get(iFun[0:1]) |
|
1677 | 1677 | if handler is not None: |
|
1678 | 1678 | return handler(line,continue_prompt,pre,iFun,theRest) |
|
1679 | 1679 | # Emacs ipython-mode tags certain input lines |
|
1680 | 1680 | if line.endswith('# PYTHON-MODE'): |
|
1681 | 1681 | return self.handle_emacs(line,continue_prompt) |
|
1682 | 1682 | |
|
1683 | 1683 | # Next, check if we can automatically execute this thing |
|
1684 | 1684 | |
|
1685 | 1685 | # Allow ! in multi-line statements if multi_line_specials is on: |
|
1686 | 1686 | if continue_prompt and self.rc.multi_line_specials and \ |
|
1687 | 1687 | iFun.startswith(self.ESC_SHELL): |
|
1688 | 1688 | return self.handle_shell_escape(line,continue_prompt, |
|
1689 | 1689 | pre=pre,iFun=iFun, |
|
1690 | 1690 | theRest=theRest) |
|
1691 | 1691 | |
|
1692 | 1692 | # Let's try to find if the input line is a magic fn |
|
1693 | 1693 | oinfo = None |
|
1694 | 1694 | if hasattr(self,'magic_'+iFun): |
|
1695 | 1695 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1696 | 1696 | if oinfo['ismagic']: |
|
1697 | 1697 | # Be careful not to call magics when a variable assignment is |
|
1698 | 1698 | # being made (ls='hi', for example) |
|
1699 | 1699 | if self.rc.automagic and \ |
|
1700 | 1700 | (len(theRest)==0 or theRest[0] not in '!=()<>,') and \ |
|
1701 | 1701 | (self.rc.multi_line_specials or not continue_prompt): |
|
1702 | 1702 | return self.handle_magic(line,continue_prompt, |
|
1703 | 1703 | pre,iFun,theRest) |
|
1704 | 1704 | else: |
|
1705 | 1705 | return self.handle_normal(line,continue_prompt) |
|
1706 | 1706 | |
|
1707 | 1707 | # If the rest of the line begins with an (in)equality, assginment or |
|
1708 | 1708 | # function call, we should not call _ofind but simply execute it. |
|
1709 | 1709 | # This avoids spurious geattr() accesses on objects upon assignment. |
|
1710 | 1710 | # |
|
1711 | 1711 | # It also allows users to assign to either alias or magic names true |
|
1712 | 1712 | # python variables (the magic/alias systems always take second seat to |
|
1713 | 1713 | # true python code). |
|
1714 | 1714 | if theRest and theRest[0] in '!=()': |
|
1715 | 1715 | return self.handle_normal(line,continue_prompt) |
|
1716 | 1716 | |
|
1717 | 1717 | if oinfo is None: |
|
1718 | 1718 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1719 | 1719 | |
|
1720 | 1720 | if not oinfo['found']: |
|
1721 | 1721 | return self.handle_normal(line,continue_prompt) |
|
1722 | 1722 | else: |
|
1723 | 1723 | #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg |
|
1724 | 1724 | if oinfo['isalias']: |
|
1725 | 1725 | return self.handle_alias(line,continue_prompt, |
|
1726 | 1726 | pre,iFun,theRest) |
|
1727 | 1727 | |
|
1728 | 1728 | if self.rc.autocall and \ |
|
1729 | 1729 | not self.re_exclude_auto.match(theRest) and \ |
|
1730 | 1730 | self.re_fun_name.match(iFun) and \ |
|
1731 | 1731 | callable(oinfo['obj']) : |
|
1732 | 1732 | #print 'going auto' # dbg |
|
1733 | 1733 | return self.handle_auto(line,continue_prompt,pre,iFun,theRest) |
|
1734 | 1734 | else: |
|
1735 | 1735 | #print 'was callable?', callable(oinfo['obj']) # dbg |
|
1736 | 1736 | return self.handle_normal(line,continue_prompt) |
|
1737 | 1737 | |
|
1738 | 1738 | # If we get here, we have a normal Python line. Log and return. |
|
1739 | 1739 | return self.handle_normal(line,continue_prompt) |
|
1740 | 1740 | |
|
1741 | 1741 | def _prefilter_dumb(self, line, continue_prompt): |
|
1742 | 1742 | """simple prefilter function, for debugging""" |
|
1743 | 1743 | return self.handle_normal(line,continue_prompt) |
|
1744 | 1744 | |
|
1745 | 1745 | # Set the default prefilter() function (this can be user-overridden) |
|
1746 | 1746 | prefilter = _prefilter |
|
1747 | 1747 | |
|
1748 | 1748 | def handle_normal(self,line,continue_prompt=None, |
|
1749 | 1749 | pre=None,iFun=None,theRest=None): |
|
1750 | 1750 | """Handle normal input lines. Use as a template for handlers.""" |
|
1751 | 1751 | |
|
1752 | 1752 | self.log(line,continue_prompt) |
|
1753 | 1753 | self.update_cache(line) |
|
1754 | 1754 | return line |
|
1755 | 1755 | |
|
1756 | 1756 | def handle_alias(self,line,continue_prompt=None, |
|
1757 | 1757 | pre=None,iFun=None,theRest=None): |
|
1758 | 1758 | """Handle alias input lines. """ |
|
1759 | 1759 | |
|
1760 | 1760 | theRest = esc_quotes(theRest) |
|
1761 | 1761 | line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest) |
|
1762 | 1762 | self.log(line_out,continue_prompt) |
|
1763 | 1763 | self.update_cache(line_out) |
|
1764 | 1764 | return line_out |
|
1765 | 1765 | |
|
1766 | 1766 | def handle_shell_escape(self, line, continue_prompt=None, |
|
1767 | 1767 | pre=None,iFun=None,theRest=None): |
|
1768 | 1768 | """Execute the line in a shell, empty return value""" |
|
1769 | 1769 | |
|
1770 | #print 'line in :', `line` # dbg | |
|
1770 | 1771 | # Example of a special handler. Others follow a similar pattern. |
|
1771 | 1772 | if continue_prompt: # multi-line statements |
|
1772 | 1773 | if iFun.startswith('!!'): |
|
1773 | 1774 | print 'SyntaxError: !! is not allowed in multiline statements' |
|
1774 | 1775 | return pre |
|
1775 | 1776 | else: |
|
1776 | 1777 | cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"') |
|
1777 | 1778 | line_out = '%s%s.system("%s")' % (pre,self.name,cmd) |
|
1779 | #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')' | |
|
1778 | 1780 | else: # single-line input |
|
1779 | 1781 | if line.startswith('!!'): |
|
1780 | 1782 | # rewrite iFun/theRest to properly hold the call to %sx and |
|
1781 | 1783 | # the actual command to be executed, so handle_magic can work |
|
1782 | 1784 | # correctly |
|
1783 | 1785 | theRest = '%s %s' % (iFun[2:],theRest) |
|
1784 | 1786 | iFun = 'sx' |
|
1785 | 1787 | return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]), |
|
1786 | 1788 | continue_prompt,pre,iFun,theRest) |
|
1787 | 1789 | else: |
|
1788 | 1790 | cmd = esc_quotes(line[1:]) |
|
1789 | 1791 | line_out = '%s.system("%s")' % (self.name,cmd) |
|
1792 | #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')' | |
|
1790 | 1793 | # update cache/log and return |
|
1791 | 1794 | self.log(line_out,continue_prompt) |
|
1792 | 1795 | self.update_cache(line_out) # readline cache gets normal line |
|
1796 | #print 'line out r:', `line_out` # dbg | |
|
1797 | #print 'line out s:', line_out # dbg | |
|
1793 | 1798 | return line_out |
|
1794 | 1799 | |
|
1795 | 1800 | def handle_magic(self, line, continue_prompt=None, |
|
1796 | 1801 | pre=None,iFun=None,theRest=None): |
|
1797 | 1802 | """Execute magic functions. |
|
1798 | 1803 | |
|
1799 | 1804 | Also log them with a prepended # so the log is clean Python.""" |
|
1800 | 1805 | |
|
1801 | 1806 | cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest))) |
|
1802 | 1807 | self.log(cmd,continue_prompt) |
|
1803 | 1808 | self.update_cache(line) |
|
1804 | 1809 | #print 'in handle_magic, cmd=<%s>' % cmd # dbg |
|
1805 | 1810 | return cmd |
|
1806 | 1811 | |
|
1807 | 1812 | def handle_auto(self, line, continue_prompt=None, |
|
1808 | 1813 | pre=None,iFun=None,theRest=None): |
|
1809 | 1814 | """Hande lines which can be auto-executed, quoting if requested.""" |
|
1810 | 1815 | |
|
1811 | 1816 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1812 | 1817 | |
|
1813 | 1818 | # This should only be active for single-line input! |
|
1814 | 1819 | if continue_prompt: |
|
1815 | 1820 | return line |
|
1816 | 1821 | |
|
1817 | 1822 | if pre == self.ESC_QUOTE: |
|
1818 | 1823 | # Auto-quote splitting on whitespace |
|
1819 | 1824 | newcmd = '%s("%s")\n' % (iFun,'", "'.join(theRest.split()) ) |
|
1820 | 1825 | elif pre == self.ESC_QUOTE2: |
|
1821 | 1826 | # Auto-quote whole string |
|
1822 | 1827 | newcmd = '%s("%s")\n' % (iFun,theRest) |
|
1823 | 1828 | else: |
|
1824 | 1829 | # Auto-paren |
|
1825 | 1830 | if theRest[0:1] in ('=','['): |
|
1826 | 1831 | # Don't autocall in these cases. They can be either |
|
1827 | 1832 | # rebindings of an existing callable's name, or item access |
|
1828 | 1833 | # for an object which is BOTH callable and implements |
|
1829 | 1834 | # __getitem__. |
|
1830 | 1835 | return '%s %s\n' % (iFun,theRest) |
|
1831 | 1836 | if theRest.endswith(';'): |
|
1832 | 1837 | newcmd = '%s(%s);\n' % (iFun.rstrip(),theRest[:-1]) |
|
1833 | 1838 | else: |
|
1834 | 1839 | newcmd = '%s(%s)\n' % (iFun.rstrip(),theRest) |
|
1835 | 1840 | |
|
1836 | 1841 | print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd, |
|
1837 | 1842 | # log what is now valid Python, not the actual user input (without the |
|
1838 | 1843 | # final newline) |
|
1839 | 1844 | self.log(newcmd.strip(),continue_prompt) |
|
1840 | 1845 | return newcmd |
|
1841 | 1846 | |
|
1842 | 1847 | def handle_help(self, line, continue_prompt=None, |
|
1843 | 1848 | pre=None,iFun=None,theRest=None): |
|
1844 | 1849 | """Try to get some help for the object. |
|
1845 | 1850 | |
|
1846 | 1851 | obj? or ?obj -> basic information. |
|
1847 | 1852 | obj?? or ??obj -> more details. |
|
1848 | 1853 | """ |
|
1849 | 1854 | |
|
1850 | 1855 | # We need to make sure that we don't process lines which would be |
|
1851 | 1856 | # otherwise valid python, such as "x=1 # what?" |
|
1852 | 1857 | try: |
|
1853 | 1858 | code.compile_command(line) |
|
1854 | 1859 | except SyntaxError: |
|
1855 | 1860 | # We should only handle as help stuff which is NOT valid syntax |
|
1856 | 1861 | if line[0]==self.ESC_HELP: |
|
1857 | 1862 | line = line[1:] |
|
1858 | 1863 | elif line[-1]==self.ESC_HELP: |
|
1859 | 1864 | line = line[:-1] |
|
1860 | 1865 | self.log('#?'+line) |
|
1861 | 1866 | self.update_cache(line) |
|
1862 | 1867 | if line: |
|
1863 | 1868 | self.magic_pinfo(line) |
|
1864 | 1869 | else: |
|
1865 | 1870 | page(self.usage,screen_lines=self.rc.screen_length) |
|
1866 | 1871 | return '' # Empty string is needed here! |
|
1867 | 1872 | except: |
|
1868 | 1873 | # Pass any other exceptions through to the normal handler |
|
1869 | 1874 | return self.handle_normal(line,continue_prompt) |
|
1870 | 1875 | else: |
|
1871 | 1876 | # If the code compiles ok, we should handle it normally |
|
1872 | 1877 | return self.handle_normal(line,continue_prompt) |
|
1873 | 1878 | |
|
1874 | 1879 | def handle_emacs(self,line,continue_prompt=None, |
|
1875 | 1880 | pre=None,iFun=None,theRest=None): |
|
1876 | 1881 | """Handle input lines marked by python-mode.""" |
|
1877 | 1882 | |
|
1878 | 1883 | # Currently, nothing is done. Later more functionality can be added |
|
1879 | 1884 | # here if needed. |
|
1880 | 1885 | |
|
1881 | 1886 | # The input cache shouldn't be updated |
|
1882 | 1887 | |
|
1883 | 1888 | return line |
|
1884 | 1889 | |
|
1885 | 1890 | def write(self,data): |
|
1886 | 1891 | """Write a string to the default output""" |
|
1887 | 1892 | Term.cout.write(data) |
|
1888 | 1893 | |
|
1889 | 1894 | def write_err(self,data): |
|
1890 | 1895 | """Write a string to the default error output""" |
|
1891 | 1896 | Term.cerr.write(data) |
|
1892 | 1897 | |
|
1893 | 1898 | def safe_execfile(self,fname,*where,**kw): |
|
1894 | 1899 | fname = os.path.expanduser(fname) |
|
1895 | 1900 | |
|
1896 | 1901 | # find things also in current directory |
|
1897 | 1902 | dname = os.path.dirname(fname) |
|
1898 | 1903 | if not sys.path.count(dname): |
|
1899 | 1904 | sys.path.append(dname) |
|
1900 | 1905 | |
|
1901 | 1906 | try: |
|
1902 | 1907 | xfile = open(fname) |
|
1903 | 1908 | except: |
|
1904 | 1909 | print >> Term.cerr, \ |
|
1905 | 1910 | 'Could not open file <%s> for safe execution.' % fname |
|
1906 | 1911 | return None |
|
1907 | 1912 | |
|
1908 | 1913 | kw.setdefault('islog',0) |
|
1909 | 1914 | kw.setdefault('quiet',1) |
|
1910 | 1915 | kw.setdefault('exit_ignore',0) |
|
1911 | 1916 | first = xfile.readline() |
|
1912 | 1917 | _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip() |
|
1913 | 1918 | xfile.close() |
|
1914 | 1919 | # line by line execution |
|
1915 | 1920 | if first.startswith(_LOGHEAD) or kw['islog']: |
|
1916 | 1921 | print 'Loading log file <%s> one line at a time...' % fname |
|
1917 | 1922 | if kw['quiet']: |
|
1918 | 1923 | stdout_save = sys.stdout |
|
1919 | 1924 | sys.stdout = StringIO.StringIO() |
|
1920 | 1925 | try: |
|
1921 | 1926 | globs,locs = where[0:2] |
|
1922 | 1927 | except: |
|
1923 | 1928 | try: |
|
1924 | 1929 | globs = locs = where[0] |
|
1925 | 1930 | except: |
|
1926 | 1931 | globs = locs = globals() |
|
1927 | 1932 | badblocks = [] |
|
1928 | 1933 | |
|
1929 | 1934 | # we also need to identify indented blocks of code when replaying |
|
1930 | 1935 | # logs and put them together before passing them to an exec |
|
1931 | 1936 | # statement. This takes a bit of regexp and look-ahead work in the |
|
1932 | 1937 | # file. It's easiest if we swallow the whole thing in memory |
|
1933 | 1938 | # first, and manually walk through the lines list moving the |
|
1934 | 1939 | # counter ourselves. |
|
1935 | 1940 | indent_re = re.compile('\s+\S') |
|
1936 | 1941 | xfile = open(fname) |
|
1937 | 1942 | filelines = xfile.readlines() |
|
1938 | 1943 | xfile.close() |
|
1939 | 1944 | nlines = len(filelines) |
|
1940 | 1945 | lnum = 0 |
|
1941 | 1946 | while lnum < nlines: |
|
1942 | 1947 | line = filelines[lnum] |
|
1943 | 1948 | lnum += 1 |
|
1944 | 1949 | # don't re-insert logger status info into cache |
|
1945 | 1950 | if line.startswith('#log#'): |
|
1946 | 1951 | continue |
|
1947 | 1952 | elif line.startswith('#%s'% self.ESC_MAGIC): |
|
1948 | 1953 | self.update_cache(line[1:]) |
|
1949 | 1954 | line = magic2python(line) |
|
1950 | 1955 | elif line.startswith('#!'): |
|
1951 | 1956 | self.update_cache(line[1:]) |
|
1952 | 1957 | else: |
|
1953 | 1958 | # build a block of code (maybe a single line) for execution |
|
1954 | 1959 | block = line |
|
1955 | 1960 | try: |
|
1956 | 1961 | next = filelines[lnum] # lnum has already incremented |
|
1957 | 1962 | except: |
|
1958 | 1963 | next = None |
|
1959 | 1964 | while next and indent_re.match(next): |
|
1960 | 1965 | block += next |
|
1961 | 1966 | lnum += 1 |
|
1962 | 1967 | try: |
|
1963 | 1968 | next = filelines[lnum] |
|
1964 | 1969 | except: |
|
1965 | 1970 | next = None |
|
1966 | 1971 | # now execute the block of one or more lines |
|
1967 | 1972 | try: |
|
1968 | 1973 | exec block in globs,locs |
|
1969 | 1974 | self.update_cache(block.rstrip()) |
|
1970 | 1975 | except SystemExit: |
|
1971 | 1976 | pass |
|
1972 | 1977 | except: |
|
1973 | 1978 | badblocks.append(block.rstrip()) |
|
1974 | 1979 | if kw['quiet']: # restore stdout |
|
1975 | 1980 | sys.stdout.close() |
|
1976 | 1981 | sys.stdout = stdout_save |
|
1977 | 1982 | print 'Finished replaying log file <%s>' % fname |
|
1978 | 1983 | if badblocks: |
|
1979 | 1984 | print >> sys.stderr, \ |
|
1980 | 1985 | '\nThe following lines/blocks in file <%s> reported errors:' \ |
|
1981 | 1986 | % fname |
|
1982 | 1987 | for badline in badblocks: |
|
1983 | 1988 | print >> sys.stderr, badline |
|
1984 | 1989 | else: # regular file execution |
|
1985 | 1990 | try: |
|
1986 | 1991 | execfile(fname,*where) |
|
1987 | 1992 | except SyntaxError: |
|
1988 | 1993 | etype, evalue = sys.exc_info()[0:2] |
|
1989 | 1994 | self.SyntaxTB(etype,evalue,[]) |
|
1990 | 1995 | warn('Failure executing file: <%s>' % fname) |
|
1991 | 1996 | except SystemExit,status: |
|
1992 | 1997 | if not kw['exit_ignore']: |
|
1993 | 1998 | self.InteractiveTB() |
|
1994 | 1999 | warn('Failure executing file: <%s>' % fname) |
|
1995 | 2000 | except: |
|
1996 | 2001 | self.InteractiveTB() |
|
1997 | 2002 | warn('Failure executing file: <%s>' % fname) |
|
1998 | 2003 | |
|
1999 | 2004 | #************************* end of file <iplib.py> ***************************** |
@@ -1,859 +1,860 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | ultraTB.py -- Spice up your tracebacks! |
|
4 | 4 | |
|
5 | 5 | * ColorTB |
|
6 | 6 | I've always found it a bit hard to visually parse tracebacks in Python. The |
|
7 | 7 | ColorTB class is a solution to that problem. It colors the different parts of a |
|
8 | 8 | traceback in a manner similar to what you would expect from a syntax-highlighting |
|
9 | 9 | text editor. |
|
10 | 10 | |
|
11 | 11 | Installation instructions for ColorTB: |
|
12 | 12 | import sys,ultraTB |
|
13 | 13 | sys.excepthook = ultraTB.ColorTB() |
|
14 | 14 | |
|
15 | 15 | * VerboseTB |
|
16 | 16 | I've also included a port of Ka-Ping Yee's "cgitb.py" that produces all kinds |
|
17 | 17 | of useful info when a traceback occurs. Ping originally had it spit out HTML |
|
18 | 18 | and intended it for CGI programmers, but why should they have all the fun? I |
|
19 | 19 | altered it to spit out colored text to the terminal. It's a bit overwhelming, |
|
20 | 20 | but kind of neat, and maybe useful for long-running programs that you believe |
|
21 | 21 | are bug-free. If a crash *does* occur in that type of program you want details. |
|
22 | 22 | Give it a shot--you'll love it or you'll hate it. |
|
23 | 23 | |
|
24 | 24 | Note: |
|
25 | 25 | |
|
26 | 26 | The Verbose mode prints the variables currently visible where the exception |
|
27 | 27 | happened (shortening their strings if too long). This can potentially be |
|
28 | 28 | very slow, if you happen to have a huge data structure whose string |
|
29 | 29 | representation is complex to compute. Your computer may appear to freeze for |
|
30 | 30 | a while with cpu usage at 100%. If this occurs, you can cancel the traceback |
|
31 | 31 | with Ctrl-C (maybe hitting it more than once). |
|
32 | 32 | |
|
33 | 33 | If you encounter this kind of situation often, you may want to use the |
|
34 | 34 | Verbose_novars mode instead of the regular Verbose, which avoids formatting |
|
35 | 35 | variables (but otherwise includes the information and context given by |
|
36 | 36 | Verbose). |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | Installation instructions for ColorTB: |
|
40 | 40 | import sys,ultraTB |
|
41 | 41 | sys.excepthook = ultraTB.VerboseTB() |
|
42 | 42 | |
|
43 | 43 | Note: Much of the code in this module was lifted verbatim from the standard |
|
44 | 44 | library module 'traceback.py' and Ka-Ping Yee's 'cgitb.py'. |
|
45 | 45 | |
|
46 | 46 | * Color schemes |
|
47 | 47 | The colors are defined in the class TBTools through the use of the |
|
48 | 48 | ColorSchemeTable class. Currently the following exist: |
|
49 | 49 | |
|
50 | 50 | - NoColor: allows all of this module to be used in any terminal (the color |
|
51 | 51 | escapes are just dummy blank strings). |
|
52 | 52 | |
|
53 | 53 | - Linux: is meant to look good in a terminal like the Linux console (black |
|
54 | 54 | or very dark background). |
|
55 | 55 | |
|
56 | 56 | - LightBG: similar to Linux but swaps dark/light colors to be more readable |
|
57 | 57 | in light background terminals. |
|
58 | 58 | |
|
59 | 59 | You can implement other color schemes easily, the syntax is fairly |
|
60 | 60 | self-explanatory. Please send back new schemes you develop to the author for |
|
61 | 61 | possible inclusion in future releases. |
|
62 | 62 | |
|
63 |
$Id: ultraTB.py |
|
|
63 | $Id: ultraTB.py 703 2005-08-16 17:34:44Z fperez $""" | |
|
64 | 64 | |
|
65 | 65 | #***************************************************************************** |
|
66 | 66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
|
67 | 67 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
68 | 68 | # |
|
69 | 69 | # Distributed under the terms of the BSD License. The full license is in |
|
70 | 70 | # the file COPYING, distributed as part of this software. |
|
71 | 71 | #***************************************************************************** |
|
72 | 72 | |
|
73 | 73 | from IPython import Release |
|
74 | 74 | __author__ = '%s <%s>\n%s <%s>' % (Release.authors['Nathan']+ |
|
75 | 75 | Release.authors['Fernando']) |
|
76 | 76 | __license__ = Release.license |
|
77 | 77 | |
|
78 | 78 | # Required modules |
|
79 | 79 | import sys, os, traceback, types, string, time |
|
80 | 80 | import keyword, tokenize, linecache, inspect, pydoc |
|
81 | 81 | from UserDict import UserDict |
|
82 | 82 | |
|
83 | 83 | # IPython's own modules |
|
84 | 84 | # Modified pdb which doesn't damage IPython's readline handling |
|
85 | 85 | from IPython import Debugger |
|
86 | 86 | |
|
87 | 87 | from IPython.Struct import Struct |
|
88 | 88 | from IPython.ColorANSI import * |
|
89 | 89 | from IPython.genutils import Term,uniq_stable,error,info |
|
90 | 90 | |
|
91 | 91 | #--------------------------------------------------------------------------- |
|
92 | 92 | # Code begins |
|
93 | 93 | |
|
94 | 94 | def inspect_error(): |
|
95 | 95 | """Print a message about internal inspect errors. |
|
96 | 96 | |
|
97 | 97 | These are unfortunately quite common.""" |
|
98 | 98 | |
|
99 | 99 | error('Internal Python error in the inspect module.\n' |
|
100 | 100 | 'Below is the traceback from this internal error.\n') |
|
101 | 101 | |
|
102 | 102 | # Make a global variable out of the color scheme table used for coloring |
|
103 | 103 | # exception tracebacks. This allows user code to add new schemes at runtime. |
|
104 | 104 | ExceptionColors = ColorSchemeTable() |
|
105 | 105 | |
|
106 | 106 | # Populate it with color schemes |
|
107 | 107 | C = TermColors # shorthand and local lookup |
|
108 | 108 | ExceptionColors.add_scheme(ColorScheme( |
|
109 | 109 | 'NoColor', |
|
110 | 110 | # The color to be used for the top line |
|
111 | 111 | topline = C.NoColor, |
|
112 | 112 | |
|
113 | 113 | # The colors to be used in the traceback |
|
114 | 114 | filename = C.NoColor, |
|
115 | 115 | lineno = C.NoColor, |
|
116 | 116 | name = C.NoColor, |
|
117 | 117 | vName = C.NoColor, |
|
118 | 118 | val = C.NoColor, |
|
119 | 119 | em = C.NoColor, |
|
120 | 120 | |
|
121 | 121 | # Emphasized colors for the last frame of the traceback |
|
122 | 122 | normalEm = C.NoColor, |
|
123 | 123 | filenameEm = C.NoColor, |
|
124 | 124 | linenoEm = C.NoColor, |
|
125 | 125 | nameEm = C.NoColor, |
|
126 | 126 | valEm = C.NoColor, |
|
127 | 127 | |
|
128 | 128 | # Colors for printing the exception |
|
129 | 129 | excName = C.NoColor, |
|
130 | 130 | line = C.NoColor, |
|
131 | 131 | caret = C.NoColor, |
|
132 | 132 | Normal = C.NoColor |
|
133 | 133 | )) |
|
134 | 134 | |
|
135 | 135 | # make some schemes as instances so we can copy them for modification easily |
|
136 | 136 | ExceptionColors.add_scheme(ColorScheme( |
|
137 | 137 | 'Linux', |
|
138 | 138 | # The color to be used for the top line |
|
139 | 139 | topline = C.LightRed, |
|
140 | 140 | |
|
141 | 141 | # The colors to be used in the traceback |
|
142 | 142 | filename = C.Green, |
|
143 | 143 | lineno = C.Green, |
|
144 | 144 | name = C.Purple, |
|
145 | 145 | vName = C.Cyan, |
|
146 | 146 | val = C.Green, |
|
147 | 147 | em = C.LightCyan, |
|
148 | 148 | |
|
149 | 149 | # Emphasized colors for the last frame of the traceback |
|
150 | 150 | normalEm = C.LightCyan, |
|
151 | 151 | filenameEm = C.LightGreen, |
|
152 | 152 | linenoEm = C.LightGreen, |
|
153 | 153 | nameEm = C.LightPurple, |
|
154 | 154 | valEm = C.LightBlue, |
|
155 | 155 | |
|
156 | 156 | # Colors for printing the exception |
|
157 | 157 | excName = C.LightRed, |
|
158 | 158 | line = C.Yellow, |
|
159 | 159 | caret = C.White, |
|
160 | 160 | Normal = C.Normal |
|
161 | 161 | )) |
|
162 | 162 | |
|
163 | 163 | # For light backgrounds, swap dark/light colors |
|
164 | 164 | ExceptionColors.add_scheme(ColorScheme( |
|
165 | 165 | 'LightBG', |
|
166 | 166 | # The color to be used for the top line |
|
167 | 167 | topline = C.Red, |
|
168 | 168 | |
|
169 | 169 | # The colors to be used in the traceback |
|
170 | 170 | filename = C.LightGreen, |
|
171 | 171 | lineno = C.LightGreen, |
|
172 | 172 | name = C.LightPurple, |
|
173 | 173 | vName = C.Cyan, |
|
174 | 174 | val = C.LightGreen, |
|
175 | 175 | em = C.Cyan, |
|
176 | 176 | |
|
177 | 177 | # Emphasized colors for the last frame of the traceback |
|
178 | 178 | normalEm = C.Cyan, |
|
179 | 179 | filenameEm = C.Green, |
|
180 | 180 | linenoEm = C.Green, |
|
181 | 181 | nameEm = C.Purple, |
|
182 | 182 | valEm = C.Blue, |
|
183 | 183 | |
|
184 | 184 | # Colors for printing the exception |
|
185 | 185 | excName = C.Red, |
|
186 | 186 | #line = C.Brown, # brown often is displayed as yellow |
|
187 | 187 | line = C.Red, |
|
188 | 188 | caret = C.Normal, |
|
189 | 189 | Normal = C.Normal |
|
190 | 190 | )) |
|
191 | 191 | |
|
192 | 192 | class TBTools: |
|
193 | 193 | """Basic tools used by all traceback printer classes.""" |
|
194 | 194 | |
|
195 | 195 | def __init__(self,color_scheme = 'NoColor',call_pdb=0): |
|
196 | 196 | # Whether to call the interactive pdb debugger after printing |
|
197 | 197 | # tracebacks or not |
|
198 | 198 | self.call_pdb = call_pdb |
|
199 | 199 | if call_pdb: |
|
200 | 200 | self.pdb = Debugger.Pdb() |
|
201 | 201 | else: |
|
202 | 202 | self.pdb = None |
|
203 | 203 | |
|
204 | 204 | # Create color table |
|
205 | 205 | self.ColorSchemeTable = ExceptionColors |
|
206 | 206 | |
|
207 | 207 | self.set_colors(color_scheme) |
|
208 | 208 | self.old_scheme = color_scheme # save initial value for toggles |
|
209 | 209 | |
|
210 | 210 | def set_colors(self,*args,**kw): |
|
211 | 211 | """Shorthand access to the color table scheme selector method.""" |
|
212 | 212 | |
|
213 | 213 | self.ColorSchemeTable.set_active_scheme(*args,**kw) |
|
214 | 214 | # for convenience, set Colors to the active scheme |
|
215 | 215 | self.Colors = self.ColorSchemeTable.active_colors |
|
216 | 216 | |
|
217 | 217 | def color_toggle(self): |
|
218 | 218 | """Toggle between the currently active color scheme and NoColor.""" |
|
219 | 219 | |
|
220 | 220 | if self.ColorSchemeTable.active_scheme_name == 'NoColor': |
|
221 | 221 | self.ColorSchemeTable.set_active_scheme(self.old_scheme) |
|
222 | 222 | self.Colors = self.ColorSchemeTable.active_colors |
|
223 | 223 | else: |
|
224 | 224 | self.old_scheme = self.ColorSchemeTable.active_scheme_name |
|
225 | 225 | self.ColorSchemeTable.set_active_scheme('NoColor') |
|
226 | 226 | self.Colors = self.ColorSchemeTable.active_colors |
|
227 | 227 | |
|
228 | 228 | #--------------------------------------------------------------------------- |
|
229 | 229 | class ListTB(TBTools): |
|
230 | 230 | """Print traceback information from a traceback list, with optional color. |
|
231 | 231 | |
|
232 | 232 | Calling: requires 3 arguments: |
|
233 | 233 | (etype, evalue, elist) |
|
234 | 234 | as would be obtained by: |
|
235 | 235 | etype, evalue, tb = sys.exc_info() |
|
236 | 236 | if tb: |
|
237 | 237 | elist = traceback.extract_tb(tb) |
|
238 | 238 | else: |
|
239 | 239 | elist = None |
|
240 | 240 | |
|
241 | 241 | It can thus be used by programs which need to process the traceback before |
|
242 | 242 | printing (such as console replacements based on the code module from the |
|
243 | 243 | standard library). |
|
244 | 244 | |
|
245 | 245 | Because they are meant to be called without a full traceback (only a |
|
246 | 246 | list), instances of this class can't call the interactive pdb debugger.""" |
|
247 | 247 | |
|
248 | 248 | def __init__(self,color_scheme = 'NoColor'): |
|
249 | 249 | TBTools.__init__(self,color_scheme = color_scheme,call_pdb=0) |
|
250 | 250 | |
|
251 | 251 | def __call__(self, etype, value, elist): |
|
252 | 252 | print >> Term.cerr, self.text(etype,value,elist) |
|
253 | 253 | |
|
254 | 254 | def text(self,etype, value, elist,context=5): |
|
255 | 255 | """Return a color formatted string with the traceback info.""" |
|
256 | 256 | |
|
257 | 257 | Colors = self.Colors |
|
258 | 258 | out_string = ['%s%s%s\n' % (Colors.topline,'-'*60,Colors.Normal)] |
|
259 | 259 | if elist: |
|
260 | 260 | out_string.append('Traceback %s(most recent call last)%s:' % \ |
|
261 | 261 | (Colors.normalEm, Colors.Normal) + '\n') |
|
262 | 262 | out_string.extend(self._format_list(elist)) |
|
263 | 263 | lines = self._format_exception_only(etype, value) |
|
264 | 264 | for line in lines[:-1]: |
|
265 | 265 | out_string.append(" "+line) |
|
266 | 266 | out_string.append(lines[-1]) |
|
267 | 267 | return ''.join(out_string) |
|
268 | 268 | |
|
269 | 269 | def _format_list(self, extracted_list): |
|
270 | 270 | """Format a list of traceback entry tuples for printing. |
|
271 | 271 | |
|
272 | 272 | Given a list of tuples as returned by extract_tb() or |
|
273 | 273 | extract_stack(), return a list of strings ready for printing. |
|
274 | 274 | Each string in the resulting list corresponds to the item with the |
|
275 | 275 | same index in the argument list. Each string ends in a newline; |
|
276 | 276 | the strings may contain internal newlines as well, for those items |
|
277 | 277 | whose source text line is not None. |
|
278 | 278 | |
|
279 | 279 | Lifted almost verbatim from traceback.py |
|
280 | 280 | """ |
|
281 | 281 | |
|
282 | 282 | Colors = self.Colors |
|
283 | 283 | list = [] |
|
284 | 284 | for filename, lineno, name, line in extracted_list[:-1]: |
|
285 | 285 | item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \ |
|
286 | 286 | (Colors.filename, filename, Colors.Normal, |
|
287 | 287 | Colors.lineno, lineno, Colors.Normal, |
|
288 | 288 | Colors.name, name, Colors.Normal) |
|
289 | 289 | if line: |
|
290 | 290 | item = item + ' %s\n' % line.strip() |
|
291 | 291 | list.append(item) |
|
292 | 292 | # Emphasize the last entry |
|
293 | 293 | filename, lineno, name, line = extracted_list[-1] |
|
294 | 294 | item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \ |
|
295 | 295 | (Colors.normalEm, |
|
296 | 296 | Colors.filenameEm, filename, Colors.normalEm, |
|
297 | 297 | Colors.linenoEm, lineno, Colors.normalEm, |
|
298 | 298 | Colors.nameEm, name, Colors.normalEm, |
|
299 | 299 | Colors.Normal) |
|
300 | 300 | if line: |
|
301 | 301 | item = item + '%s %s%s\n' % (Colors.line, line.strip(), |
|
302 | 302 | Colors.Normal) |
|
303 | 303 | list.append(item) |
|
304 | 304 | return list |
|
305 | 305 | |
|
306 | 306 | def _format_exception_only(self, etype, value): |
|
307 | 307 | """Format the exception part of a traceback. |
|
308 | 308 | |
|
309 | 309 | The arguments are the exception type and value such as given by |
|
310 | 310 | sys.last_type and sys.last_value. The return value is a list of |
|
311 | 311 | strings, each ending in a newline. Normally, the list contains a |
|
312 | 312 | single string; however, for SyntaxError exceptions, it contains |
|
313 | 313 | several lines that (when printed) display detailed information |
|
314 | 314 | about where the syntax error occurred. The message indicating |
|
315 | 315 | which exception occurred is the always last string in the list. |
|
316 | 316 | |
|
317 | 317 | Also lifted nearly verbatim from traceback.py |
|
318 | 318 | """ |
|
319 | 319 | |
|
320 | 320 | Colors = self.Colors |
|
321 | 321 | list = [] |
|
322 | 322 | if type(etype) == types.ClassType: |
|
323 | 323 | stype = Colors.excName + etype.__name__ + Colors.Normal |
|
324 | 324 | else: |
|
325 | 325 | stype = etype # String exceptions don't get special coloring |
|
326 | 326 | if value is None: |
|
327 | 327 | list.append( str(stype) + '\n') |
|
328 | 328 | else: |
|
329 | 329 | if etype is SyntaxError: |
|
330 | 330 | try: |
|
331 | 331 | msg, (filename, lineno, offset, line) = value |
|
332 | 332 | except: |
|
333 | 333 | pass |
|
334 | 334 | else: |
|
335 | 335 | #print 'filename is',filename # dbg |
|
336 | 336 | if not filename: filename = "<string>" |
|
337 | 337 | list.append('%s File %s"%s"%s, line %s%d%s\n' % \ |
|
338 | 338 | (Colors.normalEm, |
|
339 | 339 | Colors.filenameEm, filename, Colors.normalEm, |
|
340 | 340 | Colors.linenoEm, lineno, Colors.Normal )) |
|
341 | 341 | if line is not None: |
|
342 | 342 | i = 0 |
|
343 | 343 | while i < len(line) and line[i].isspace(): |
|
344 | 344 | i = i+1 |
|
345 | 345 | list.append('%s %s%s\n' % (Colors.line, |
|
346 | 346 | line.strip(), |
|
347 | 347 | Colors.Normal)) |
|
348 | 348 | if offset is not None: |
|
349 | 349 | s = ' ' |
|
350 | 350 | for c in line[i:offset-1]: |
|
351 | 351 | if c.isspace(): |
|
352 | 352 | s = s + c |
|
353 | 353 | else: |
|
354 | 354 | s = s + ' ' |
|
355 | 355 | list.append('%s%s^%s\n' % (Colors.caret, s, |
|
356 | 356 | Colors.Normal) ) |
|
357 | 357 | value = msg |
|
358 | 358 | s = self._some_str(value) |
|
359 | 359 | if s: |
|
360 | 360 | list.append('%s%s:%s %s\n' % (str(stype), Colors.excName, |
|
361 | 361 | Colors.Normal, s)) |
|
362 | 362 | else: |
|
363 | 363 | list.append('%s\n' % str(stype)) |
|
364 | 364 | return list |
|
365 | 365 | |
|
366 | 366 | def _some_str(self, value): |
|
367 | 367 | # Lifted from traceback.py |
|
368 | 368 | try: |
|
369 | 369 | return str(value) |
|
370 | 370 | except: |
|
371 | 371 | return '<unprintable %s object>' % type(value).__name__ |
|
372 | 372 | |
|
373 | 373 | #---------------------------------------------------------------------------- |
|
374 | 374 | class VerboseTB(TBTools): |
|
375 | 375 | """A port of Ka-Ping Yee's cgitb.py module that outputs color text instead |
|
376 | 376 | of HTML. Requires inspect and pydoc. Crazy, man. |
|
377 | 377 | |
|
378 | 378 | Modified version which optionally strips the topmost entries from the |
|
379 | 379 | traceback, to be used with alternate interpreters (because their own code |
|
380 | 380 | would appear in the traceback).""" |
|
381 | 381 | |
|
382 | 382 | def __init__(self,color_scheme = 'Linux',tb_offset=0,long_header=0, |
|
383 | 383 | call_pdb = 0, include_vars=1): |
|
384 | 384 | """Specify traceback offset, headers and color scheme. |
|
385 | 385 | |
|
386 | 386 | Define how many frames to drop from the tracebacks. Calling it with |
|
387 | 387 | tb_offset=1 allows use of this handler in interpreters which will have |
|
388 | 388 | their own code at the top of the traceback (VerboseTB will first |
|
389 | 389 | remove that frame before printing the traceback info).""" |
|
390 | 390 | TBTools.__init__(self,color_scheme=color_scheme,call_pdb=call_pdb) |
|
391 | 391 | self.tb_offset = tb_offset |
|
392 | 392 | self.long_header = long_header |
|
393 | 393 | self.include_vars = include_vars |
|
394 | 394 | |
|
395 | 395 | def text(self, etype, evalue, etb, context=5): |
|
396 | 396 | """Return a nice text document describing the traceback.""" |
|
397 | 397 | |
|
398 | 398 | # some locals |
|
399 | 399 | Colors = self.Colors # just a shorthand + quicker name lookup |
|
400 | 400 | ColorsNormal = Colors.Normal # used a lot |
|
401 | 401 | indent_size = 8 # we need some space to put line numbers before |
|
402 | 402 | indent = ' '*indent_size |
|
403 | 403 | numbers_width = indent_size - 1 # leave space between numbers & code |
|
404 | 404 | text_repr = pydoc.text.repr |
|
405 | 405 | exc = '%s%s%s' % (Colors.excName, str(etype), ColorsNormal) |
|
406 | 406 | em_normal = '%s\n%s%s' % (Colors.valEm, indent,ColorsNormal) |
|
407 | 407 | undefined = '%sundefined%s' % (Colors.em, ColorsNormal) |
|
408 | 408 | |
|
409 | 409 | # some internal-use functions |
|
410 | 410 | def eqrepr(value, repr=text_repr): return '=%s' % repr(value) |
|
411 | 411 | def nullrepr(value, repr=text_repr): return '' |
|
412 | 412 | |
|
413 | 413 | # meat of the code begins |
|
414 | 414 | if type(etype) is types.ClassType: |
|
415 | 415 | etype = etype.__name__ |
|
416 | 416 | |
|
417 | 417 | if self.long_header: |
|
418 | 418 | # Header with the exception type, python version, and date |
|
419 | 419 | pyver = 'Python ' + string.split(sys.version)[0] + ': ' + sys.executable |
|
420 | 420 | date = time.ctime(time.time()) |
|
421 | 421 | |
|
422 | 422 | head = '%s%s%s\n%s%s%s\n%s' % (Colors.topline, '-'*75, ColorsNormal, |
|
423 | 423 | exc, ' '*(75-len(str(etype))-len(pyver)), |
|
424 | 424 | pyver, string.rjust(date, 75) ) |
|
425 | 425 | head += "\nA problem occured executing Python code. Here is the sequence of function"\ |
|
426 | 426 | "\ncalls leading up to the error, with the most recent (innermost) call last." |
|
427 | 427 | else: |
|
428 | 428 | # Simplified header |
|
429 | 429 | head = '%s%s%s\n%s%s' % (Colors.topline, '-'*75, ColorsNormal,exc, |
|
430 | 430 | string.rjust('Traceback (most recent call last)', |
|
431 | 431 | 75 - len(str(etype)) ) ) |
|
432 | 432 | frames = [] |
|
433 | 433 | # Flush cache before calling inspect. This helps alleviate some of the |
|
434 | 434 | # problems with python 2.3's inspect.py. |
|
435 | 435 | linecache.checkcache() |
|
436 | 436 | # Drop topmost frames if requested |
|
437 | 437 | try: |
|
438 | 438 | records = inspect.getinnerframes(etb, context)[self.tb_offset:] |
|
439 | 439 | except: |
|
440 | 440 | |
|
441 | 441 | # FIXME: I've been getting many crash reports from python 2.3 |
|
442 | 442 | # users, traceable to inspect.py. If I can find a small test-case |
|
443 | 443 | # to reproduce this, I should either write a better workaround or |
|
444 | 444 | # file a bug report against inspect (if that's the real problem). |
|
445 | 445 | # So far, I haven't been able to find an isolated example to |
|
446 | 446 | # reproduce the problem. |
|
447 | 447 | inspect_error() |
|
448 | 448 | traceback.print_exc(file=Term.cerr) |
|
449 | 449 | info('\nUnfortunately, your original traceback can not be constructed.\n') |
|
450 | 450 | return '' |
|
451 | 451 | |
|
452 | 452 | # build some color string templates outside these nested loops |
|
453 | 453 | tpl_link = '%s%%s%s' % (Colors.filenameEm,ColorsNormal) |
|
454 | 454 | tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, |
|
455 | 455 | ColorsNormal) |
|
456 | 456 | tpl_call_fail = 'in %s%%s%s(***failed resolving arguments***)%s' % \ |
|
457 | 457 | (Colors.vName, Colors.valEm, ColorsNormal) |
|
458 | 458 | tpl_local_var = '%s%%s%s' % (Colors.vName, ColorsNormal) |
|
459 | 459 | tpl_global_var = '%sglobal%s %s%%s%s' % (Colors.em, ColorsNormal, |
|
460 | 460 | Colors.vName, ColorsNormal) |
|
461 | 461 | tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal) |
|
462 | 462 | tpl_line = '%s%%s%s %%s' % (Colors.lineno, ColorsNormal) |
|
463 | 463 | tpl_line_em = '%s%%s%s %%s%s' % (Colors.linenoEm,Colors.line, |
|
464 | 464 | ColorsNormal) |
|
465 | 465 | |
|
466 | 466 | # now, loop over all records printing context and info |
|
467 | 467 | abspath = os.path.abspath |
|
468 | 468 | for frame, file, lnum, func, lines, index in records: |
|
469 | 469 | #print '*** record:',file,lnum,func,lines,index # dbg |
|
470 | 470 | try: |
|
471 | 471 | file = file and abspath(file) or '?' |
|
472 | 472 | except OSError: |
|
473 | 473 | # if file is '<console>' or something not in the filesystem, |
|
474 | 474 | # the abspath call will throw an OSError. Just ignore it and |
|
475 | 475 | # keep the original file string. |
|
476 | 476 | pass |
|
477 | 477 | link = tpl_link % file |
|
478 | 478 | try: |
|
479 | 479 | args, varargs, varkw, locals = inspect.getargvalues(frame) |
|
480 | 480 | except: |
|
481 | 481 | # This can happen due to a bug in python2.3. We should be |
|
482 | 482 | # able to remove this try/except when 2.4 becomes a |
|
483 | 483 | # requirement. Bug details at http://python.org/sf/1005466 |
|
484 | 484 | inspect_error() |
|
485 | 485 | traceback.print_exc(file=Term.cerr) |
|
486 | 486 | info("\nIPython's exception reporting continues...\n") |
|
487 | 487 | |
|
488 | 488 | if func == '?': |
|
489 | 489 | call = '' |
|
490 | 490 | else: |
|
491 | 491 | # Decide whether to include variable details or not |
|
492 | 492 | var_repr = self.include_vars and eqrepr or nullrepr |
|
493 | 493 | try: |
|
494 | 494 | call = tpl_call % (func,inspect.formatargvalues(args, |
|
495 | 495 | varargs, varkw, |
|
496 | 496 | locals,formatvalue=var_repr)) |
|
497 | 497 | except KeyError: |
|
498 | 498 | # Very odd crash from inspect.formatargvalues(). The |
|
499 | 499 | # scenario under which it appeared was a call to |
|
500 | 500 | # view(array,scale) in NumTut.view.view(), where scale had |
|
501 | 501 | # been defined as a scalar (it should be a tuple). Somehow |
|
502 | 502 | # inspect messes up resolving the argument list of view() |
|
503 | 503 | # and barfs out. At some point I should dig into this one |
|
504 | 504 | # and file a bug report about it. |
|
505 | 505 | inspect_error() |
|
506 | 506 | traceback.print_exc(file=Term.cerr) |
|
507 | 507 | info("\nIPython's exception reporting continues...\n") |
|
508 | 508 | call = tpl_call_fail % func |
|
509 | 509 | |
|
510 | 510 | # Initialize a list of names on the current line, which the |
|
511 | 511 | # tokenizer below will populate. |
|
512 | 512 | names = [] |
|
513 | 513 | |
|
514 | 514 | def tokeneater(token_type, token, start, end, line): |
|
515 | 515 | """Stateful tokeneater which builds dotted names. |
|
516 | 516 | |
|
517 | 517 | The list of names it appends to (from the enclosing scope) can |
|
518 | 518 | contain repeated composite names. This is unavoidable, since |
|
519 | 519 | there is no way to disambguate partial dotted structures until |
|
520 | 520 | the full list is known. The caller is responsible for pruning |
|
521 | 521 | the final list of duplicates before using it.""" |
|
522 | 522 | |
|
523 | 523 | # build composite names |
|
524 | 524 | if token == '.': |
|
525 | 525 | try: |
|
526 | 526 | names[-1] += '.' |
|
527 | 527 | # store state so the next token is added for x.y.z names |
|
528 | 528 | tokeneater.name_cont = True |
|
529 | 529 | return |
|
530 | 530 | except IndexError: |
|
531 | 531 | pass |
|
532 | 532 | if token_type == tokenize.NAME and token not in keyword.kwlist: |
|
533 | 533 | if tokeneater.name_cont: |
|
534 | 534 | # Dotted names |
|
535 | 535 | names[-1] += token |
|
536 | 536 | tokeneater.name_cont = False |
|
537 | 537 | else: |
|
538 | 538 | # Regular new names. We append everything, the caller |
|
539 | 539 | # will be responsible for pruning the list later. It's |
|
540 | 540 | # very tricky to try to prune as we go, b/c composite |
|
541 | 541 | # names can fool us. The pruning at the end is easy |
|
542 | 542 | # to do (or the caller can print a list with repeated |
|
543 | 543 | # names if so desired. |
|
544 | 544 | names.append(token) |
|
545 | 545 | elif token_type == tokenize.NEWLINE: |
|
546 | 546 | raise IndexError |
|
547 | 547 | # we need to store a bit of state in the tokenizer to build |
|
548 | 548 | # dotted names |
|
549 | 549 | tokeneater.name_cont = False |
|
550 | 550 | |
|
551 | 551 | def linereader(file=file, lnum=[lnum], getline=linecache.getline): |
|
552 | 552 | line = getline(file, lnum[0]) |
|
553 | 553 | lnum[0] += 1 |
|
554 | 554 | return line |
|
555 | 555 | |
|
556 | 556 | # Build the list of names on this line of code where the exception |
|
557 | 557 | # occurred. |
|
558 | 558 | try: |
|
559 | 559 | # This builds the names list in-place by capturing it from the |
|
560 | 560 | # enclosing scope. |
|
561 | 561 | tokenize.tokenize(linereader, tokeneater) |
|
562 | 562 | except IndexError: |
|
563 | 563 | # signals exit of tokenizer |
|
564 | 564 | pass |
|
565 | 565 | except tokenize.TokenError,msg: |
|
566 | 566 | _m = ("An unexpected error occurred while tokenizing input\n" |
|
567 | 567 | "The following traceback may be corrupted or invalid\n" |
|
568 | 568 | "The error message is: %s\n" % msg) |
|
569 | 569 | error(_m) |
|
570 | 570 | |
|
571 | 571 | # prune names list of duplicates, but keep the right order |
|
572 | 572 | unique_names = uniq_stable(names) |
|
573 | 573 | |
|
574 | 574 | # Start loop over vars |
|
575 | 575 | lvals = [] |
|
576 | 576 | if self.include_vars: |
|
577 | 577 | for name_full in unique_names: |
|
578 | 578 | name_base = name_full.split('.',1)[0] |
|
579 | 579 | if name_base in frame.f_code.co_varnames: |
|
580 | 580 | if locals.has_key(name_base): |
|
581 | 581 | try: |
|
582 | 582 | value = repr(eval(name_full,locals)) |
|
583 | 583 | except: |
|
584 | 584 | value = undefined |
|
585 | 585 | else: |
|
586 | 586 | value = undefined |
|
587 | 587 | name = tpl_local_var % name_full |
|
588 | 588 | else: |
|
589 | 589 | if frame.f_globals.has_key(name_base): |
|
590 | 590 | try: |
|
591 | 591 | value = repr(eval(name_full,frame.f_globals)) |
|
592 | 592 | except: |
|
593 | 593 | value = undefined |
|
594 | 594 | else: |
|
595 | 595 | value = undefined |
|
596 | 596 | name = tpl_global_var % name_full |
|
597 | 597 | lvals.append(tpl_name_val % (name,value)) |
|
598 | 598 | if lvals: |
|
599 | 599 | lvals = '%s%s' % (indent,em_normal.join(lvals)) |
|
600 | 600 | else: |
|
601 | 601 | lvals = '' |
|
602 | 602 | |
|
603 | 603 | level = '%s %s\n' % (link,call) |
|
604 | 604 | excerpt = [] |
|
605 | 605 | if index is not None: |
|
606 | 606 | i = lnum - index |
|
607 | 607 | for line in lines: |
|
608 | 608 | if i == lnum: |
|
609 | 609 | # This is the line with the error |
|
610 | 610 | pad = numbers_width - len(str(i)) |
|
611 | 611 | if pad >= 3: |
|
612 | 612 | marker = '-'*(pad-3) + '-> ' |
|
613 | 613 | elif pad == 2: |
|
614 | 614 | marker = '> ' |
|
615 | 615 | elif pad == 1: |
|
616 | 616 | marker = '>' |
|
617 | 617 | else: |
|
618 | 618 | marker = '' |
|
619 | 619 | num = '%s%s' % (marker,i) |
|
620 | 620 | line = tpl_line_em % (num,line) |
|
621 | 621 | else: |
|
622 | 622 | num = '%*s' % (numbers_width,i) |
|
623 | 623 | line = tpl_line % (num,line) |
|
624 | 624 | |
|
625 | 625 | excerpt.append(line) |
|
626 | 626 | if self.include_vars and i == lnum: |
|
627 | 627 | excerpt.append('%s\n' % lvals) |
|
628 | 628 | i += 1 |
|
629 | 629 | frames.append('%s%s' % (level,''.join(excerpt)) ) |
|
630 | 630 | |
|
631 | 631 | # Get (safely) a string form of the exception info |
|
632 | 632 | try: |
|
633 | 633 | etype_str,evalue_str = map(str,(etype,evalue)) |
|
634 | 634 | except: |
|
635 | 635 | # User exception is improperly defined. |
|
636 | 636 | etype,evalue = str,sys.exc_info()[:2] |
|
637 | 637 | etype_str,evalue_str = map(str,(etype,evalue)) |
|
638 | 638 | # ... and format it |
|
639 | 639 | exception = ['%s%s%s: %s' % (Colors.excName, etype_str, |
|
640 | 640 | ColorsNormal, evalue_str)] |
|
641 | 641 | if type(evalue) is types.InstanceType: |
|
642 | for name in dir(evalue): | |
|
642 | names = [w for w in dir(evalue) if isinstance(w, basestring)] | |
|
643 | for name in names: | |
|
643 | 644 | value = text_repr(getattr(evalue, name)) |
|
644 | 645 | exception.append('\n%s%s = %s' % (indent, name, value)) |
|
645 | 646 | # return all our info assembled as a single string |
|
646 | 647 | return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) ) |
|
647 | 648 | |
|
648 | 649 | def debugger(self): |
|
649 | 650 | """Call up the pdb debugger if desired, always clean up the tb reference. |
|
650 | 651 | |
|
651 | 652 | If the call_pdb flag is set, the pdb interactive debugger is |
|
652 | 653 | invoked. In all cases, the self.tb reference to the current traceback |
|
653 | 654 | is deleted to prevent lingering references which hamper memory |
|
654 | 655 | management. |
|
655 | 656 | |
|
656 | 657 | Note that each call to pdb() does an 'import readline', so if your app |
|
657 | 658 | requires a special setup for the readline completers, you'll have to |
|
658 | 659 | fix that by hand after invoking the exception handler.""" |
|
659 | 660 | |
|
660 | 661 | if self.call_pdb: |
|
661 | 662 | if self.pdb is None: |
|
662 | 663 | self.pdb = Debugger.Pdb() |
|
663 | 664 | # the system displayhook may have changed, restore the original for pdb |
|
664 | 665 | dhook = sys.displayhook |
|
665 | 666 | sys.displayhook = sys.__displayhook__ |
|
666 | 667 | self.pdb.reset() |
|
667 | 668 | while self.tb.tb_next is not None: |
|
668 | 669 | self.tb = self.tb.tb_next |
|
669 | 670 | try: |
|
670 | 671 | self.pdb.interaction(self.tb.tb_frame, self.tb) |
|
671 | 672 | except: |
|
672 | 673 | print '*** ERROR ***' |
|
673 | 674 | print 'This version of pdb has a bug and crashed.' |
|
674 | 675 | print 'Returning to IPython...' |
|
675 | 676 | sys.displayhook = dhook |
|
676 | 677 | del self.tb |
|
677 | 678 | |
|
678 | 679 | def handler(self, info=None): |
|
679 | 680 | (etype, evalue, etb) = info or sys.exc_info() |
|
680 | 681 | self.tb = etb |
|
681 | 682 | print >> Term.cerr, self.text(etype, evalue, etb) |
|
682 | 683 | |
|
683 | 684 | # Changed so an instance can just be called as VerboseTB_inst() and print |
|
684 | 685 | # out the right info on its own. |
|
685 | 686 | def __call__(self, etype=None, evalue=None, etb=None): |
|
686 | 687 | """This hook can replace sys.excepthook (for Python 2.1 or higher).""" |
|
687 | 688 | if etb is not None: |
|
688 | 689 | self.handler((etype, evalue, etb)) |
|
689 | 690 | else: |
|
690 | 691 | self.handler() |
|
691 | 692 | self.debugger() |
|
692 | 693 | |
|
693 | 694 | #---------------------------------------------------------------------------- |
|
694 | 695 | class FormattedTB(VerboseTB,ListTB): |
|
695 | 696 | """Subclass ListTB but allow calling with a traceback. |
|
696 | 697 | |
|
697 | 698 | It can thus be used as a sys.excepthook for Python > 2.1. |
|
698 | 699 | |
|
699 | 700 | Also adds 'Context' and 'Verbose' modes, not available in ListTB. |
|
700 | 701 | |
|
701 | 702 | Allows a tb_offset to be specified. This is useful for situations where |
|
702 | 703 | one needs to remove a number of topmost frames from the traceback (such as |
|
703 | 704 | occurs with python programs that themselves execute other python code, |
|
704 | 705 | like Python shells). """ |
|
705 | 706 | |
|
706 | 707 | def __init__(self, mode = 'Plain', color_scheme='Linux', |
|
707 | 708 | tb_offset = 0,long_header=0,call_pdb=0,include_vars=0): |
|
708 | 709 | |
|
709 | 710 | # NEVER change the order of this list. Put new modes at the end: |
|
710 | 711 | self.valid_modes = ['Plain','Context','Verbose'] |
|
711 | 712 | self.verbose_modes = self.valid_modes[1:3] |
|
712 | 713 | |
|
713 | 714 | VerboseTB.__init__(self,color_scheme,tb_offset,long_header, |
|
714 | 715 | call_pdb=call_pdb,include_vars=include_vars) |
|
715 | 716 | self.set_mode(mode) |
|
716 | 717 | |
|
717 | 718 | def _extract_tb(self,tb): |
|
718 | 719 | if tb: |
|
719 | 720 | return traceback.extract_tb(tb) |
|
720 | 721 | else: |
|
721 | 722 | return None |
|
722 | 723 | |
|
723 | 724 | def text(self, etype, value, tb,context=5,mode=None): |
|
724 | 725 | """Return formatted traceback. |
|
725 | 726 | |
|
726 | 727 | If the optional mode parameter is given, it overrides the current |
|
727 | 728 | mode.""" |
|
728 | 729 | |
|
729 | 730 | if mode is None: |
|
730 | 731 | mode = self.mode |
|
731 | 732 | if mode in self.verbose_modes: |
|
732 | 733 | # verbose modes need a full traceback |
|
733 | 734 | return VerboseTB.text(self,etype, value, tb,context=5) |
|
734 | 735 | else: |
|
735 | 736 | # We must check the source cache because otherwise we can print |
|
736 | 737 | # out-of-date source code. |
|
737 | 738 | linecache.checkcache() |
|
738 | 739 | # Now we can extract and format the exception |
|
739 | 740 | elist = self._extract_tb(tb) |
|
740 | 741 | if len(elist) > self.tb_offset: |
|
741 | 742 | del elist[:self.tb_offset] |
|
742 | 743 | return ListTB.text(self,etype,value,elist) |
|
743 | 744 | |
|
744 | 745 | def set_mode(self,mode=None): |
|
745 | 746 | """Switch to the desired mode. |
|
746 | 747 | |
|
747 | 748 | If mode is not specified, cycles through the available modes.""" |
|
748 | 749 | |
|
749 | 750 | if not mode: |
|
750 | 751 | new_idx = ( self.valid_modes.index(self.mode) + 1 ) % \ |
|
751 | 752 | len(self.valid_modes) |
|
752 | 753 | self.mode = self.valid_modes[new_idx] |
|
753 | 754 | elif mode not in self.valid_modes: |
|
754 | 755 | raise ValueError, 'Unrecognized mode in FormattedTB: <'+mode+'>\n'\ |
|
755 | 756 | 'Valid modes: '+str(self.valid_modes) |
|
756 | 757 | else: |
|
757 | 758 | self.mode = mode |
|
758 | 759 | # include variable details only in 'Verbose' mode |
|
759 | 760 | self.include_vars = (self.mode == self.valid_modes[2]) |
|
760 | 761 | |
|
761 | 762 | # some convenient shorcuts |
|
762 | 763 | def plain(self): |
|
763 | 764 | self.set_mode(self.valid_modes[0]) |
|
764 | 765 | |
|
765 | 766 | def context(self): |
|
766 | 767 | self.set_mode(self.valid_modes[1]) |
|
767 | 768 | |
|
768 | 769 | def verbose(self): |
|
769 | 770 | self.set_mode(self.valid_modes[2]) |
|
770 | 771 | |
|
771 | 772 | #---------------------------------------------------------------------------- |
|
772 | 773 | class AutoFormattedTB(FormattedTB): |
|
773 | 774 | """A traceback printer which can be called on the fly. |
|
774 | 775 | |
|
775 | 776 | It will find out about exceptions by itself. |
|
776 | 777 | |
|
777 | 778 | A brief example: |
|
778 | 779 | |
|
779 | 780 | AutoTB = AutoFormattedTB(mode = 'Verbose',color_scheme='Linux') |
|
780 | 781 | try: |
|
781 | 782 | ... |
|
782 | 783 | except: |
|
783 | 784 | AutoTB() # or AutoTB(out=logfile) where logfile is an open file object |
|
784 | 785 | """ |
|
785 | 786 | def __call__(self,etype=None,evalue=None,etb=None, |
|
786 | 787 | out=None,tb_offset=None): |
|
787 | 788 | """Print out a formatted exception traceback. |
|
788 | 789 | |
|
789 | 790 | Optional arguments: |
|
790 | 791 | - out: an open file-like object to direct output to. |
|
791 | 792 | |
|
792 | 793 | - tb_offset: the number of frames to skip over in the stack, on a |
|
793 | 794 | per-call basis (this overrides temporarily the instance's tb_offset |
|
794 | 795 | given at initialization time. """ |
|
795 | 796 | |
|
796 | 797 | if out is None: |
|
797 | 798 | out = Term.cerr |
|
798 | 799 | if tb_offset is not None: |
|
799 | 800 | tb_offset, self.tb_offset = self.tb_offset, tb_offset |
|
800 | 801 | print >> out, self.text(etype, evalue, etb) |
|
801 | 802 | self.tb_offset = tb_offset |
|
802 | 803 | else: |
|
803 | 804 | print >> out, self.text() |
|
804 | 805 | self.debugger() |
|
805 | 806 | |
|
806 | 807 | def text(self,etype=None,value=None,tb=None,context=5,mode=None): |
|
807 | 808 | if etype is None: |
|
808 | 809 | etype,value,tb = sys.exc_info() |
|
809 | 810 | self.tb = tb |
|
810 | 811 | return FormattedTB.text(self,etype,value,tb,context=5,mode=mode) |
|
811 | 812 | |
|
812 | 813 | #--------------------------------------------------------------------------- |
|
813 | 814 | # A simple class to preserve Nathan's original functionality. |
|
814 | 815 | class ColorTB(FormattedTB): |
|
815 | 816 | """Shorthand to initialize a FormattedTB in Linux colors mode.""" |
|
816 | 817 | def __init__(self,color_scheme='Linux',call_pdb=0): |
|
817 | 818 | FormattedTB.__init__(self,color_scheme=color_scheme, |
|
818 | 819 | call_pdb=call_pdb) |
|
819 | 820 | |
|
820 | 821 | #---------------------------------------------------------------------------- |
|
821 | 822 | # module testing (minimal) |
|
822 | 823 | if __name__ == "__main__": |
|
823 | 824 | def spam(c, (d, e)): |
|
824 | 825 | x = c + d |
|
825 | 826 | y = c * d |
|
826 | 827 | foo(x, y) |
|
827 | 828 | |
|
828 | 829 | def foo(a, b, bar=1): |
|
829 | 830 | eggs(a, b + bar) |
|
830 | 831 | |
|
831 | 832 | def eggs(f, g, z=globals()): |
|
832 | 833 | h = f + g |
|
833 | 834 | i = f - g |
|
834 | 835 | return h / i |
|
835 | 836 | |
|
836 | 837 | print '' |
|
837 | 838 | print '*** Before ***' |
|
838 | 839 | try: |
|
839 | 840 | print spam(1, (2, 3)) |
|
840 | 841 | except: |
|
841 | 842 | traceback.print_exc() |
|
842 | 843 | print '' |
|
843 | 844 | |
|
844 | 845 | handler = ColorTB() |
|
845 | 846 | print '*** ColorTB ***' |
|
846 | 847 | try: |
|
847 | 848 | print spam(1, (2, 3)) |
|
848 | 849 | except: |
|
849 | 850 | apply(handler, sys.exc_info() ) |
|
850 | 851 | print '' |
|
851 | 852 | |
|
852 | 853 | handler = VerboseTB() |
|
853 | 854 | print '*** VerboseTB ***' |
|
854 | 855 | try: |
|
855 | 856 | print spam(1, (2, 3)) |
|
856 | 857 | except: |
|
857 | 858 | apply(handler, sys.exc_info() ) |
|
858 | 859 | print '' |
|
859 | 860 |
@@ -1,4299 +1,4322 b'' | |||
|
1 | 2005-08-16 Fernando Perez <fperez@colorado.edu> | |
|
2 | ||
|
3 | * IPython/ultraTB.py (VerboseTB.text): don't crash if object | |
|
4 | contains non-string attribute. Closes | |
|
5 | http://www.scipy.net/roundup/ipython/issue38. | |
|
6 | ||
|
7 | 2005-08-14 Fernando Perez <fperez@colorado.edu> | |
|
8 | ||
|
9 | * tools/ipsvnc: Minor improvements, to add changeset info. | |
|
10 | ||
|
11 | 2005-08-12 Fernando Perez <fperez@colorado.edu> | |
|
12 | ||
|
13 | * IPython/iplib.py (runsource): remove self.code_to_run_src | |
|
14 | attribute. I realized this is nothing more than | |
|
15 | '\n'.join(self.buffer), and having the same data in two different | |
|
16 | places is just asking for synchronization bugs. This may impact | |
|
17 | people who have custom exception handlers, so I need to warn | |
|
18 | ipython-dev about it (F. Mantegazza may use them). | |
|
19 | ||
|
20 | 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu> | |
|
21 | ||
|
22 | * IPython/genutils.py: fix 2.2 compatibility (generators) | |
|
23 | ||
|
1 | 24 | 2005-07-18 Fernando Perez <fperez@colorado.edu> |
|
2 | 25 | |
|
3 | 26 | * IPython/genutils.py (get_home_dir): fix to help users with |
|
4 | 27 | invalid $HOME under win32. |
|
5 | 28 | |
|
6 | 29 | 2005-07-17 Fernando Perez <fperez@colorado.edu> |
|
7 | 30 | |
|
8 | 31 | * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove |
|
9 | 32 | some old hacks and clean up a bit other routines; code should be |
|
10 | 33 | simpler and a bit faster. |
|
11 | 34 | |
|
12 | 35 | * IPython/iplib.py (interact): removed some last-resort attempts |
|
13 | 36 | to survive broken stdout/stderr. That code was only making it |
|
14 | 37 | harder to abstract out the i/o (necessary for gui integration), |
|
15 | 38 | and the crashes it could prevent were extremely rare in practice |
|
16 | 39 | (besides being fully user-induced in a pretty violent manner). |
|
17 | 40 | |
|
18 | 41 | * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff. |
|
19 | 42 | Nothing major yet, but the code is simpler to read; this should |
|
20 | 43 | make it easier to do more serious modifications in the future. |
|
21 | 44 | |
|
22 | 45 | * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh, |
|
23 | 46 | which broke in .15 (thanks to a report by Ville). |
|
24 | 47 | |
|
25 | 48 | * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not |
|
26 | 49 | be quite correct, I know next to nothing about unicode). This |
|
27 | 50 | will allow unicode strings to be used in prompts, amongst other |
|
28 | 51 | cases. It also will prevent ipython from crashing when unicode |
|
29 | 52 | shows up unexpectedly in many places. If ascii encoding fails, we |
|
30 | 53 | assume utf_8. Currently the encoding is not a user-visible |
|
31 | 54 | setting, though it could be made so if there is demand for it. |
|
32 | 55 | |
|
33 | 56 | * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack. |
|
34 | 57 | |
|
35 | 58 | * IPython/Struct.py (Struct.merge): switch keys() to iterator. |
|
36 | 59 | |
|
37 | 60 | * IPython/background_jobs.py: moved 2.2 compatibility to genutils. |
|
38 | 61 | |
|
39 | 62 | * IPython/genutils.py: Add 2.2 compatibility here, so all other |
|
40 | 63 | code can work transparently for 2.2/2.3. |
|
41 | 64 | |
|
42 | 65 | 2005-07-16 Fernando Perez <fperez@colorado.edu> |
|
43 | 66 | |
|
44 | 67 | * IPython/ultraTB.py (ExceptionColors): Make a global variable |
|
45 | 68 | out of the color scheme table used for coloring exception |
|
46 | 69 | tracebacks. This allows user code to add new schemes at runtime. |
|
47 | 70 | This is a minimally modified version of the patch at |
|
48 | 71 | http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw |
|
49 | 72 | for the contribution. |
|
50 | 73 | |
|
51 | 74 | * IPython/FlexCompleter.py (Completer.attr_matches): Add a |
|
52 | 75 | slightly modified version of the patch in |
|
53 | 76 | http://www.scipy.net/roundup/ipython/issue34, which also allows me |
|
54 | 77 | to remove the previous try/except solution (which was costlier). |
|
55 | 78 | Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix. |
|
56 | 79 | |
|
57 | 80 | 2005-06-08 Fernando Perez <fperez@colorado.edu> |
|
58 | 81 | |
|
59 | 82 | * IPython/iplib.py (write/write_err): Add methods to abstract all |
|
60 | 83 | I/O a bit more. |
|
61 | 84 | |
|
62 | 85 | * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation |
|
63 | 86 | warning, reported by Aric Hagberg, fix by JD Hunter. |
|
64 | 87 | |
|
65 | 88 | 2005-06-02 *** Released version 0.6.15 |
|
66 | 89 | |
|
67 | 90 | 2005-06-01 Fernando Perez <fperez@colorado.edu> |
|
68 | 91 | |
|
69 | 92 | * IPython/iplib.py (MagicCompleter.file_matches): Fix |
|
70 | 93 | tab-completion of filenames within open-quoted strings. Note that |
|
71 | 94 | this requires that in ~/.ipython/ipythonrc, users change the |
|
72 | 95 | readline delimiters configuration to read: |
|
73 | 96 | |
|
74 | 97 | readline_remove_delims -/~ |
|
75 | 98 | |
|
76 | 99 | |
|
77 | 100 | 2005-05-31 *** Released version 0.6.14 |
|
78 | 101 | |
|
79 | 102 | 2005-05-29 Fernando Perez <fperez@colorado.edu> |
|
80 | 103 | |
|
81 | 104 | * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks |
|
82 | 105 | with files not on the filesystem. Reported by Eliyahu Sandler |
|
83 | 106 | <eli@gondolin.net> |
|
84 | 107 | |
|
85 | 108 | 2005-05-22 Fernando Perez <fperez@colorado.edu> |
|
86 | 109 | |
|
87 | 110 | * IPython/iplib.py: Fix a few crashes in the --upgrade option. |
|
88 | 111 | After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>. |
|
89 | 112 | |
|
90 | 113 | 2005-05-19 Fernando Perez <fperez@colorado.edu> |
|
91 | 114 | |
|
92 | 115 | * IPython/iplib.py (safe_execfile): close a file which could be |
|
93 | 116 | left open (causing problems in win32, which locks open files). |
|
94 | 117 | Thanks to a bug report by D Brown <dbrown2@yahoo.com>. |
|
95 | 118 | |
|
96 | 119 | 2005-05-18 Fernando Perez <fperez@colorado.edu> |
|
97 | 120 | |
|
98 | 121 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all |
|
99 | 122 | keyword arguments correctly to safe_execfile(). |
|
100 | 123 | |
|
101 | 124 | 2005-05-13 Fernando Perez <fperez@colorado.edu> |
|
102 | 125 | |
|
103 | 126 | * ipython.1: Added info about Qt to manpage, and threads warning |
|
104 | 127 | to usage page (invoked with --help). |
|
105 | 128 | |
|
106 | 129 | * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added |
|
107 | 130 | new matcher (it goes at the end of the priority list) to do |
|
108 | 131 | tab-completion on named function arguments. Submitted by George |
|
109 | 132 | Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at |
|
110 | 133 | http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html |
|
111 | 134 | for more details. |
|
112 | 135 | |
|
113 | 136 | * IPython/Magic.py (magic_run): Added new -e flag to ignore |
|
114 | 137 | SystemExit exceptions in the script being run. Thanks to a report |
|
115 | 138 | by danny shevitz <danny_shevitz-AT-yahoo.com>, about this |
|
116 | 139 | producing very annoying behavior when running unit tests. |
|
117 | 140 | |
|
118 | 141 | 2005-05-12 Fernando Perez <fperez@colorado.edu> |
|
119 | 142 | |
|
120 | 143 | * IPython/iplib.py (handle_auto): fixed auto-quoting and parens, |
|
121 | 144 | which I'd broken (again) due to a changed regexp. In the process, |
|
122 | 145 | added ';' as an escape to auto-quote the whole line without |
|
123 | 146 | splitting its arguments. Thanks to a report by Jerry McRae |
|
124 | 147 | <qrs0xyc02-AT-sneakemail.com>. |
|
125 | 148 | |
|
126 | 149 | * IPython/ultraTB.py (VerboseTB.text): protect against rare but |
|
127 | 150 | possible crashes caused by a TokenError. Reported by Ed Schofield |
|
128 | 151 | <schofield-AT-ftw.at>. |
|
129 | 152 | |
|
130 | 153 | 2005-05-06 Fernando Perez <fperez@colorado.edu> |
|
131 | 154 | |
|
132 | 155 | * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6. |
|
133 | 156 | |
|
134 | 157 | 2005-04-29 Fernando Perez <fperez@colorado.edu> |
|
135 | 158 | |
|
136 | 159 | * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière |
|
137 | 160 | <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin |
|
138 | 161 | Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option |
|
139 | 162 | which provides support for Qt interactive usage (similar to the |
|
140 | 163 | existing one for WX and GTK). This had been often requested. |
|
141 | 164 | |
|
142 | 165 | 2005-04-14 *** Released version 0.6.13 |
|
143 | 166 | |
|
144 | 167 | 2005-04-08 Fernando Perez <fperez@colorado.edu> |
|
145 | 168 | |
|
146 | 169 | * IPython/Magic.py (Magic._ofind): remove docstring evaluation |
|
147 | 170 | from _ofind, which gets called on almost every input line. Now, |
|
148 | 171 | we only try to get docstrings if they are actually going to be |
|
149 | 172 | used (the overhead of fetching unnecessary docstrings can be |
|
150 | 173 | noticeable for certain objects, such as Pyro proxies). |
|
151 | 174 | |
|
152 | 175 | * IPython/iplib.py (MagicCompleter.python_matches): Change the API |
|
153 | 176 | for completers. For some reason I had been passing them the state |
|
154 | 177 | variable, which completers never actually need, and was in |
|
155 | 178 | conflict with the rlcompleter API. Custom completers ONLY need to |
|
156 | 179 | take the text parameter. |
|
157 | 180 | |
|
158 | 181 | * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics |
|
159 | 182 | work correctly in pysh. I've also moved all the logic which used |
|
160 | 183 | to be in pysh.py here, which will prevent problems with future |
|
161 | 184 | upgrades. However, this time I must warn users to update their |
|
162 | 185 | pysh profile to include the line |
|
163 | 186 | |
|
164 | 187 | import_all IPython.Extensions.InterpreterExec |
|
165 | 188 | |
|
166 | 189 | because otherwise things won't work for them. They MUST also |
|
167 | 190 | delete pysh.py and the line |
|
168 | 191 | |
|
169 | 192 | execfile pysh.py |
|
170 | 193 | |
|
171 | 194 | from their ipythonrc-pysh. |
|
172 | 195 | |
|
173 | 196 | * IPython/FlexCompleter.py (Completer.attr_matches): Make more |
|
174 | 197 | robust in the face of objects whose dir() returns non-strings |
|
175 | 198 | (which it shouldn't, but some broken libs like ITK do). Thanks to |
|
176 | 199 | a patch by John Hunter (implemented differently, though). Also |
|
177 | 200 | minor improvements by using .extend instead of + on lists. |
|
178 | 201 | |
|
179 | 202 | * pysh.py: |
|
180 | 203 | |
|
181 | 204 | 2005-04-06 Fernando Perez <fperez@colorado.edu> |
|
182 | 205 | |
|
183 | 206 | * IPython/ipmaker.py (make_IPython): Make multi_line_specials on |
|
184 | 207 | by default, so that all users benefit from it. Those who don't |
|
185 | 208 | want it can still turn it off. |
|
186 | 209 | |
|
187 | 210 | * IPython/UserConfig/ipythonrc: Add multi_line_specials to the |
|
188 | 211 | config file, I'd forgotten about this, so users were getting it |
|
189 | 212 | off by default. |
|
190 | 213 | |
|
191 | 214 | * IPython/iplib.py (ipmagic): big overhaul of the magic system for |
|
192 | 215 | consistency. Now magics can be called in multiline statements, |
|
193 | 216 | and python variables can be expanded in magic calls via $var. |
|
194 | 217 | This makes the magic system behave just like aliases or !system |
|
195 | 218 | calls. |
|
196 | 219 | |
|
197 | 220 | 2005-03-28 Fernando Perez <fperez@colorado.edu> |
|
198 | 221 | |
|
199 | 222 | * IPython/iplib.py (handle_auto): cleanup to use %s instead of |
|
200 | 223 | expensive string additions for building command. Add support for |
|
201 | 224 | trailing ';' when autocall is used. |
|
202 | 225 | |
|
203 | 226 | 2005-03-26 Fernando Perez <fperez@colorado.edu> |
|
204 | 227 | |
|
205 | 228 | * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31. |
|
206 | 229 | Bugfix by A. Schmolck, the ipython.el maintainer. Also make |
|
207 | 230 | ipython.el robust against prompts with any number of spaces |
|
208 | 231 | (including 0) after the ':' character. |
|
209 | 232 | |
|
210 | 233 | * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in |
|
211 | 234 | continuation prompt, which misled users to think the line was |
|
212 | 235 | already indented. Closes debian Bug#300847, reported to me by |
|
213 | 236 | Norbert Tretkowski <tretkowski-AT-inittab.de>. |
|
214 | 237 | |
|
215 | 238 | 2005-03-23 Fernando Perez <fperez@colorado.edu> |
|
216 | 239 | |
|
217 | 240 | * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are |
|
218 | 241 | properly aligned if they have embedded newlines. |
|
219 | 242 | |
|
220 | 243 | * IPython/iplib.py (runlines): Add a public method to expose |
|
221 | 244 | IPython's code execution machinery, so that users can run strings |
|
222 | 245 | as if they had been typed at the prompt interactively. |
|
223 | 246 | (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__ |
|
224 | 247 | methods which can call the system shell, but with python variable |
|
225 | 248 | expansion. The three such methods are: __IPYTHON__.system, |
|
226 | 249 | .getoutput and .getoutputerror. These need to be documented in a |
|
227 | 250 | 'public API' section (to be written) of the manual. |
|
228 | 251 | |
|
229 | 252 | 2005-03-20 Fernando Perez <fperez@colorado.edu> |
|
230 | 253 | |
|
231 | 254 | * IPython/iplib.py (InteractiveShell.set_custom_exc): new system |
|
232 | 255 | for custom exception handling. This is quite powerful, and it |
|
233 | 256 | allows for user-installable exception handlers which can trap |
|
234 | 257 | custom exceptions at runtime and treat them separately from |
|
235 | 258 | IPython's default mechanisms. At the request of FrΓ©dΓ©ric |
|
236 | 259 | Mantegazza <mantegazza-AT-ill.fr>. |
|
237 | 260 | (InteractiveShell.set_custom_completer): public API function to |
|
238 | 261 | add new completers at runtime. |
|
239 | 262 | |
|
240 | 263 | 2005-03-19 Fernando Perez <fperez@colorado.edu> |
|
241 | 264 | |
|
242 | 265 | * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to |
|
243 | 266 | allow objects which provide their docstrings via non-standard |
|
244 | 267 | mechanisms (like Pyro proxies) to still be inspected by ipython's |
|
245 | 268 | ? system. |
|
246 | 269 | |
|
247 | 270 | * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e |
|
248 | 271 | automatic capture system. I tried quite hard to make it work |
|
249 | 272 | reliably, and simply failed. I tried many combinations with the |
|
250 | 273 | subprocess module, but eventually nothing worked in all needed |
|
251 | 274 | cases (not blocking stdin for the child, duplicating stdout |
|
252 | 275 | without blocking, etc). The new %sc/%sx still do capture to these |
|
253 | 276 | magical list/string objects which make shell use much more |
|
254 | 277 | conveninent, so not all is lost. |
|
255 | 278 | |
|
256 | 279 | XXX - FIX MANUAL for the change above! |
|
257 | 280 | |
|
258 | 281 | (runsource): I copied code.py's runsource() into ipython to modify |
|
259 | 282 | it a bit. Now the code object and source to be executed are |
|
260 | 283 | stored in ipython. This makes this info accessible to third-party |
|
261 | 284 | tools, like custom exception handlers. After a request by FrΓ©dΓ©ric |
|
262 | 285 | Mantegazza <mantegazza-AT-ill.fr>. |
|
263 | 286 | |
|
264 | 287 | * IPython/UserConfig/ipythonrc: Add up/down arrow keys to |
|
265 | 288 | history-search via readline (like C-p/C-n). I'd wanted this for a |
|
266 | 289 | long time, but only recently found out how to do it. For users |
|
267 | 290 | who already have their ipythonrc files made and want this, just |
|
268 | 291 | add: |
|
269 | 292 | |
|
270 | 293 | readline_parse_and_bind "\e[A": history-search-backward |
|
271 | 294 | readline_parse_and_bind "\e[B": history-search-forward |
|
272 | 295 | |
|
273 | 296 | 2005-03-18 Fernando Perez <fperez@colorado.edu> |
|
274 | 297 | |
|
275 | 298 | * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy |
|
276 | 299 | LSString and SList classes which allow transparent conversions |
|
277 | 300 | between list mode and whitespace-separated string. |
|
278 | 301 | (magic_r): Fix recursion problem in %r. |
|
279 | 302 | |
|
280 | 303 | * IPython/genutils.py (LSString): New class to be used for |
|
281 | 304 | automatic storage of the results of all alias/system calls in _o |
|
282 | 305 | and _e (stdout/err). These provide a .l/.list attribute which |
|
283 | 306 | does automatic splitting on newlines. This means that for most |
|
284 | 307 | uses, you'll never need to do capturing of output with %sc/%sx |
|
285 | 308 | anymore, since ipython keeps this always done for you. Note that |
|
286 | 309 | only the LAST results are stored, the _o/e variables are |
|
287 | 310 | overwritten on each call. If you need to save their contents |
|
288 | 311 | further, simply bind them to any other name. |
|
289 | 312 | |
|
290 | 313 | 2005-03-17 Fernando Perez <fperez@colorado.edu> |
|
291 | 314 | |
|
292 | 315 | * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for |
|
293 | 316 | prompt namespace handling. |
|
294 | 317 | |
|
295 | 318 | 2005-03-16 Fernando Perez <fperez@colorado.edu> |
|
296 | 319 | |
|
297 | 320 | * IPython/Prompts.py (CachedOutput.__init__): Fix default and |
|
298 | 321 | classic prompts to be '>>> ' (final space was missing, and it |
|
299 | 322 | trips the emacs python mode). |
|
300 | 323 | (BasePrompt.__str__): Added safe support for dynamic prompt |
|
301 | 324 | strings. Now you can set your prompt string to be '$x', and the |
|
302 | 325 | value of x will be printed from your interactive namespace. The |
|
303 | 326 | interpolation syntax includes the full Itpl support, so |
|
304 | 327 | ${foo()+x+bar()} is a valid prompt string now, and the function |
|
305 | 328 | calls will be made at runtime. |
|
306 | 329 | |
|
307 | 330 | 2005-03-15 Fernando Perez <fperez@colorado.edu> |
|
308 | 331 | |
|
309 | 332 | * IPython/Magic.py (magic_history): renamed %hist to %history, to |
|
310 | 333 | avoid name clashes in pylab. %hist still works, it just forwards |
|
311 | 334 | the call to %history. |
|
312 | 335 | |
|
313 | 336 | 2005-03-02 *** Released version 0.6.12 |
|
314 | 337 | |
|
315 | 338 | 2005-03-02 Fernando Perez <fperez@colorado.edu> |
|
316 | 339 | |
|
317 | 340 | * IPython/iplib.py (handle_magic): log magic calls properly as |
|
318 | 341 | ipmagic() function calls. |
|
319 | 342 | |
|
320 | 343 | * IPython/Magic.py (magic_time): Improved %time to support |
|
321 | 344 | statements and provide wall-clock as well as CPU time. |
|
322 | 345 | |
|
323 | 346 | 2005-02-27 Fernando Perez <fperez@colorado.edu> |
|
324 | 347 | |
|
325 | 348 | * IPython/hooks.py: New hooks module, to expose user-modifiable |
|
326 | 349 | IPython functionality in a clean manner. For now only the editor |
|
327 | 350 | hook is actually written, and other thigns which I intend to turn |
|
328 | 351 | into proper hooks aren't yet there. The display and prefilter |
|
329 | 352 | stuff, for example, should be hooks. But at least now the |
|
330 | 353 | framework is in place, and the rest can be moved here with more |
|
331 | 354 | time later. IPython had had a .hooks variable for a long time for |
|
332 | 355 | this purpose, but I'd never actually used it for anything. |
|
333 | 356 | |
|
334 | 357 | 2005-02-26 Fernando Perez <fperez@colorado.edu> |
|
335 | 358 | |
|
336 | 359 | * IPython/ipmaker.py (make_IPython): make the default ipython |
|
337 | 360 | directory be called _ipython under win32, to follow more the |
|
338 | 361 | naming peculiarities of that platform (where buggy software like |
|
339 | 362 | Visual Sourcesafe breaks with .named directories). Reported by |
|
340 | 363 | Ville Vainio. |
|
341 | 364 | |
|
342 | 365 | 2005-02-23 Fernando Perez <fperez@colorado.edu> |
|
343 | 366 | |
|
344 | 367 | * IPython/iplib.py (InteractiveShell.__init__): removed a few |
|
345 | 368 | auto_aliases for win32 which were causing problems. Users can |
|
346 | 369 | define the ones they personally like. |
|
347 | 370 | |
|
348 | 371 | 2005-02-21 Fernando Perez <fperez@colorado.edu> |
|
349 | 372 | |
|
350 | 373 | * IPython/Magic.py (magic_time): new magic to time execution of |
|
351 | 374 | expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>. |
|
352 | 375 | |
|
353 | 376 | 2005-02-19 Fernando Perez <fperez@colorado.edu> |
|
354 | 377 | |
|
355 | 378 | * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings |
|
356 | 379 | into keys (for prompts, for example). |
|
357 | 380 | |
|
358 | 381 | * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty |
|
359 | 382 | prompts in case users want them. This introduces a small behavior |
|
360 | 383 | change: ipython does not automatically add a space to all prompts |
|
361 | 384 | anymore. To get the old prompts with a space, users should add it |
|
362 | 385 | manually to their ipythonrc file, so for example prompt_in1 should |
|
363 | 386 | now read 'In [\#]: ' instead of 'In [\#]:'. |
|
364 | 387 | (BasePrompt.__init__): New option prompts_pad_left (only in rc |
|
365 | 388 | file) to control left-padding of secondary prompts. |
|
366 | 389 | |
|
367 | 390 | * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if |
|
368 | 391 | the profiler can't be imported. Fix for Debian, which removed |
|
369 | 392 | profile.py because of License issues. I applied a slightly |
|
370 | 393 | modified version of the original Debian patch at |
|
371 | 394 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500. |
|
372 | 395 | |
|
373 | 396 | 2005-02-17 Fernando Perez <fperez@colorado.edu> |
|
374 | 397 | |
|
375 | 398 | * IPython/genutils.py (native_line_ends): Fix bug which would |
|
376 | 399 | cause improper line-ends under win32 b/c I was not opening files |
|
377 | 400 | in binary mode. Bug report and fix thanks to Ville. |
|
378 | 401 | |
|
379 | 402 | * IPython/iplib.py (handle_auto): Fix bug which I introduced when |
|
380 | 403 | trying to catch spurious foo[1] autocalls. My fix actually broke |
|
381 | 404 | ',/' autoquote/call with explicit escape (bad regexp). |
|
382 | 405 | |
|
383 | 406 | 2005-02-15 *** Released version 0.6.11 |
|
384 | 407 | |
|
385 | 408 | 2005-02-14 Fernando Perez <fperez@colorado.edu> |
|
386 | 409 | |
|
387 | 410 | * IPython/background_jobs.py: New background job management |
|
388 | 411 | subsystem. This is implemented via a new set of classes, and |
|
389 | 412 | IPython now provides a builtin 'jobs' object for background job |
|
390 | 413 | execution. A convenience %bg magic serves as a lightweight |
|
391 | 414 | frontend for starting the more common type of calls. This was |
|
392 | 415 | inspired by discussions with B. Granger and the BackgroundCommand |
|
393 | 416 | class described in the book Python Scripting for Computational |
|
394 | 417 | Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting |
|
395 | 418 | (although ultimately no code from this text was used, as IPython's |
|
396 | 419 | system is a separate implementation). |
|
397 | 420 | |
|
398 | 421 | * IPython/iplib.py (MagicCompleter.python_matches): add new option |
|
399 | 422 | to control the completion of single/double underscore names |
|
400 | 423 | separately. As documented in the example ipytonrc file, the |
|
401 | 424 | readline_omit__names variable can now be set to 2, to omit even |
|
402 | 425 | single underscore names. Thanks to a patch by Brian Wong |
|
403 | 426 | <BrianWong-AT-AirgoNetworks.Com>. |
|
404 | 427 | (InteractiveShell.__init__): Fix bug which would cause foo[1] to |
|
405 | 428 | be autocalled as foo([1]) if foo were callable. A problem for |
|
406 | 429 | things which are both callable and implement __getitem__. |
|
407 | 430 | (init_readline): Fix autoindentation for win32. Thanks to a patch |
|
408 | 431 | by Vivian De Smedt <vivian-AT-vdesmedt.com>. |
|
409 | 432 | |
|
410 | 433 | 2005-02-12 Fernando Perez <fperez@colorado.edu> |
|
411 | 434 | |
|
412 | 435 | * IPython/ipmaker.py (make_IPython): Disabled the stout traps |
|
413 | 436 | which I had written long ago to sort out user error messages which |
|
414 | 437 | may occur during startup. This seemed like a good idea initially, |
|
415 | 438 | but it has proven a disaster in retrospect. I don't want to |
|
416 | 439 | change much code for now, so my fix is to set the internal 'debug' |
|
417 | 440 | flag to true everywhere, whose only job was precisely to control |
|
418 | 441 | this subsystem. This closes issue 28 (as well as avoiding all |
|
419 | 442 | sorts of strange hangups which occur from time to time). |
|
420 | 443 | |
|
421 | 444 | 2005-02-07 Fernando Perez <fperez@colorado.edu> |
|
422 | 445 | |
|
423 | 446 | * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the |
|
424 | 447 | previous call produced a syntax error. |
|
425 | 448 | |
|
426 | 449 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
427 | 450 | classes without constructor. |
|
428 | 451 | |
|
429 | 452 | 2005-02-06 Fernando Perez <fperez@colorado.edu> |
|
430 | 453 | |
|
431 | 454 | * IPython/iplib.py (MagicCompleter.complete): Extend the list of |
|
432 | 455 | completions with the results of each matcher, so we return results |
|
433 | 456 | to the user from all namespaces. This breaks with ipython |
|
434 | 457 | tradition, but I think it's a nicer behavior. Now you get all |
|
435 | 458 | possible completions listed, from all possible namespaces (python, |
|
436 | 459 | filesystem, magics...) After a request by John Hunter |
|
437 | 460 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
438 | 461 | |
|
439 | 462 | 2005-02-05 Fernando Perez <fperez@colorado.edu> |
|
440 | 463 | |
|
441 | 464 | * IPython/Magic.py (magic_prun): Fix bug where prun would fail if |
|
442 | 465 | the call had quote characters in it (the quotes were stripped). |
|
443 | 466 | |
|
444 | 467 | 2005-01-31 Fernando Perez <fperez@colorado.edu> |
|
445 | 468 | |
|
446 | 469 | * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on |
|
447 | 470 | Itpl.itpl() to make the code more robust against psyco |
|
448 | 471 | optimizations. |
|
449 | 472 | |
|
450 | 473 | * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead |
|
451 | 474 | of causing an exception. Quicker, cleaner. |
|
452 | 475 | |
|
453 | 476 | 2005-01-28 Fernando Perez <fperez@colorado.edu> |
|
454 | 477 | |
|
455 | 478 | * scripts/ipython_win_post_install.py (install): hardcode |
|
456 | 479 | sys.prefix+'python.exe' as the executable path. It turns out that |
|
457 | 480 | during the post-installation run, sys.executable resolves to the |
|
458 | 481 | name of the binary installer! I should report this as a distutils |
|
459 | 482 | bug, I think. I updated the .10 release with this tiny fix, to |
|
460 | 483 | avoid annoying the lists further. |
|
461 | 484 | |
|
462 | 485 | 2005-01-27 *** Released version 0.6.10 |
|
463 | 486 | |
|
464 | 487 | 2005-01-27 Fernando Perez <fperez@colorado.edu> |
|
465 | 488 | |
|
466 | 489 | * IPython/numutils.py (norm): Added 'inf' as optional name for |
|
467 | 490 | L-infinity norm, included references to mathworld.com for vector |
|
468 | 491 | norm definitions. |
|
469 | 492 | (amin/amax): added amin/amax for array min/max. Similar to what |
|
470 | 493 | pylab ships with after the recent reorganization of names. |
|
471 | 494 | (spike/spike_odd): removed deprecated spike/spike_odd functions. |
|
472 | 495 | |
|
473 | 496 | * ipython.el: committed Alex's recent fixes and improvements. |
|
474 | 497 | Tested with python-mode from CVS, and it looks excellent. Since |
|
475 | 498 | python-mode hasn't released anything in a while, I'm temporarily |
|
476 | 499 | putting a copy of today's CVS (v 4.70) of python-mode in: |
|
477 | 500 | http://ipython.scipy.org/tmp/python-mode.el |
|
478 | 501 | |
|
479 | 502 | * scripts/ipython_win_post_install.py (install): Win32 fix to use |
|
480 | 503 | sys.executable for the executable name, instead of assuming it's |
|
481 | 504 | called 'python.exe' (the post-installer would have produced broken |
|
482 | 505 | setups on systems with a differently named python binary). |
|
483 | 506 | |
|
484 | 507 | * IPython/PyColorize.py (Parser.__call__): change explicit '\n' |
|
485 | 508 | references to os.linesep, to make the code more |
|
486 | 509 | platform-independent. This is also part of the win32 coloring |
|
487 | 510 | fixes. |
|
488 | 511 | |
|
489 | 512 | * IPython/genutils.py (page_dumb): Remove attempts to chop long |
|
490 | 513 | lines, which actually cause coloring bugs because the length of |
|
491 | 514 | the line is very difficult to correctly compute with embedded |
|
492 | 515 | escapes. This was the source of all the coloring problems under |
|
493 | 516 | Win32. I think that _finally_, Win32 users have a properly |
|
494 | 517 | working ipython in all respects. This would never have happened |
|
495 | 518 | if not for Gary Bishop and Viktor Ransmayr's great help and work. |
|
496 | 519 | |
|
497 | 520 | 2005-01-26 *** Released version 0.6.9 |
|
498 | 521 | |
|
499 | 522 | 2005-01-25 Fernando Perez <fperez@colorado.edu> |
|
500 | 523 | |
|
501 | 524 | * setup.py: finally, we have a true Windows installer, thanks to |
|
502 | 525 | the excellent work of Viktor Ransmayr |
|
503 | 526 | <viktor.ransmayr-AT-t-online.de>. The docs have been updated for |
|
504 | 527 | Windows users. The setup routine is quite a bit cleaner thanks to |
|
505 | 528 | this, and the post-install script uses the proper functions to |
|
506 | 529 | allow a clean de-installation using the standard Windows Control |
|
507 | 530 | Panel. |
|
508 | 531 | |
|
509 | 532 | * IPython/genutils.py (get_home_dir): changed to use the $HOME |
|
510 | 533 | environment variable under all OSes (including win32) if |
|
511 | 534 | available. This will give consistency to win32 users who have set |
|
512 | 535 | this variable for any reason. If os.environ['HOME'] fails, the |
|
513 | 536 | previous policy of using HOMEDRIVE\HOMEPATH kicks in. |
|
514 | 537 | |
|
515 | 538 | 2005-01-24 Fernando Perez <fperez@colorado.edu> |
|
516 | 539 | |
|
517 | 540 | * IPython/numutils.py (empty_like): add empty_like(), similar to |
|
518 | 541 | zeros_like() but taking advantage of the new empty() Numeric routine. |
|
519 | 542 | |
|
520 | 543 | 2005-01-23 *** Released version 0.6.8 |
|
521 | 544 | |
|
522 | 545 | 2005-01-22 Fernando Perez <fperez@colorado.edu> |
|
523 | 546 | |
|
524 | 547 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the |
|
525 | 548 | automatic show() calls. After discussing things with JDH, it |
|
526 | 549 | turns out there are too many corner cases where this can go wrong. |
|
527 | 550 | It's best not to try to be 'too smart', and simply have ipython |
|
528 | 551 | reproduce as much as possible the default behavior of a normal |
|
529 | 552 | python shell. |
|
530 | 553 | |
|
531 | 554 | * IPython/iplib.py (InteractiveShell.__init__): Modified the |
|
532 | 555 | line-splitting regexp and _prefilter() to avoid calling getattr() |
|
533 | 556 | on assignments. This closes |
|
534 | 557 | http://www.scipy.net/roundup/ipython/issue24. Note that Python's |
|
535 | 558 | readline uses getattr(), so a simple <TAB> keypress is still |
|
536 | 559 | enough to trigger getattr() calls on an object. |
|
537 | 560 | |
|
538 | 561 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
539 | 562 | |
|
540 | 563 | * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run |
|
541 | 564 | docstring under pylab so it doesn't mask the original. |
|
542 | 565 | |
|
543 | 566 | 2005-01-21 *** Released version 0.6.7 |
|
544 | 567 | |
|
545 | 568 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
546 | 569 | |
|
547 | 570 | * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with |
|
548 | 571 | signal handling for win32 users in multithreaded mode. |
|
549 | 572 | |
|
550 | 573 | 2005-01-17 Fernando Perez <fperez@colorado.edu> |
|
551 | 574 | |
|
552 | 575 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
553 | 576 | instances with no __init__. After a crash report by Norbert Nemec |
|
554 | 577 | <Norbert-AT-nemec-online.de>. |
|
555 | 578 | |
|
556 | 579 | 2005-01-14 Fernando Perez <fperez@colorado.edu> |
|
557 | 580 | |
|
558 | 581 | * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of |
|
559 | 582 | names for verbose exceptions, when multiple dotted names and the |
|
560 | 583 | 'parent' object were present on the same line. |
|
561 | 584 | |
|
562 | 585 | 2005-01-11 Fernando Perez <fperez@colorado.edu> |
|
563 | 586 | |
|
564 | 587 | * IPython/genutils.py (flag_calls): new utility to trap and flag |
|
565 | 588 | calls in functions. I need it to clean up matplotlib support. |
|
566 | 589 | Also removed some deprecated code in genutils. |
|
567 | 590 | |
|
568 | 591 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so |
|
569 | 592 | that matplotlib scripts called with %run, which don't call show() |
|
570 | 593 | themselves, still have their plotting windows open. |
|
571 | 594 | |
|
572 | 595 | 2005-01-05 Fernando Perez <fperez@colorado.edu> |
|
573 | 596 | |
|
574 | 597 | * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw |
|
575 | 598 | <astraw-AT-caltech.edu>, to fix gtk deprecation warnings. |
|
576 | 599 | |
|
577 | 600 | 2004-12-19 Fernando Perez <fperez@colorado.edu> |
|
578 | 601 | |
|
579 | 602 | * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of |
|
580 | 603 | parent_runcode, which was an eyesore. The same result can be |
|
581 | 604 | obtained with Python's regular superclass mechanisms. |
|
582 | 605 | |
|
583 | 606 | 2004-12-17 Fernando Perez <fperez@colorado.edu> |
|
584 | 607 | |
|
585 | 608 | * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem |
|
586 | 609 | reported by Prabhu. |
|
587 | 610 | (Magic.magic_sx): direct all errors to Term.cerr (defaults to |
|
588 | 611 | sys.stderr) instead of explicitly calling sys.stderr. This helps |
|
589 | 612 | maintain our I/O abstractions clean, for future GUI embeddings. |
|
590 | 613 | |
|
591 | 614 | * IPython/genutils.py (info): added new utility for sys.stderr |
|
592 | 615 | unified info message handling (thin wrapper around warn()). |
|
593 | 616 | |
|
594 | 617 | * IPython/ultraTB.py (VerboseTB.text): Fix misreported global |
|
595 | 618 | composite (dotted) names on verbose exceptions. |
|
596 | 619 | (VerboseTB.nullrepr): harden against another kind of errors which |
|
597 | 620 | Python's inspect module can trigger, and which were crashing |
|
598 | 621 | IPython. Thanks to a report by Marco Lombardi |
|
599 | 622 | <mlombard-AT-ma010192.hq.eso.org>. |
|
600 | 623 | |
|
601 | 624 | 2004-12-13 *** Released version 0.6.6 |
|
602 | 625 | |
|
603 | 626 | 2004-12-12 Fernando Perez <fperez@colorado.edu> |
|
604 | 627 | |
|
605 | 628 | * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors |
|
606 | 629 | generated by pygtk upon initialization if it was built without |
|
607 | 630 | threads (for matplotlib users). After a crash reported by |
|
608 | 631 | Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>. |
|
609 | 632 | |
|
610 | 633 | * IPython/ipmaker.py (make_IPython): fix small bug in the |
|
611 | 634 | import_some parameter for multiple imports. |
|
612 | 635 | |
|
613 | 636 | * IPython/iplib.py (ipmagic): simplified the interface of |
|
614 | 637 | ipmagic() to take a single string argument, just as it would be |
|
615 | 638 | typed at the IPython cmd line. |
|
616 | 639 | (ipalias): Added new ipalias() with an interface identical to |
|
617 | 640 | ipmagic(). This completes exposing a pure python interface to the |
|
618 | 641 | alias and magic system, which can be used in loops or more complex |
|
619 | 642 | code where IPython's automatic line mangling is not active. |
|
620 | 643 | |
|
621 | 644 | * IPython/genutils.py (timing): changed interface of timing to |
|
622 | 645 | simply run code once, which is the most common case. timings() |
|
623 | 646 | remains unchanged, for the cases where you want multiple runs. |
|
624 | 647 | |
|
625 | 648 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a |
|
626 | 649 | bug where Python2.2 crashes with exec'ing code which does not end |
|
627 | 650 | in a single newline. Python 2.3 is OK, so I hadn't noticed this |
|
628 | 651 | before. |
|
629 | 652 | |
|
630 | 653 | 2004-12-10 Fernando Perez <fperez@colorado.edu> |
|
631 | 654 | |
|
632 | 655 | * IPython/Magic.py (Magic.magic_prun): changed name of option from |
|
633 | 656 | -t to -T, to accomodate the new -t flag in %run (the %run and |
|
634 | 657 | %prun options are kind of intermixed, and it's not easy to change |
|
635 | 658 | this with the limitations of python's getopt). |
|
636 | 659 | |
|
637 | 660 | * IPython/Magic.py (Magic.magic_run): Added new -t option to time |
|
638 | 661 | the execution of scripts. It's not as fine-tuned as timeit.py, |
|
639 | 662 | but it works from inside ipython (and under 2.2, which lacks |
|
640 | 663 | timeit.py). Optionally a number of runs > 1 can be given for |
|
641 | 664 | timing very short-running code. |
|
642 | 665 | |
|
643 | 666 | * IPython/genutils.py (uniq_stable): new routine which returns a |
|
644 | 667 | list of unique elements in any iterable, but in stable order of |
|
645 | 668 | appearance. I needed this for the ultraTB fixes, and it's a handy |
|
646 | 669 | utility. |
|
647 | 670 | |
|
648 | 671 | * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of |
|
649 | 672 | dotted names in Verbose exceptions. This had been broken since |
|
650 | 673 | the very start, now x.y will properly be printed in a Verbose |
|
651 | 674 | traceback, instead of x being shown and y appearing always as an |
|
652 | 675 | 'undefined global'. Getting this to work was a bit tricky, |
|
653 | 676 | because by default python tokenizers are stateless. Saved by |
|
654 | 677 | python's ability to easily add a bit of state to an arbitrary |
|
655 | 678 | function (without needing to build a full-blown callable object). |
|
656 | 679 | |
|
657 | 680 | Also big cleanup of this code, which had horrendous runtime |
|
658 | 681 | lookups of zillions of attributes for colorization. Moved all |
|
659 | 682 | this code into a few templates, which make it cleaner and quicker. |
|
660 | 683 | |
|
661 | 684 | Printout quality was also improved for Verbose exceptions: one |
|
662 | 685 | variable per line, and memory addresses are printed (this can be |
|
663 | 686 | quite handy in nasty debugging situations, which is what Verbose |
|
664 | 687 | is for). |
|
665 | 688 | |
|
666 | 689 | * IPython/ipmaker.py (make_IPython): Do NOT execute files named in |
|
667 | 690 | the command line as scripts to be loaded by embedded instances. |
|
668 | 691 | Doing so has the potential for an infinite recursion if there are |
|
669 | 692 | exceptions thrown in the process. This fixes a strange crash |
|
670 | 693 | reported by Philippe MULLER <muller-AT-irit.fr>. |
|
671 | 694 | |
|
672 | 695 | 2004-12-09 Fernando Perez <fperez@colorado.edu> |
|
673 | 696 | |
|
674 | 697 | * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support |
|
675 | 698 | to reflect new names in matplotlib, which now expose the |
|
676 | 699 | matlab-compatible interface via a pylab module instead of the |
|
677 | 700 | 'matlab' name. The new code is backwards compatible, so users of |
|
678 | 701 | all matplotlib versions are OK. Patch by J. Hunter. |
|
679 | 702 | |
|
680 | 703 | * IPython/OInspect.py (Inspector.pinfo): Add to object? printing |
|
681 | 704 | of __init__ docstrings for instances (class docstrings are already |
|
682 | 705 | automatically printed). Instances with customized docstrings |
|
683 | 706 | (indep. of the class) are also recognized and all 3 separate |
|
684 | 707 | docstrings are printed (instance, class, constructor). After some |
|
685 | 708 | comments/suggestions by J. Hunter. |
|
686 | 709 | |
|
687 | 710 | 2004-12-05 Fernando Perez <fperez@colorado.edu> |
|
688 | 711 | |
|
689 | 712 | * IPython/iplib.py (MagicCompleter.complete): Remove annoying |
|
690 | 713 | warnings when tab-completion fails and triggers an exception. |
|
691 | 714 | |
|
692 | 715 | 2004-12-03 Fernando Perez <fperez@colorado.edu> |
|
693 | 716 | |
|
694 | 717 | * IPython/Magic.py (magic_prun): Fix bug where an exception would |
|
695 | 718 | be triggered when using 'run -p'. An incorrect option flag was |
|
696 | 719 | being set ('d' instead of 'D'). |
|
697 | 720 | (manpage): fix missing escaped \- sign. |
|
698 | 721 | |
|
699 | 722 | 2004-11-30 *** Released version 0.6.5 |
|
700 | 723 | |
|
701 | 724 | 2004-11-30 Fernando Perez <fperez@colorado.edu> |
|
702 | 725 | |
|
703 | 726 | * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint |
|
704 | 727 | setting with -d option. |
|
705 | 728 | |
|
706 | 729 | * setup.py (docfiles): Fix problem where the doc glob I was using |
|
707 | 730 | was COMPLETELY BROKEN. It was giving the right files by pure |
|
708 | 731 | accident, but failed once I tried to include ipython.el. Note: |
|
709 | 732 | glob() does NOT allow you to do exclusion on multiple endings! |
|
710 | 733 | |
|
711 | 734 | 2004-11-29 Fernando Perez <fperez@colorado.edu> |
|
712 | 735 | |
|
713 | 736 | * IPython/usage.py (__doc__): cleaned up usage docstring, by using |
|
714 | 737 | the manpage as the source. Better formatting & consistency. |
|
715 | 738 | |
|
716 | 739 | * IPython/Magic.py (magic_run): Added new -d option, to run |
|
717 | 740 | scripts under the control of the python pdb debugger. Note that |
|
718 | 741 | this required changing the %prun option -d to -D, to avoid a clash |
|
719 | 742 | (since %run must pass options to %prun, and getopt is too dumb to |
|
720 | 743 | handle options with string values with embedded spaces). Thanks |
|
721 | 744 | to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>. |
|
722 | 745 | (magic_who_ls): added type matching to %who and %whos, so that one |
|
723 | 746 | can filter their output to only include variables of certain |
|
724 | 747 | types. Another suggestion by Matthew. |
|
725 | 748 | (magic_whos): Added memory summaries in kb and Mb for arrays. |
|
726 | 749 | (magic_who): Improve formatting (break lines every 9 vars). |
|
727 | 750 | |
|
728 | 751 | 2004-11-28 Fernando Perez <fperez@colorado.edu> |
|
729 | 752 | |
|
730 | 753 | * IPython/Logger.py (Logger.log): Fix bug in syncing the input |
|
731 | 754 | cache when empty lines were present. |
|
732 | 755 | |
|
733 | 756 | 2004-11-24 Fernando Perez <fperez@colorado.edu> |
|
734 | 757 | |
|
735 | 758 | * IPython/usage.py (__doc__): document the re-activated threading |
|
736 | 759 | options for WX and GTK. |
|
737 | 760 | |
|
738 | 761 | 2004-11-23 Fernando Perez <fperez@colorado.edu> |
|
739 | 762 | |
|
740 | 763 | * IPython/Shell.py (start): Added Prabhu's big patch to reactivate |
|
741 | 764 | the -wthread and -gthread options, along with a new -tk one to try |
|
742 | 765 | and coordinate Tk threading with wx/gtk. The tk support is very |
|
743 | 766 | platform dependent, since it seems to require Tcl and Tk to be |
|
744 | 767 | built with threads (Fedora1/2 appears NOT to have it, but in |
|
745 | 768 | Prabhu's Debian boxes it works OK). But even with some Tk |
|
746 | 769 | limitations, this is a great improvement. |
|
747 | 770 | |
|
748 | 771 | * IPython/Prompts.py (prompt_specials_color): Added \t for time |
|
749 | 772 | info in user prompts. Patch by Prabhu. |
|
750 | 773 | |
|
751 | 774 | 2004-11-18 Fernando Perez <fperez@colorado.edu> |
|
752 | 775 | |
|
753 | 776 | * IPython/genutils.py (ask_yes_no): Add check for a max of 20 |
|
754 | 777 | EOFErrors and bail, to avoid infinite loops if a non-terminating |
|
755 | 778 | file is fed into ipython. Patch submitted in issue 19 by user, |
|
756 | 779 | many thanks. |
|
757 | 780 | |
|
758 | 781 | * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger |
|
759 | 782 | autoquote/parens in continuation prompts, which can cause lots of |
|
760 | 783 | problems. Closes roundup issue 20. |
|
761 | 784 | |
|
762 | 785 | 2004-11-17 Fernando Perez <fperez@colorado.edu> |
|
763 | 786 | |
|
764 | 787 | * debian/control (Build-Depends-Indep): Fix dpatch dependency, |
|
765 | 788 | reported as debian bug #280505. I'm not sure my local changelog |
|
766 | 789 | entry has the proper debian format (Jack?). |
|
767 | 790 | |
|
768 | 791 | 2004-11-08 *** Released version 0.6.4 |
|
769 | 792 | |
|
770 | 793 | 2004-11-08 Fernando Perez <fperez@colorado.edu> |
|
771 | 794 | |
|
772 | 795 | * IPython/iplib.py (init_readline): Fix exit message for Windows |
|
773 | 796 | when readline is active. Thanks to a report by Eric Jones |
|
774 | 797 | <eric-AT-enthought.com>. |
|
775 | 798 | |
|
776 | 799 | 2004-11-07 Fernando Perez <fperez@colorado.edu> |
|
777 | 800 | |
|
778 | 801 | * IPython/genutils.py (page): Add a trap for OSError exceptions, |
|
779 | 802 | sometimes seen by win2k/cygwin users. |
|
780 | 803 | |
|
781 | 804 | 2004-11-06 Fernando Perez <fperez@colorado.edu> |
|
782 | 805 | |
|
783 | 806 | * IPython/iplib.py (interact): Change the handling of %Exit from |
|
784 | 807 | trying to propagate a SystemExit to an internal ipython flag. |
|
785 | 808 | This is less elegant than using Python's exception mechanism, but |
|
786 | 809 | I can't get that to work reliably with threads, so under -pylab |
|
787 | 810 | %Exit was hanging IPython. Cross-thread exception handling is |
|
788 | 811 | really a bitch. Thaks to a bug report by Stephen Walton |
|
789 | 812 | <stephen.walton-AT-csun.edu>. |
|
790 | 813 | |
|
791 | 814 | 2004-11-04 Fernando Perez <fperez@colorado.edu> |
|
792 | 815 | |
|
793 | 816 | * IPython/iplib.py (raw_input_original): store a pointer to the |
|
794 | 817 | true raw_input to harden against code which can modify it |
|
795 | 818 | (wx.py.PyShell does this and would otherwise crash ipython). |
|
796 | 819 | Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>. |
|
797 | 820 | |
|
798 | 821 | * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for |
|
799 | 822 | Ctrl-C problem, which does not mess up the input line. |
|
800 | 823 | |
|
801 | 824 | 2004-11-03 Fernando Perez <fperez@colorado.edu> |
|
802 | 825 | |
|
803 | 826 | * IPython/Release.py: Changed licensing to BSD, in all files. |
|
804 | 827 | (name): lowercase name for tarball/RPM release. |
|
805 | 828 | |
|
806 | 829 | * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for |
|
807 | 830 | use throughout ipython. |
|
808 | 831 | |
|
809 | 832 | * IPython/Magic.py (Magic._ofind): Switch to using the new |
|
810 | 833 | OInspect.getdoc() function. |
|
811 | 834 | |
|
812 | 835 | * IPython/Shell.py (sigint_handler): Hack to ignore the execution |
|
813 | 836 | of the line currently being canceled via Ctrl-C. It's extremely |
|
814 | 837 | ugly, but I don't know how to do it better (the problem is one of |
|
815 | 838 | handling cross-thread exceptions). |
|
816 | 839 | |
|
817 | 840 | 2004-10-28 Fernando Perez <fperez@colorado.edu> |
|
818 | 841 | |
|
819 | 842 | * IPython/Shell.py (signal_handler): add signal handlers to trap |
|
820 | 843 | SIGINT and SIGSEGV in threaded code properly. Thanks to a bug |
|
821 | 844 | report by Francesc Alted. |
|
822 | 845 | |
|
823 | 846 | 2004-10-21 Fernando Perez <fperez@colorado.edu> |
|
824 | 847 | |
|
825 | 848 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @ |
|
826 | 849 | to % for pysh syntax extensions. |
|
827 | 850 | |
|
828 | 851 | 2004-10-09 Fernando Perez <fperez@colorado.edu> |
|
829 | 852 | |
|
830 | 853 | * IPython/Magic.py (Magic.magic_whos): modify output of Numeric |
|
831 | 854 | arrays to print a more useful summary, without calling str(arr). |
|
832 | 855 | This avoids the problem of extremely lengthy computations which |
|
833 | 856 | occur if arr is large, and appear to the user as a system lockup |
|
834 | 857 | with 100% cpu activity. After a suggestion by Kristian Sandberg |
|
835 | 858 | <Kristian.Sandberg@colorado.edu>. |
|
836 | 859 | (Magic.__init__): fix bug in global magic escapes not being |
|
837 | 860 | correctly set. |
|
838 | 861 | |
|
839 | 862 | 2004-10-08 Fernando Perez <fperez@colorado.edu> |
|
840 | 863 | |
|
841 | 864 | * IPython/Magic.py (__license__): change to absolute imports of |
|
842 | 865 | ipython's own internal packages, to start adapting to the absolute |
|
843 | 866 | import requirement of PEP-328. |
|
844 | 867 | |
|
845 | 868 | * IPython/genutils.py (__author__): Fix coding to utf-8 on all |
|
846 | 869 | files, and standardize author/license marks through the Release |
|
847 | 870 | module instead of having per/file stuff (except for files with |
|
848 | 871 | particular licenses, like the MIT/PSF-licensed codes). |
|
849 | 872 | |
|
850 | 873 | * IPython/Debugger.py: remove dead code for python 2.1 |
|
851 | 874 | |
|
852 | 875 | 2004-10-04 Fernando Perez <fperez@colorado.edu> |
|
853 | 876 | |
|
854 | 877 | * IPython/iplib.py (ipmagic): New function for accessing magics |
|
855 | 878 | via a normal python function call. |
|
856 | 879 | |
|
857 | 880 | * IPython/Magic.py (Magic.magic_magic): Change the magic escape |
|
858 | 881 | from '@' to '%', to accomodate the new @decorator syntax of python |
|
859 | 882 | 2.4. |
|
860 | 883 | |
|
861 | 884 | 2004-09-29 Fernando Perez <fperez@colorado.edu> |
|
862 | 885 | |
|
863 | 886 | * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to |
|
864 | 887 | matplotlib.use to prevent running scripts which try to switch |
|
865 | 888 | interactive backends from within ipython. This will just crash |
|
866 | 889 | the python interpreter, so we can't allow it (but a detailed error |
|
867 | 890 | is given to the user). |
|
868 | 891 | |
|
869 | 892 | 2004-09-28 Fernando Perez <fperez@colorado.edu> |
|
870 | 893 | |
|
871 | 894 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): |
|
872 | 895 | matplotlib-related fixes so that using @run with non-matplotlib |
|
873 | 896 | scripts doesn't pop up spurious plot windows. This requires |
|
874 | 897 | matplotlib >= 0.63, where I had to make some changes as well. |
|
875 | 898 | |
|
876 | 899 | * IPython/ipmaker.py (make_IPython): update version requirement to |
|
877 | 900 | python 2.2. |
|
878 | 901 | |
|
879 | 902 | * IPython/iplib.py (InteractiveShell.mainloop): Add an optional |
|
880 | 903 | banner arg for embedded customization. |
|
881 | 904 | |
|
882 | 905 | * IPython/Magic.py (Magic.__init__): big cleanup to remove all |
|
883 | 906 | explicit uses of __IP as the IPython's instance name. Now things |
|
884 | 907 | are properly handled via the shell.name value. The actual code |
|
885 | 908 | is a bit ugly b/c I'm doing it via a global in Magic.py, but this |
|
886 | 909 | is much better than before. I'll clean things completely when the |
|
887 | 910 | magic stuff gets a real overhaul. |
|
888 | 911 | |
|
889 | 912 | * ipython.1: small fixes, sent in by Jack Moffit. He also sent in |
|
890 | 913 | minor changes to debian dir. |
|
891 | 914 | |
|
892 | 915 | * IPython/iplib.py (InteractiveShell.__init__): Fix adding a |
|
893 | 916 | pointer to the shell itself in the interactive namespace even when |
|
894 | 917 | a user-supplied dict is provided. This is needed for embedding |
|
895 | 918 | purposes (found by tests with Michel Sanner). |
|
896 | 919 | |
|
897 | 920 | 2004-09-27 Fernando Perez <fperez@colorado.edu> |
|
898 | 921 | |
|
899 | 922 | * IPython/UserConfig/ipythonrc: remove []{} from |
|
900 | 923 | readline_remove_delims, so that things like [modname.<TAB> do |
|
901 | 924 | proper completion. This disables [].TAB, but that's a less common |
|
902 | 925 | case than module names in list comprehensions, for example. |
|
903 | 926 | Thanks to a report by Andrea Riciputi. |
|
904 | 927 | |
|
905 | 928 | 2004-09-09 Fernando Perez <fperez@colorado.edu> |
|
906 | 929 | |
|
907 | 930 | * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid |
|
908 | 931 | blocking problems in win32 and osx. Fix by John. |
|
909 | 932 | |
|
910 | 933 | 2004-09-08 Fernando Perez <fperez@colorado.edu> |
|
911 | 934 | |
|
912 | 935 | * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug |
|
913 | 936 | for Win32 and OSX. Fix by John Hunter. |
|
914 | 937 | |
|
915 | 938 | 2004-08-30 *** Released version 0.6.3 |
|
916 | 939 | |
|
917 | 940 | 2004-08-30 Fernando Perez <fperez@colorado.edu> |
|
918 | 941 | |
|
919 | 942 | * setup.py (isfile): Add manpages to list of dependent files to be |
|
920 | 943 | updated. |
|
921 | 944 | |
|
922 | 945 | 2004-08-27 Fernando Perez <fperez@colorado.edu> |
|
923 | 946 | |
|
924 | 947 | * IPython/Shell.py (start): I've disabled -wthread and -gthread |
|
925 | 948 | for now. They don't really work with standalone WX/GTK code |
|
926 | 949 | (though matplotlib IS working fine with both of those backends). |
|
927 | 950 | This will neeed much more testing. I disabled most things with |
|
928 | 951 | comments, so turning it back on later should be pretty easy. |
|
929 | 952 | |
|
930 | 953 | * IPython/iplib.py (InteractiveShell.__init__): Fix accidental |
|
931 | 954 | autocalling of expressions like r'foo', by modifying the line |
|
932 | 955 | split regexp. Closes |
|
933 | 956 | http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas |
|
934 | 957 | Riley <ipythonbugs-AT-sabi.net>. |
|
935 | 958 | (InteractiveShell.mainloop): honor --nobanner with banner |
|
936 | 959 | extensions. |
|
937 | 960 | |
|
938 | 961 | * IPython/Shell.py: Significant refactoring of all classes, so |
|
939 | 962 | that we can really support ALL matplotlib backends and threading |
|
940 | 963 | models (John spotted a bug with Tk which required this). Now we |
|
941 | 964 | should support single-threaded, WX-threads and GTK-threads, both |
|
942 | 965 | for generic code and for matplotlib. |
|
943 | 966 | |
|
944 | 967 | * IPython/ipmaker.py (__call__): Changed -mpthread option to |
|
945 | 968 | -pylab, to simplify things for users. Will also remove the pylab |
|
946 | 969 | profile, since now all of matplotlib configuration is directly |
|
947 | 970 | handled here. This also reduces startup time. |
|
948 | 971 | |
|
949 | 972 | * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of |
|
950 | 973 | shell wasn't being correctly called. Also in IPShellWX. |
|
951 | 974 | |
|
952 | 975 | * IPython/iplib.py (InteractiveShell.__init__): Added option to |
|
953 | 976 | fine-tune banner. |
|
954 | 977 | |
|
955 | 978 | * IPython/numutils.py (spike): Deprecate these spike functions, |
|
956 | 979 | delete (long deprecated) gnuplot_exec handler. |
|
957 | 980 | |
|
958 | 981 | 2004-08-26 Fernando Perez <fperez@colorado.edu> |
|
959 | 982 | |
|
960 | 983 | * ipython.1: Update for threading options, plus some others which |
|
961 | 984 | were missing. |
|
962 | 985 | |
|
963 | 986 | * IPython/ipmaker.py (__call__): Added -wthread option for |
|
964 | 987 | wxpython thread handling. Make sure threading options are only |
|
965 | 988 | valid at the command line. |
|
966 | 989 | |
|
967 | 990 | * scripts/ipython: moved shell selection into a factory function |
|
968 | 991 | in Shell.py, to keep the starter script to a minimum. |
|
969 | 992 | |
|
970 | 993 | 2004-08-25 Fernando Perez <fperez@colorado.edu> |
|
971 | 994 | |
|
972 | 995 | * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by |
|
973 | 996 | John. Along with some recent changes he made to matplotlib, the |
|
974 | 997 | next versions of both systems should work very well together. |
|
975 | 998 | |
|
976 | 999 | 2004-08-24 Fernando Perez <fperez@colorado.edu> |
|
977 | 1000 | |
|
978 | 1001 | * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I |
|
979 | 1002 | tried to switch the profiling to using hotshot, but I'm getting |
|
980 | 1003 | strange errors from prof.runctx() there. I may be misreading the |
|
981 | 1004 | docs, but it looks weird. For now the profiling code will |
|
982 | 1005 | continue to use the standard profiler. |
|
983 | 1006 | |
|
984 | 1007 | 2004-08-23 Fernando Perez <fperez@colorado.edu> |
|
985 | 1008 | |
|
986 | 1009 | * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX |
|
987 | 1010 | threaded shell, by John Hunter. It's not quite ready yet, but |
|
988 | 1011 | close. |
|
989 | 1012 | |
|
990 | 1013 | 2004-08-22 Fernando Perez <fperez@colorado.edu> |
|
991 | 1014 | |
|
992 | 1015 | * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also |
|
993 | 1016 | in Magic and ultraTB. |
|
994 | 1017 | |
|
995 | 1018 | * ipython.1: document threading options in manpage. |
|
996 | 1019 | |
|
997 | 1020 | * scripts/ipython: Changed name of -thread option to -gthread, |
|
998 | 1021 | since this is GTK specific. I want to leave the door open for a |
|
999 | 1022 | -wthread option for WX, which will most likely be necessary. This |
|
1000 | 1023 | change affects usage and ipmaker as well. |
|
1001 | 1024 | |
|
1002 | 1025 | * IPython/Shell.py (matplotlib_shell): Add a factory function to |
|
1003 | 1026 | handle the matplotlib shell issues. Code by John Hunter |
|
1004 | 1027 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
1005 | 1028 | (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's |
|
1006 | 1029 | broken (and disabled for end users) for now, but it puts the |
|
1007 | 1030 | infrastructure in place. |
|
1008 | 1031 | |
|
1009 | 1032 | 2004-08-21 Fernando Perez <fperez@colorado.edu> |
|
1010 | 1033 | |
|
1011 | 1034 | * ipythonrc-pylab: Add matplotlib support. |
|
1012 | 1035 | |
|
1013 | 1036 | * matplotlib_config.py: new files for matplotlib support, part of |
|
1014 | 1037 | the pylab profile. |
|
1015 | 1038 | |
|
1016 | 1039 | * IPython/usage.py (__doc__): documented the threading options. |
|
1017 | 1040 | |
|
1018 | 1041 | 2004-08-20 Fernando Perez <fperez@colorado.edu> |
|
1019 | 1042 | |
|
1020 | 1043 | * ipython: Modified the main calling routine to handle the -thread |
|
1021 | 1044 | and -mpthread options. This needs to be done as a top-level hack, |
|
1022 | 1045 | because it determines which class to instantiate for IPython |
|
1023 | 1046 | itself. |
|
1024 | 1047 | |
|
1025 | 1048 | * IPython/Shell.py (MTInteractiveShell.__init__): New set of |
|
1026 | 1049 | classes to support multithreaded GTK operation without blocking, |
|
1027 | 1050 | and matplotlib with all backends. This is a lot of still very |
|
1028 | 1051 | experimental code, and threads are tricky. So it may still have a |
|
1029 | 1052 | few rough edges... This code owes a lot to |
|
1030 | 1053 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by |
|
1031 | 1054 | Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and |
|
1032 | 1055 | to John Hunter for all the matplotlib work. |
|
1033 | 1056 | |
|
1034 | 1057 | * IPython/ipmaker.py (__call__): Added -thread and -mpthread |
|
1035 | 1058 | options for gtk thread and matplotlib support. |
|
1036 | 1059 | |
|
1037 | 1060 | 2004-08-16 Fernando Perez <fperez@colorado.edu> |
|
1038 | 1061 | |
|
1039 | 1062 | * IPython/iplib.py (InteractiveShell.__init__): don't trigger |
|
1040 | 1063 | autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug |
|
1041 | 1064 | reported by Stephen Walton <stephen.walton-AT-csun.edu>. |
|
1042 | 1065 | |
|
1043 | 1066 | 2004-08-11 Fernando Perez <fperez@colorado.edu> |
|
1044 | 1067 | |
|
1045 | 1068 | * setup.py (isfile): Fix build so documentation gets updated for |
|
1046 | 1069 | rpms (it was only done for .tgz builds). |
|
1047 | 1070 | |
|
1048 | 1071 | 2004-08-10 Fernando Perez <fperez@colorado.edu> |
|
1049 | 1072 | |
|
1050 | 1073 | * genutils.py (Term): Fix misspell of stdin stream (sin->cin). |
|
1051 | 1074 | |
|
1052 | 1075 | * iplib.py : Silence syntax error exceptions in tab-completion. |
|
1053 | 1076 | |
|
1054 | 1077 | 2004-08-05 Fernando Perez <fperez@colorado.edu> |
|
1055 | 1078 | |
|
1056 | 1079 | * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set |
|
1057 | 1080 | 'color off' mark for continuation prompts. This was causing long |
|
1058 | 1081 | continuation lines to mis-wrap. |
|
1059 | 1082 | |
|
1060 | 1083 | 2004-08-01 Fernando Perez <fperez@colorado.edu> |
|
1061 | 1084 | |
|
1062 | 1085 | * IPython/ipmaker.py (make_IPython): Allow the shell class used |
|
1063 | 1086 | for building ipython to be a parameter. All this is necessary |
|
1064 | 1087 | right now to have a multithreaded version, but this insane |
|
1065 | 1088 | non-design will be cleaned up soon. For now, it's a hack that |
|
1066 | 1089 | works. |
|
1067 | 1090 | |
|
1068 | 1091 | * IPython/Shell.py (IPShell.__init__): Stop using mutable default |
|
1069 | 1092 | args in various places. No bugs so far, but it's a dangerous |
|
1070 | 1093 | practice. |
|
1071 | 1094 | |
|
1072 | 1095 | 2004-07-31 Fernando Perez <fperez@colorado.edu> |
|
1073 | 1096 | |
|
1074 | 1097 | * IPython/iplib.py (complete): ignore SyntaxError exceptions to |
|
1075 | 1098 | fix completion of files with dots in their names under most |
|
1076 | 1099 | profiles (pysh was OK because the completion order is different). |
|
1077 | 1100 | |
|
1078 | 1101 | 2004-07-27 Fernando Perez <fperez@colorado.edu> |
|
1079 | 1102 | |
|
1080 | 1103 | * IPython/iplib.py (InteractiveShell.__init__): build dict of |
|
1081 | 1104 | keywords manually, b/c the one in keyword.py was removed in python |
|
1082 | 1105 | 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>. |
|
1083 | 1106 | This is NOT a bug under python 2.3 and earlier. |
|
1084 | 1107 | |
|
1085 | 1108 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1086 | 1109 | |
|
1087 | 1110 | * IPython/ultraTB.py (VerboseTB.text): Add another |
|
1088 | 1111 | linecache.checkcache() call to try to prevent inspect.py from |
|
1089 | 1112 | crashing under python 2.3. I think this fixes |
|
1090 | 1113 | http://www.scipy.net/roundup/ipython/issue17. |
|
1091 | 1114 | |
|
1092 | 1115 | 2004-07-26 *** Released version 0.6.2 |
|
1093 | 1116 | |
|
1094 | 1117 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1095 | 1118 | |
|
1096 | 1119 | * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would |
|
1097 | 1120 | fail for any number. |
|
1098 | 1121 | (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for |
|
1099 | 1122 | empty bookmarks. |
|
1100 | 1123 | |
|
1101 | 1124 | 2004-07-26 *** Released version 0.6.1 |
|
1102 | 1125 | |
|
1103 | 1126 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1104 | 1127 | |
|
1105 | 1128 | * ipython_win_post_install.py (run): Added pysh shortcut for Windows. |
|
1106 | 1129 | |
|
1107 | 1130 | * IPython/iplib.py (protect_filename): Applied Ville's patch for |
|
1108 | 1131 | escaping '()[]{}' in filenames. |
|
1109 | 1132 | |
|
1110 | 1133 | * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for |
|
1111 | 1134 | Python 2.2 users who lack a proper shlex.split. |
|
1112 | 1135 | |
|
1113 | 1136 | 2004-07-19 Fernando Perez <fperez@colorado.edu> |
|
1114 | 1137 | |
|
1115 | 1138 | * IPython/iplib.py (InteractiveShell.init_readline): Add support |
|
1116 | 1139 | for reading readline's init file. I follow the normal chain: |
|
1117 | 1140 | $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a |
|
1118 | 1141 | report by Mike Heeter. This closes |
|
1119 | 1142 | http://www.scipy.net/roundup/ipython/issue16. |
|
1120 | 1143 | |
|
1121 | 1144 | 2004-07-18 Fernando Perez <fperez@colorado.edu> |
|
1122 | 1145 | |
|
1123 | 1146 | * IPython/iplib.py (__init__): Add better handling of '\' under |
|
1124 | 1147 | Win32 for filenames. After a patch by Ville. |
|
1125 | 1148 | |
|
1126 | 1149 | 2004-07-17 Fernando Perez <fperez@colorado.edu> |
|
1127 | 1150 | |
|
1128 | 1151 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1129 | 1152 | autocalling would be triggered for 'foo is bar' if foo is |
|
1130 | 1153 | callable. I also cleaned up the autocall detection code to use a |
|
1131 | 1154 | regexp, which is faster. Bug reported by Alexander Schmolck. |
|
1132 | 1155 | |
|
1133 | 1156 | * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with |
|
1134 | 1157 | '?' in them would confuse the help system. Reported by Alex |
|
1135 | 1158 | Schmolck. |
|
1136 | 1159 | |
|
1137 | 1160 | 2004-07-16 Fernando Perez <fperez@colorado.edu> |
|
1138 | 1161 | |
|
1139 | 1162 | * IPython/GnuplotInteractive.py (__all__): added plot2. |
|
1140 | 1163 | |
|
1141 | 1164 | * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for |
|
1142 | 1165 | plotting dictionaries, lists or tuples of 1d arrays. |
|
1143 | 1166 | |
|
1144 | 1167 | * IPython/Magic.py (Magic.magic_hist): small clenaups and |
|
1145 | 1168 | optimizations. |
|
1146 | 1169 | |
|
1147 | 1170 | * IPython/iplib.py:Remove old Changelog info for cleanup. This is |
|
1148 | 1171 | the information which was there from Janko's original IPP code: |
|
1149 | 1172 | |
|
1150 | 1173 | 03.05.99 20:53 porto.ifm.uni-kiel.de |
|
1151 | 1174 | --Started changelog. |
|
1152 | 1175 | --make clear do what it say it does |
|
1153 | 1176 | --added pretty output of lines from inputcache |
|
1154 | 1177 | --Made Logger a mixin class, simplifies handling of switches |
|
1155 | 1178 | --Added own completer class. .string<TAB> expands to last history |
|
1156 | 1179 | line which starts with string. The new expansion is also present |
|
1157 | 1180 | with Ctrl-r from the readline library. But this shows, who this |
|
1158 | 1181 | can be done for other cases. |
|
1159 | 1182 | --Added convention that all shell functions should accept a |
|
1160 | 1183 | parameter_string This opens the door for different behaviour for |
|
1161 | 1184 | each function. @cd is a good example of this. |
|
1162 | 1185 | |
|
1163 | 1186 | 04.05.99 12:12 porto.ifm.uni-kiel.de |
|
1164 | 1187 | --added logfile rotation |
|
1165 | 1188 | --added new mainloop method which freezes first the namespace |
|
1166 | 1189 | |
|
1167 | 1190 | 07.05.99 21:24 porto.ifm.uni-kiel.de |
|
1168 | 1191 | --added the docreader classes. Now there is a help system. |
|
1169 | 1192 | -This is only a first try. Currently it's not easy to put new |
|
1170 | 1193 | stuff in the indices. But this is the way to go. Info would be |
|
1171 | 1194 | better, but HTML is every where and not everybody has an info |
|
1172 | 1195 | system installed and it's not so easy to change html-docs to info. |
|
1173 | 1196 | --added global logfile option |
|
1174 | 1197 | --there is now a hook for object inspection method pinfo needs to |
|
1175 | 1198 | be provided for this. Can be reached by two '??'. |
|
1176 | 1199 | |
|
1177 | 1200 | 08.05.99 20:51 porto.ifm.uni-kiel.de |
|
1178 | 1201 | --added a README |
|
1179 | 1202 | --bug in rc file. Something has changed so functions in the rc |
|
1180 | 1203 | file need to reference the shell and not self. Not clear if it's a |
|
1181 | 1204 | bug or feature. |
|
1182 | 1205 | --changed rc file for new behavior |
|
1183 | 1206 | |
|
1184 | 1207 | 2004-07-15 Fernando Perez <fperez@colorado.edu> |
|
1185 | 1208 | |
|
1186 | 1209 | * IPython/Logger.py (Logger.log): fixed recent bug where the input |
|
1187 | 1210 | cache was falling out of sync in bizarre manners when multi-line |
|
1188 | 1211 | input was present. Minor optimizations and cleanup. |
|
1189 | 1212 | |
|
1190 | 1213 | (Logger): Remove old Changelog info for cleanup. This is the |
|
1191 | 1214 | information which was there from Janko's original code: |
|
1192 | 1215 | |
|
1193 | 1216 | Changes to Logger: - made the default log filename a parameter |
|
1194 | 1217 | |
|
1195 | 1218 | - put a check for lines beginning with !@? in log(). Needed |
|
1196 | 1219 | (even if the handlers properly log their lines) for mid-session |
|
1197 | 1220 | logging activation to work properly. Without this, lines logged |
|
1198 | 1221 | in mid session, which get read from the cache, would end up |
|
1199 | 1222 | 'bare' (with !@? in the open) in the log. Now they are caught |
|
1200 | 1223 | and prepended with a #. |
|
1201 | 1224 | |
|
1202 | 1225 | * IPython/iplib.py (InteractiveShell.init_readline): added check |
|
1203 | 1226 | in case MagicCompleter fails to be defined, so we don't crash. |
|
1204 | 1227 | |
|
1205 | 1228 | 2004-07-13 Fernando Perez <fperez@colorado.edu> |
|
1206 | 1229 | |
|
1207 | 1230 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation |
|
1208 | 1231 | of EPS if the requested filename ends in '.eps'. |
|
1209 | 1232 | |
|
1210 | 1233 | 2004-07-04 Fernando Perez <fperez@colorado.edu> |
|
1211 | 1234 | |
|
1212 | 1235 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix |
|
1213 | 1236 | escaping of quotes when calling the shell. |
|
1214 | 1237 | |
|
1215 | 1238 | 2004-07-02 Fernando Perez <fperez@colorado.edu> |
|
1216 | 1239 | |
|
1217 | 1240 | * IPython/Prompts.py (CachedOutput.update): Fix problem with |
|
1218 | 1241 | gettext not working because we were clobbering '_'. Fixes |
|
1219 | 1242 | http://www.scipy.net/roundup/ipython/issue6. |
|
1220 | 1243 | |
|
1221 | 1244 | 2004-07-01 Fernando Perez <fperez@colorado.edu> |
|
1222 | 1245 | |
|
1223 | 1246 | * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling |
|
1224 | 1247 | into @cd. Patch by Ville. |
|
1225 | 1248 | |
|
1226 | 1249 | * IPython/iplib.py (InteractiveShell.post_config_initialization): |
|
1227 | 1250 | new function to store things after ipmaker runs. Patch by Ville. |
|
1228 | 1251 | Eventually this will go away once ipmaker is removed and the class |
|
1229 | 1252 | gets cleaned up, but for now it's ok. Key functionality here is |
|
1230 | 1253 | the addition of the persistent storage mechanism, a dict for |
|
1231 | 1254 | keeping data across sessions (for now just bookmarks, but more can |
|
1232 | 1255 | be implemented later). |
|
1233 | 1256 | |
|
1234 | 1257 | * IPython/Magic.py (Magic.magic_bookmark): New bookmark system, |
|
1235 | 1258 | persistent across sections. Patch by Ville, I modified it |
|
1236 | 1259 | soemwhat to allow bookmarking arbitrary dirs other than CWD. Also |
|
1237 | 1260 | added a '-l' option to list all bookmarks. |
|
1238 | 1261 | |
|
1239 | 1262 | * IPython/iplib.py (InteractiveShell.atexit_operations): new |
|
1240 | 1263 | center for cleanup. Registered with atexit.register(). I moved |
|
1241 | 1264 | here the old exit_cleanup(). After a patch by Ville. |
|
1242 | 1265 | |
|
1243 | 1266 | * IPython/Magic.py (get_py_filename): added '~' to the accepted |
|
1244 | 1267 | characters in the hacked shlex_split for python 2.2. |
|
1245 | 1268 | |
|
1246 | 1269 | * IPython/iplib.py (file_matches): more fixes to filenames with |
|
1247 | 1270 | whitespace in them. It's not perfect, but limitations in python's |
|
1248 | 1271 | readline make it impossible to go further. |
|
1249 | 1272 | |
|
1250 | 1273 | 2004-06-29 Fernando Perez <fperez@colorado.edu> |
|
1251 | 1274 | |
|
1252 | 1275 | * IPython/iplib.py (file_matches): escape whitespace correctly in |
|
1253 | 1276 | filename completions. Bug reported by Ville. |
|
1254 | 1277 | |
|
1255 | 1278 | 2004-06-28 Fernando Perez <fperez@colorado.edu> |
|
1256 | 1279 | |
|
1257 | 1280 | * IPython/ipmaker.py (__call__): Added per-profile histories. Now |
|
1258 | 1281 | the history file will be called 'history-PROFNAME' (or just |
|
1259 | 1282 | 'history' if no profile is loaded). I was getting annoyed at |
|
1260 | 1283 | getting my Numerical work history clobbered by pysh sessions. |
|
1261 | 1284 | |
|
1262 | 1285 | * IPython/iplib.py (InteractiveShell.__init__): Internal |
|
1263 | 1286 | getoutputerror() function so that we can honor the system_verbose |
|
1264 | 1287 | flag for _all_ system calls. I also added escaping of # |
|
1265 | 1288 | characters here to avoid confusing Itpl. |
|
1266 | 1289 | |
|
1267 | 1290 | * IPython/Magic.py (shlex_split): removed call to shell in |
|
1268 | 1291 | parse_options and replaced it with shlex.split(). The annoying |
|
1269 | 1292 | part was that in Python 2.2, shlex.split() doesn't exist, so I had |
|
1270 | 1293 | to backport it from 2.3, with several frail hacks (the shlex |
|
1271 | 1294 | module is rather limited in 2.2). Thanks to a suggestion by Ville |
|
1272 | 1295 | Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no |
|
1273 | 1296 | problem. |
|
1274 | 1297 | |
|
1275 | 1298 | (Magic.magic_system_verbose): new toggle to print the actual |
|
1276 | 1299 | system calls made by ipython. Mainly for debugging purposes. |
|
1277 | 1300 | |
|
1278 | 1301 | * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which |
|
1279 | 1302 | doesn't support persistence. Reported (and fix suggested) by |
|
1280 | 1303 | Travis Caldwell <travis_caldwell2000@yahoo.com>. |
|
1281 | 1304 | |
|
1282 | 1305 | 2004-06-26 Fernando Perez <fperez@colorado.edu> |
|
1283 | 1306 | |
|
1284 | 1307 | * IPython/Logger.py (Logger.log): fix to handle correctly empty |
|
1285 | 1308 | continue prompts. |
|
1286 | 1309 | |
|
1287 | 1310 | * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh() |
|
1288 | 1311 | function (basically a big docstring) and a few more things here to |
|
1289 | 1312 | speedup startup. pysh.py is now very lightweight. We want because |
|
1290 | 1313 | it gets execfile'd, while InterpreterExec gets imported, so |
|
1291 | 1314 | byte-compilation saves time. |
|
1292 | 1315 | |
|
1293 | 1316 | 2004-06-25 Fernando Perez <fperez@colorado.edu> |
|
1294 | 1317 | |
|
1295 | 1318 | * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd |
|
1296 | 1319 | -NUM', which was recently broken. |
|
1297 | 1320 | |
|
1298 | 1321 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow ! |
|
1299 | 1322 | in multi-line input (but not !!, which doesn't make sense there). |
|
1300 | 1323 | |
|
1301 | 1324 | * IPython/UserConfig/ipythonrc: made autoindent on by default. |
|
1302 | 1325 | It's just too useful, and people can turn it off in the less |
|
1303 | 1326 | common cases where it's a problem. |
|
1304 | 1327 | |
|
1305 | 1328 | 2004-06-24 Fernando Perez <fperez@colorado.edu> |
|
1306 | 1329 | |
|
1307 | 1330 | * IPython/iplib.py (InteractiveShell._prefilter): big change - |
|
1308 | 1331 | special syntaxes (like alias calling) is now allied in multi-line |
|
1309 | 1332 | input. This is still _very_ experimental, but it's necessary for |
|
1310 | 1333 | efficient shell usage combining python looping syntax with system |
|
1311 | 1334 | calls. For now it's restricted to aliases, I don't think it |
|
1312 | 1335 | really even makes sense to have this for magics. |
|
1313 | 1336 | |
|
1314 | 1337 | 2004-06-23 Fernando Perez <fperez@colorado.edu> |
|
1315 | 1338 | |
|
1316 | 1339 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added |
|
1317 | 1340 | $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd. |
|
1318 | 1341 | |
|
1319 | 1342 | * IPython/Magic.py (Magic.magic_rehashx): modified to handle |
|
1320 | 1343 | extensions under Windows (after code sent by Gary Bishop). The |
|
1321 | 1344 | extensions considered 'executable' are stored in IPython's rc |
|
1322 | 1345 | structure as win_exec_ext. |
|
1323 | 1346 | |
|
1324 | 1347 | * IPython/genutils.py (shell): new function, like system() but |
|
1325 | 1348 | without return value. Very useful for interactive shell work. |
|
1326 | 1349 | |
|
1327 | 1350 | * IPython/Magic.py (Magic.magic_unalias): New @unalias function to |
|
1328 | 1351 | delete aliases. |
|
1329 | 1352 | |
|
1330 | 1353 | * IPython/iplib.py (InteractiveShell.alias_table_update): make |
|
1331 | 1354 | sure that the alias table doesn't contain python keywords. |
|
1332 | 1355 | |
|
1333 | 1356 | 2004-06-21 Fernando Perez <fperez@colorado.edu> |
|
1334 | 1357 | |
|
1335 | 1358 | * IPython/Magic.py (Magic.magic_rehash): Fix crash when |
|
1336 | 1359 | non-existent items are found in $PATH. Reported by Thorsten. |
|
1337 | 1360 | |
|
1338 | 1361 | 2004-06-20 Fernando Perez <fperez@colorado.edu> |
|
1339 | 1362 | |
|
1340 | 1363 | * IPython/iplib.py (complete): modified the completer so that the |
|
1341 | 1364 | order of priorities can be easily changed at runtime. |
|
1342 | 1365 | |
|
1343 | 1366 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): |
|
1344 | 1367 | Modified to auto-execute all lines beginning with '~', '/' or '.'. |
|
1345 | 1368 | |
|
1346 | 1369 | * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to |
|
1347 | 1370 | expand Python variables prepended with $ in all system calls. The |
|
1348 | 1371 | same was done to InteractiveShell.handle_shell_escape. Now all |
|
1349 | 1372 | system access mechanisms (!, !!, @sc, @sx and aliases) allow the |
|
1350 | 1373 | expansion of python variables and expressions according to the |
|
1351 | 1374 | syntax of PEP-215 - http://www.python.org/peps/pep-0215.html. |
|
1352 | 1375 | |
|
1353 | 1376 | Though PEP-215 has been rejected, a similar (but simpler) one |
|
1354 | 1377 | seems like it will go into Python 2.4, PEP-292 - |
|
1355 | 1378 | http://www.python.org/peps/pep-0292.html. |
|
1356 | 1379 | |
|
1357 | 1380 | I'll keep the full syntax of PEP-215, since IPython has since the |
|
1358 | 1381 | start used Ka-Ping Yee's reference implementation discussed there |
|
1359 | 1382 | (Itpl), and I actually like the powerful semantics it offers. |
|
1360 | 1383 | |
|
1361 | 1384 | In order to access normal shell variables, the $ has to be escaped |
|
1362 | 1385 | via an extra $. For example: |
|
1363 | 1386 | |
|
1364 | 1387 | In [7]: PATH='a python variable' |
|
1365 | 1388 | |
|
1366 | 1389 | In [8]: !echo $PATH |
|
1367 | 1390 | a python variable |
|
1368 | 1391 | |
|
1369 | 1392 | In [9]: !echo $$PATH |
|
1370 | 1393 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1371 | 1394 | |
|
1372 | 1395 | (Magic.parse_options): escape $ so the shell doesn't evaluate |
|
1373 | 1396 | things prematurely. |
|
1374 | 1397 | |
|
1375 | 1398 | * IPython/iplib.py (InteractiveShell.call_alias): added the |
|
1376 | 1399 | ability for aliases to expand python variables via $. |
|
1377 | 1400 | |
|
1378 | 1401 | * IPython/Magic.py (Magic.magic_rehash): based on the new alias |
|
1379 | 1402 | system, now there's a @rehash/@rehashx pair of magics. These work |
|
1380 | 1403 | like the csh rehash command, and can be invoked at any time. They |
|
1381 | 1404 | build a table of aliases to everything in the user's $PATH |
|
1382 | 1405 | (@rehash uses everything, @rehashx is slower but only adds |
|
1383 | 1406 | executable files). With this, the pysh.py-based shell profile can |
|
1384 | 1407 | now simply call rehash upon startup, and full access to all |
|
1385 | 1408 | programs in the user's path is obtained. |
|
1386 | 1409 | |
|
1387 | 1410 | * IPython/iplib.py (InteractiveShell.call_alias): The new alias |
|
1388 | 1411 | functionality is now fully in place. I removed the old dynamic |
|
1389 | 1412 | code generation based approach, in favor of a much lighter one |
|
1390 | 1413 | based on a simple dict. The advantage is that this allows me to |
|
1391 | 1414 | now have thousands of aliases with negligible cost (unthinkable |
|
1392 | 1415 | with the old system). |
|
1393 | 1416 | |
|
1394 | 1417 | 2004-06-19 Fernando Perez <fperez@colorado.edu> |
|
1395 | 1418 | |
|
1396 | 1419 | * IPython/iplib.py (__init__): extended MagicCompleter class to |
|
1397 | 1420 | also complete (last in priority) on user aliases. |
|
1398 | 1421 | |
|
1399 | 1422 | * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in |
|
1400 | 1423 | call to eval. |
|
1401 | 1424 | (ItplNS.__init__): Added a new class which functions like Itpl, |
|
1402 | 1425 | but allows configuring the namespace for the evaluation to occur |
|
1403 | 1426 | in. |
|
1404 | 1427 | |
|
1405 | 1428 | 2004-06-18 Fernando Perez <fperez@colorado.edu> |
|
1406 | 1429 | |
|
1407 | 1430 | * IPython/iplib.py (InteractiveShell.runcode): modify to print a |
|
1408 | 1431 | better message when 'exit' or 'quit' are typed (a common newbie |
|
1409 | 1432 | confusion). |
|
1410 | 1433 | |
|
1411 | 1434 | * IPython/Magic.py (Magic.magic_colors): Added the runtime color |
|
1412 | 1435 | check for Windows users. |
|
1413 | 1436 | |
|
1414 | 1437 | * IPython/iplib.py (InteractiveShell.user_setup): removed |
|
1415 | 1438 | disabling of colors for Windows. I'll test at runtime and issue a |
|
1416 | 1439 | warning if Gary's readline isn't found, as to nudge users to |
|
1417 | 1440 | download it. |
|
1418 | 1441 | |
|
1419 | 1442 | 2004-06-16 Fernando Perez <fperez@colorado.edu> |
|
1420 | 1443 | |
|
1421 | 1444 | * IPython/genutils.py (Stream.__init__): changed to print errors |
|
1422 | 1445 | to sys.stderr. I had a circular dependency here. Now it's |
|
1423 | 1446 | possible to run ipython as IDLE's shell (consider this pre-alpha, |
|
1424 | 1447 | since true stdout things end up in the starting terminal instead |
|
1425 | 1448 | of IDLE's out). |
|
1426 | 1449 | |
|
1427 | 1450 | * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for |
|
1428 | 1451 | users who haven't # updated their prompt_in2 definitions. Remove |
|
1429 | 1452 | eventually. |
|
1430 | 1453 | (multiple_replace): added credit to original ASPN recipe. |
|
1431 | 1454 | |
|
1432 | 1455 | 2004-06-15 Fernando Perez <fperez@colorado.edu> |
|
1433 | 1456 | |
|
1434 | 1457 | * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the |
|
1435 | 1458 | list of auto-defined aliases. |
|
1436 | 1459 | |
|
1437 | 1460 | 2004-06-13 Fernando Perez <fperez@colorado.edu> |
|
1438 | 1461 | |
|
1439 | 1462 | * setup.py (scriptfiles): Don't trigger win_post_install unless an |
|
1440 | 1463 | install was really requested (so setup.py can be used for other |
|
1441 | 1464 | things under Windows). |
|
1442 | 1465 | |
|
1443 | 1466 | 2004-06-10 Fernando Perez <fperez@colorado.edu> |
|
1444 | 1467 | |
|
1445 | 1468 | * IPython/Logger.py (Logger.create_log): Manually remove any old |
|
1446 | 1469 | backup, since os.remove may fail under Windows. Fixes bug |
|
1447 | 1470 | reported by Thorsten. |
|
1448 | 1471 | |
|
1449 | 1472 | 2004-06-09 Fernando Perez <fperez@colorado.edu> |
|
1450 | 1473 | |
|
1451 | 1474 | * examples/example-embed.py: fixed all references to %n (replaced |
|
1452 | 1475 | with \\# for ps1/out prompts and with \\D for ps2 prompts). Done |
|
1453 | 1476 | for all examples and the manual as well. |
|
1454 | 1477 | |
|
1455 | 1478 | 2004-06-08 Fernando Perez <fperez@colorado.edu> |
|
1456 | 1479 | |
|
1457 | 1480 | * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt |
|
1458 | 1481 | alignment and color management. All 3 prompt subsystems now |
|
1459 | 1482 | inherit from BasePrompt. |
|
1460 | 1483 | |
|
1461 | 1484 | * tools/release: updates for windows installer build and tag rpms |
|
1462 | 1485 | with python version (since paths are fixed). |
|
1463 | 1486 | |
|
1464 | 1487 | * IPython/UserConfig/ipythonrc: modified to use \# instead of %n, |
|
1465 | 1488 | which will become eventually obsolete. Also fixed the default |
|
1466 | 1489 | prompt_in2 to use \D, so at least new users start with the correct |
|
1467 | 1490 | defaults. |
|
1468 | 1491 | WARNING: Users with existing ipythonrc files will need to apply |
|
1469 | 1492 | this fix manually! |
|
1470 | 1493 | |
|
1471 | 1494 | * setup.py: make windows installer (.exe). This is finally the |
|
1472 | 1495 | integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>, |
|
1473 | 1496 | which I hadn't included because it required Python 2.3 (or recent |
|
1474 | 1497 | distutils). |
|
1475 | 1498 | |
|
1476 | 1499 | * IPython/usage.py (__doc__): update docs (and manpage) to reflect |
|
1477 | 1500 | usage of new '\D' escape. |
|
1478 | 1501 | |
|
1479 | 1502 | * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which |
|
1480 | 1503 | lacks os.getuid()) |
|
1481 | 1504 | (CachedOutput.set_colors): Added the ability to turn coloring |
|
1482 | 1505 | on/off with @colors even for manually defined prompt colors. It |
|
1483 | 1506 | uses a nasty global, but it works safely and via the generic color |
|
1484 | 1507 | handling mechanism. |
|
1485 | 1508 | (Prompt2.__init__): Introduced new escape '\D' for continuation |
|
1486 | 1509 | prompts. It represents the counter ('\#') as dots. |
|
1487 | 1510 | *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will |
|
1488 | 1511 | need to update their ipythonrc files and replace '%n' with '\D' in |
|
1489 | 1512 | their prompt_in2 settings everywhere. Sorry, but there's |
|
1490 | 1513 | otherwise no clean way to get all prompts to properly align. The |
|
1491 | 1514 | ipythonrc shipped with IPython has been updated. |
|
1492 | 1515 | |
|
1493 | 1516 | 2004-06-07 Fernando Perez <fperez@colorado.edu> |
|
1494 | 1517 | |
|
1495 | 1518 | * setup.py (isfile): Pass local_icons option to latex2html, so the |
|
1496 | 1519 | resulting HTML file is self-contained. Thanks to |
|
1497 | 1520 | dryice-AT-liu.com.cn for the tip. |
|
1498 | 1521 | |
|
1499 | 1522 | * pysh.py: I created a new profile 'shell', which implements a |
|
1500 | 1523 | _rudimentary_ IPython-based shell. This is in NO WAY a realy |
|
1501 | 1524 | system shell, nor will it become one anytime soon. It's mainly |
|
1502 | 1525 | meant to illustrate the use of the new flexible bash-like prompts. |
|
1503 | 1526 | I guess it could be used by hardy souls for true shell management, |
|
1504 | 1527 | but it's no tcsh/bash... pysh.py is loaded by the 'shell' |
|
1505 | 1528 | profile. This uses the InterpreterExec extension provided by |
|
1506 | 1529 | W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl> |
|
1507 | 1530 | |
|
1508 | 1531 | * IPython/Prompts.py (PromptOut.__str__): now it will correctly |
|
1509 | 1532 | auto-align itself with the length of the previous input prompt |
|
1510 | 1533 | (taking into account the invisible color escapes). |
|
1511 | 1534 | (CachedOutput.__init__): Large restructuring of this class. Now |
|
1512 | 1535 | all three prompts (primary1, primary2, output) are proper objects, |
|
1513 | 1536 | managed by the 'parent' CachedOutput class. The code is still a |
|
1514 | 1537 | bit hackish (all prompts share state via a pointer to the cache), |
|
1515 | 1538 | but it's overall far cleaner than before. |
|
1516 | 1539 | |
|
1517 | 1540 | * IPython/genutils.py (getoutputerror): modified to add verbose, |
|
1518 | 1541 | debug and header options. This makes the interface of all getout* |
|
1519 | 1542 | functions uniform. |
|
1520 | 1543 | (SystemExec.getoutputerror): added getoutputerror to SystemExec. |
|
1521 | 1544 | |
|
1522 | 1545 | * IPython/Magic.py (Magic.default_option): added a function to |
|
1523 | 1546 | allow registering default options for any magic command. This |
|
1524 | 1547 | makes it easy to have profiles which customize the magics globally |
|
1525 | 1548 | for a certain use. The values set through this function are |
|
1526 | 1549 | picked up by the parse_options() method, which all magics should |
|
1527 | 1550 | use to parse their options. |
|
1528 | 1551 | |
|
1529 | 1552 | * IPython/genutils.py (warn): modified the warnings framework to |
|
1530 | 1553 | use the Term I/O class. I'm trying to slowly unify all of |
|
1531 | 1554 | IPython's I/O operations to pass through Term. |
|
1532 | 1555 | |
|
1533 | 1556 | * IPython/Prompts.py (Prompt2._str_other): Added functionality in |
|
1534 | 1557 | the secondary prompt to correctly match the length of the primary |
|
1535 | 1558 | one for any prompt. Now multi-line code will properly line up |
|
1536 | 1559 | even for path dependent prompts, such as the new ones available |
|
1537 | 1560 | via the prompt_specials. |
|
1538 | 1561 | |
|
1539 | 1562 | 2004-06-06 Fernando Perez <fperez@colorado.edu> |
|
1540 | 1563 | |
|
1541 | 1564 | * IPython/Prompts.py (prompt_specials): Added the ability to have |
|
1542 | 1565 | bash-like special sequences in the prompts, which get |
|
1543 | 1566 | automatically expanded. Things like hostname, current working |
|
1544 | 1567 | directory and username are implemented already, but it's easy to |
|
1545 | 1568 | add more in the future. Thanks to a patch by W.J. van der Laan |
|
1546 | 1569 | <gnufnork-AT-hetdigitalegat.nl> |
|
1547 | 1570 | (prompt_specials): Added color support for prompt strings, so |
|
1548 | 1571 | users can define arbitrary color setups for their prompts. |
|
1549 | 1572 | |
|
1550 | 1573 | 2004-06-05 Fernando Perez <fperez@colorado.edu> |
|
1551 | 1574 | |
|
1552 | 1575 | * IPython/genutils.py (Term.reopen_all): Added Windows-specific |
|
1553 | 1576 | code to load Gary Bishop's readline and configure it |
|
1554 | 1577 | automatically. Thanks to Gary for help on this. |
|
1555 | 1578 | |
|
1556 | 1579 | 2004-06-01 Fernando Perez <fperez@colorado.edu> |
|
1557 | 1580 | |
|
1558 | 1581 | * IPython/Logger.py (Logger.create_log): fix bug for logging |
|
1559 | 1582 | with no filename (previous fix was incomplete). |
|
1560 | 1583 | |
|
1561 | 1584 | 2004-05-25 Fernando Perez <fperez@colorado.edu> |
|
1562 | 1585 | |
|
1563 | 1586 | * IPython/Magic.py (Magic.parse_options): fix bug where naked |
|
1564 | 1587 | parens would get passed to the shell. |
|
1565 | 1588 | |
|
1566 | 1589 | 2004-05-20 Fernando Perez <fperez@colorado.edu> |
|
1567 | 1590 | |
|
1568 | 1591 | * IPython/Magic.py (Magic.magic_prun): changed default profile |
|
1569 | 1592 | sort order to 'time' (the more common profiling need). |
|
1570 | 1593 | |
|
1571 | 1594 | * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache |
|
1572 | 1595 | so that source code shown is guaranteed in sync with the file on |
|
1573 | 1596 | disk (also changed in psource). Similar fix to the one for |
|
1574 | 1597 | ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du |
|
1575 | 1598 | <yann.ledu-AT-noos.fr>. |
|
1576 | 1599 | |
|
1577 | 1600 | * IPython/Magic.py (Magic.parse_options): Fixed bug where commands |
|
1578 | 1601 | with a single option would not be correctly parsed. Closes |
|
1579 | 1602 | http://www.scipy.net/roundup/ipython/issue14. This bug had been |
|
1580 | 1603 | introduced in 0.6.0 (on 2004-05-06). |
|
1581 | 1604 | |
|
1582 | 1605 | 2004-05-13 *** Released version 0.6.0 |
|
1583 | 1606 | |
|
1584 | 1607 | 2004-05-13 Fernando Perez <fperez@colorado.edu> |
|
1585 | 1608 | |
|
1586 | 1609 | * debian/: Added debian/ directory to CVS, so that debian support |
|
1587 | 1610 | is publicly accessible. The debian package is maintained by Jack |
|
1588 | 1611 | Moffit <jack-AT-xiph.org>. |
|
1589 | 1612 | |
|
1590 | 1613 | * Documentation: included the notes about an ipython-based system |
|
1591 | 1614 | shell (the hypothetical 'pysh') into the new_design.pdf document, |
|
1592 | 1615 | so that these ideas get distributed to users along with the |
|
1593 | 1616 | official documentation. |
|
1594 | 1617 | |
|
1595 | 1618 | 2004-05-10 Fernando Perez <fperez@colorado.edu> |
|
1596 | 1619 | |
|
1597 | 1620 | * IPython/Logger.py (Logger.create_log): fix recently introduced |
|
1598 | 1621 | bug (misindented line) where logstart would fail when not given an |
|
1599 | 1622 | explicit filename. |
|
1600 | 1623 | |
|
1601 | 1624 | 2004-05-09 Fernando Perez <fperez@colorado.edu> |
|
1602 | 1625 | |
|
1603 | 1626 | * IPython/Magic.py (Magic.parse_options): skip system call when |
|
1604 | 1627 | there are no options to look for. Faster, cleaner for the common |
|
1605 | 1628 | case. |
|
1606 | 1629 | |
|
1607 | 1630 | * Documentation: many updates to the manual: describing Windows |
|
1608 | 1631 | support better, Gnuplot updates, credits, misc small stuff. Also |
|
1609 | 1632 | updated the new_design doc a bit. |
|
1610 | 1633 | |
|
1611 | 1634 | 2004-05-06 *** Released version 0.6.0.rc1 |
|
1612 | 1635 | |
|
1613 | 1636 | 2004-05-06 Fernando Perez <fperez@colorado.edu> |
|
1614 | 1637 | |
|
1615 | 1638 | * IPython/ultraTB.py (ListTB.text): modified a ton of string += |
|
1616 | 1639 | operations to use the vastly more efficient list/''.join() method. |
|
1617 | 1640 | (FormattedTB.text): Fix |
|
1618 | 1641 | http://www.scipy.net/roundup/ipython/issue12 - exception source |
|
1619 | 1642 | extract not updated after reload. Thanks to Mike Salib |
|
1620 | 1643 | <msalib-AT-mit.edu> for pinning the source of the problem. |
|
1621 | 1644 | Fortunately, the solution works inside ipython and doesn't require |
|
1622 | 1645 | any changes to python proper. |
|
1623 | 1646 | |
|
1624 | 1647 | * IPython/Magic.py (Magic.parse_options): Improved to process the |
|
1625 | 1648 | argument list as a true shell would (by actually using the |
|
1626 | 1649 | underlying system shell). This way, all @magics automatically get |
|
1627 | 1650 | shell expansion for variables. Thanks to a comment by Alex |
|
1628 | 1651 | Schmolck. |
|
1629 | 1652 | |
|
1630 | 1653 | 2004-04-04 Fernando Perez <fperez@colorado.edu> |
|
1631 | 1654 | |
|
1632 | 1655 | * IPython/iplib.py (InteractiveShell.interact): Added a special |
|
1633 | 1656 | trap for a debugger quit exception, which is basically impossible |
|
1634 | 1657 | to handle by normal mechanisms, given what pdb does to the stack. |
|
1635 | 1658 | This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>. |
|
1636 | 1659 | |
|
1637 | 1660 | 2004-04-03 Fernando Perez <fperez@colorado.edu> |
|
1638 | 1661 | |
|
1639 | 1662 | * IPython/genutils.py (Term): Standardized the names of the Term |
|
1640 | 1663 | class streams to cin/cout/cerr, following C++ naming conventions |
|
1641 | 1664 | (I can't use in/out/err because 'in' is not a valid attribute |
|
1642 | 1665 | name). |
|
1643 | 1666 | |
|
1644 | 1667 | * IPython/iplib.py (InteractiveShell.interact): don't increment |
|
1645 | 1668 | the prompt if there's no user input. By Daniel 'Dang' Griffith |
|
1646 | 1669 | <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from |
|
1647 | 1670 | Francois Pinard. |
|
1648 | 1671 | |
|
1649 | 1672 | 2004-04-02 Fernando Perez <fperez@colorado.edu> |
|
1650 | 1673 | |
|
1651 | 1674 | * IPython/genutils.py (Stream.__init__): Modified to survive at |
|
1652 | 1675 | least importing in contexts where stdin/out/err aren't true file |
|
1653 | 1676 | objects, such as PyCrust (they lack fileno() and mode). However, |
|
1654 | 1677 | the recovery facilities which rely on these things existing will |
|
1655 | 1678 | not work. |
|
1656 | 1679 | |
|
1657 | 1680 | 2004-04-01 Fernando Perez <fperez@colorado.edu> |
|
1658 | 1681 | |
|
1659 | 1682 | * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to |
|
1660 | 1683 | use the new getoutputerror() function, so it properly |
|
1661 | 1684 | distinguishes stdout/err. |
|
1662 | 1685 | |
|
1663 | 1686 | * IPython/genutils.py (getoutputerror): added a function to |
|
1664 | 1687 | capture separately the standard output and error of a command. |
|
1665 | 1688 | After a comment from dang on the mailing lists. This code is |
|
1666 | 1689 | basically a modified version of commands.getstatusoutput(), from |
|
1667 | 1690 | the standard library. |
|
1668 | 1691 | |
|
1669 | 1692 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): added |
|
1670 | 1693 | '!!' as a special syntax (shorthand) to access @sx. |
|
1671 | 1694 | |
|
1672 | 1695 | * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell |
|
1673 | 1696 | command and return its output as a list split on '\n'. |
|
1674 | 1697 | |
|
1675 | 1698 | 2004-03-31 Fernando Perez <fperez@colorado.edu> |
|
1676 | 1699 | |
|
1677 | 1700 | * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__ |
|
1678 | 1701 | method to dictionaries used as FakeModule instances if they lack |
|
1679 | 1702 | it. At least pydoc in python2.3 breaks for runtime-defined |
|
1680 | 1703 | functions without this hack. At some point I need to _really_ |
|
1681 | 1704 | understand what FakeModule is doing, because it's a gross hack. |
|
1682 | 1705 | But it solves Arnd's problem for now... |
|
1683 | 1706 | |
|
1684 | 1707 | 2004-02-27 Fernando Perez <fperez@colorado.edu> |
|
1685 | 1708 | |
|
1686 | 1709 | * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate' |
|
1687 | 1710 | mode would behave erratically. Also increased the number of |
|
1688 | 1711 | possible logs in rotate mod to 999. Thanks to Rod Holland |
|
1689 | 1712 | <rhh@StructureLABS.com> for the report and fixes. |
|
1690 | 1713 | |
|
1691 | 1714 | 2004-02-26 Fernando Perez <fperez@colorado.edu> |
|
1692 | 1715 | |
|
1693 | 1716 | * IPython/genutils.py (page): Check that the curses module really |
|
1694 | 1717 | has the initscr attribute before trying to use it. For some |
|
1695 | 1718 | reason, the Solaris curses module is missing this. I think this |
|
1696 | 1719 | should be considered a Solaris python bug, but I'm not sure. |
|
1697 | 1720 | |
|
1698 | 1721 | 2004-01-17 Fernando Perez <fperez@colorado.edu> |
|
1699 | 1722 | |
|
1700 | 1723 | * IPython/genutils.py (Stream.__init__): Changes to try to make |
|
1701 | 1724 | ipython robust against stdin/out/err being closed by the user. |
|
1702 | 1725 | This is 'user error' (and blocks a normal python session, at least |
|
1703 | 1726 | the stdout case). However, Ipython should be able to survive such |
|
1704 | 1727 | instances of abuse as gracefully as possible. To simplify the |
|
1705 | 1728 | coding and maintain compatibility with Gary Bishop's Term |
|
1706 | 1729 | contributions, I've made use of classmethods for this. I think |
|
1707 | 1730 | this introduces a dependency on python 2.2. |
|
1708 | 1731 | |
|
1709 | 1732 | 2004-01-13 Fernando Perez <fperez@colorado.edu> |
|
1710 | 1733 | |
|
1711 | 1734 | * IPython/numutils.py (exp_safe): simplified the code a bit and |
|
1712 | 1735 | removed the need for importing the kinds module altogether. |
|
1713 | 1736 | |
|
1714 | 1737 | 2004-01-06 Fernando Perez <fperez@colorado.edu> |
|
1715 | 1738 | |
|
1716 | 1739 | * IPython/Magic.py (Magic.magic_sc): Made the shell capture system |
|
1717 | 1740 | a magic function instead, after some community feedback. No |
|
1718 | 1741 | special syntax will exist for it, but its name is deliberately |
|
1719 | 1742 | very short. |
|
1720 | 1743 | |
|
1721 | 1744 | 2003-12-20 Fernando Perez <fperez@colorado.edu> |
|
1722 | 1745 | |
|
1723 | 1746 | * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added |
|
1724 | 1747 | new functionality, to automagically assign the result of a shell |
|
1725 | 1748 | command to a variable. I'll solicit some community feedback on |
|
1726 | 1749 | this before making it permanent. |
|
1727 | 1750 | |
|
1728 | 1751 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was |
|
1729 | 1752 | requested about callables for which inspect couldn't obtain a |
|
1730 | 1753 | proper argspec. Thanks to a crash report sent by Etienne |
|
1731 | 1754 | Posthumus <etienne-AT-apple01.cs.vu.nl>. |
|
1732 | 1755 | |
|
1733 | 1756 | 2003-12-09 Fernando Perez <fperez@colorado.edu> |
|
1734 | 1757 | |
|
1735 | 1758 | * IPython/genutils.py (page): patch for the pager to work across |
|
1736 | 1759 | various versions of Windows. By Gary Bishop. |
|
1737 | 1760 | |
|
1738 | 1761 | 2003-12-04 Fernando Perez <fperez@colorado.edu> |
|
1739 | 1762 | |
|
1740 | 1763 | * IPython/Gnuplot2.py (PlotItems): Fixes for working with |
|
1741 | 1764 | Gnuplot.py version 1.7, whose internal names changed quite a bit. |
|
1742 | 1765 | While I tested this and it looks ok, there may still be corner |
|
1743 | 1766 | cases I've missed. |
|
1744 | 1767 | |
|
1745 | 1768 | 2003-12-01 Fernando Perez <fperez@colorado.edu> |
|
1746 | 1769 | |
|
1747 | 1770 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug |
|
1748 | 1771 | where a line like 'p,q=1,2' would fail because the automagic |
|
1749 | 1772 | system would be triggered for @p. |
|
1750 | 1773 | |
|
1751 | 1774 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related |
|
1752 | 1775 | cleanups, code unmodified. |
|
1753 | 1776 | |
|
1754 | 1777 | * IPython/genutils.py (Term): added a class for IPython to handle |
|
1755 | 1778 | output. In most cases it will just be a proxy for stdout/err, but |
|
1756 | 1779 | having this allows modifications to be made for some platforms, |
|
1757 | 1780 | such as handling color escapes under Windows. All of this code |
|
1758 | 1781 | was contributed by Gary Bishop, with minor modifications by me. |
|
1759 | 1782 | The actual changes affect many files. |
|
1760 | 1783 | |
|
1761 | 1784 | 2003-11-30 Fernando Perez <fperez@colorado.edu> |
|
1762 | 1785 | |
|
1763 | 1786 | * IPython/iplib.py (file_matches): new completion code, courtesy |
|
1764 | 1787 | of Jeff Collins. This enables filename completion again under |
|
1765 | 1788 | python 2.3, which disabled it at the C level. |
|
1766 | 1789 | |
|
1767 | 1790 | 2003-11-11 Fernando Perez <fperez@colorado.edu> |
|
1768 | 1791 | |
|
1769 | 1792 | * IPython/numutils.py (amap): Added amap() fn. Simple shorthand |
|
1770 | 1793 | for Numeric.array(map(...)), but often convenient. |
|
1771 | 1794 | |
|
1772 | 1795 | 2003-11-05 Fernando Perez <fperez@colorado.edu> |
|
1773 | 1796 | |
|
1774 | 1797 | * IPython/numutils.py (frange): Changed a call from int() to |
|
1775 | 1798 | int(round()) to prevent a problem reported with arange() in the |
|
1776 | 1799 | numpy list. |
|
1777 | 1800 | |
|
1778 | 1801 | 2003-10-06 Fernando Perez <fperez@colorado.edu> |
|
1779 | 1802 | |
|
1780 | 1803 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to |
|
1781 | 1804 | prevent crashes if sys lacks an argv attribute (it happens with |
|
1782 | 1805 | embedded interpreters which build a bare-bones sys module). |
|
1783 | 1806 | Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>. |
|
1784 | 1807 | |
|
1785 | 1808 | 2003-09-24 Fernando Perez <fperez@colorado.edu> |
|
1786 | 1809 | |
|
1787 | 1810 | * IPython/Magic.py (Magic._ofind): blanket except around getattr() |
|
1788 | 1811 | to protect against poorly written user objects where __getattr__ |
|
1789 | 1812 | raises exceptions other than AttributeError. Thanks to a bug |
|
1790 | 1813 | report by Oliver Sander <osander-AT-gmx.de>. |
|
1791 | 1814 | |
|
1792 | 1815 | * IPython/FakeModule.py (FakeModule.__repr__): this method was |
|
1793 | 1816 | missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>. |
|
1794 | 1817 | |
|
1795 | 1818 | 2003-09-09 Fernando Perez <fperez@colorado.edu> |
|
1796 | 1819 | |
|
1797 | 1820 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1798 | 1821 | unpacking a list whith a callable as first element would |
|
1799 | 1822 | mistakenly trigger autocalling. Thanks to a bug report by Jeffery |
|
1800 | 1823 | Collins. |
|
1801 | 1824 | |
|
1802 | 1825 | 2003-08-25 *** Released version 0.5.0 |
|
1803 | 1826 | |
|
1804 | 1827 | 2003-08-22 Fernando Perez <fperez@colorado.edu> |
|
1805 | 1828 | |
|
1806 | 1829 | * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of |
|
1807 | 1830 | improperly defined user exceptions. Thanks to feedback from Mark |
|
1808 | 1831 | Russell <mrussell-AT-verio.net>. |
|
1809 | 1832 | |
|
1810 | 1833 | 2003-08-20 Fernando Perez <fperez@colorado.edu> |
|
1811 | 1834 | |
|
1812 | 1835 | * IPython/OInspect.py (Inspector.pinfo): changed String Form |
|
1813 | 1836 | printing so that it would print multi-line string forms starting |
|
1814 | 1837 | with a new line. This way the formatting is better respected for |
|
1815 | 1838 | objects which work hard to make nice string forms. |
|
1816 | 1839 | |
|
1817 | 1840 | * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where |
|
1818 | 1841 | autocall would overtake data access for objects with both |
|
1819 | 1842 | __getitem__ and __call__. |
|
1820 | 1843 | |
|
1821 | 1844 | 2003-08-19 *** Released version 0.5.0-rc1 |
|
1822 | 1845 | |
|
1823 | 1846 | 2003-08-19 Fernando Perez <fperez@colorado.edu> |
|
1824 | 1847 | |
|
1825 | 1848 | * IPython/deep_reload.py (load_tail): single tiny change here |
|
1826 | 1849 | seems to fix the long-standing bug of dreload() failing to work |
|
1827 | 1850 | for dotted names. But this module is pretty tricky, so I may have |
|
1828 | 1851 | missed some subtlety. Needs more testing!. |
|
1829 | 1852 | |
|
1830 | 1853 | * IPython/ultraTB.py (VerboseTB.linereader): harden against user |
|
1831 | 1854 | exceptions which have badly implemented __str__ methods. |
|
1832 | 1855 | (VerboseTB.text): harden against inspect.getinnerframes crashing, |
|
1833 | 1856 | which I've been getting reports about from Python 2.3 users. I |
|
1834 | 1857 | wish I had a simple test case to reproduce the problem, so I could |
|
1835 | 1858 | either write a cleaner workaround or file a bug report if |
|
1836 | 1859 | necessary. |
|
1837 | 1860 | |
|
1838 | 1861 | * IPython/Magic.py (Magic.magic_edit): fixed bug where after |
|
1839 | 1862 | making a class 'foo', file 'foo.py' couldn't be edited. Thanks to |
|
1840 | 1863 | a bug report by Tjabo Kloppenburg. |
|
1841 | 1864 | |
|
1842 | 1865 | * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb |
|
1843 | 1866 | crashes. Wrapped the pdb call in a blanket try/except, since pdb |
|
1844 | 1867 | seems rather unstable. Thanks to a bug report by Tjabo |
|
1845 | 1868 | Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>. |
|
1846 | 1869 | |
|
1847 | 1870 | * IPython/Release.py (version): release 0.5.0-rc1. I want to put |
|
1848 | 1871 | this out soon because of the critical fixes in the inner loop for |
|
1849 | 1872 | generators. |
|
1850 | 1873 | |
|
1851 | 1874 | * IPython/Magic.py (Magic.getargspec): removed. This (and |
|
1852 | 1875 | _get_def) have been obsoleted by OInspect for a long time, I |
|
1853 | 1876 | hadn't noticed that they were dead code. |
|
1854 | 1877 | (Magic._ofind): restored _ofind functionality for a few literals |
|
1855 | 1878 | (those in ["''",'""','[]','{}','()']). But it won't work anymore |
|
1856 | 1879 | for things like "hello".capitalize?, since that would require a |
|
1857 | 1880 | potentially dangerous eval() again. |
|
1858 | 1881 | |
|
1859 | 1882 | * IPython/iplib.py (InteractiveShell._prefilter): reorganized the |
|
1860 | 1883 | logic a bit more to clean up the escapes handling and minimize the |
|
1861 | 1884 | use of _ofind to only necessary cases. The interactive 'feel' of |
|
1862 | 1885 | IPython should have improved quite a bit with the changes in |
|
1863 | 1886 | _prefilter and _ofind (besides being far safer than before). |
|
1864 | 1887 | |
|
1865 | 1888 | * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather |
|
1866 | 1889 | obscure, never reported). Edit would fail to find the object to |
|
1867 | 1890 | edit under some circumstances. |
|
1868 | 1891 | (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls |
|
1869 | 1892 | which were causing double-calling of generators. Those eval calls |
|
1870 | 1893 | were _very_ dangerous, since code with side effects could be |
|
1871 | 1894 | triggered. As they say, 'eval is evil'... These were the |
|
1872 | 1895 | nastiest evals in IPython. Besides, _ofind is now far simpler, |
|
1873 | 1896 | and it should also be quite a bit faster. Its use of inspect is |
|
1874 | 1897 | also safer, so perhaps some of the inspect-related crashes I've |
|
1875 | 1898 | seen lately with Python 2.3 might be taken care of. That will |
|
1876 | 1899 | need more testing. |
|
1877 | 1900 | |
|
1878 | 1901 | 2003-08-17 Fernando Perez <fperez@colorado.edu> |
|
1879 | 1902 | |
|
1880 | 1903 | * IPython/iplib.py (InteractiveShell._prefilter): significant |
|
1881 | 1904 | simplifications to the logic for handling user escapes. Faster |
|
1882 | 1905 | and simpler code. |
|
1883 | 1906 | |
|
1884 | 1907 | 2003-08-14 Fernando Perez <fperez@colorado.edu> |
|
1885 | 1908 | |
|
1886 | 1909 | * IPython/numutils.py (sum_flat): rewrote to be non-recursive. |
|
1887 | 1910 | Now it requires O(N) storage (N=size(a)) for non-contiguous input, |
|
1888 | 1911 | but it should be quite a bit faster. And the recursive version |
|
1889 | 1912 | generated O(log N) intermediate storage for all rank>1 arrays, |
|
1890 | 1913 | even if they were contiguous. |
|
1891 | 1914 | (l1norm): Added this function. |
|
1892 | 1915 | (norm): Added this function for arbitrary norms (including |
|
1893 | 1916 | l-infinity). l1 and l2 are still special cases for convenience |
|
1894 | 1917 | and speed. |
|
1895 | 1918 | |
|
1896 | 1919 | 2003-08-03 Fernando Perez <fperez@colorado.edu> |
|
1897 | 1920 | |
|
1898 | 1921 | * IPython/Magic.py (Magic.magic_edit): Removed all remaining string |
|
1899 | 1922 | exceptions, which now raise PendingDeprecationWarnings in Python |
|
1900 | 1923 | 2.3. There were some in Magic and some in Gnuplot2. |
|
1901 | 1924 | |
|
1902 | 1925 | 2003-06-30 Fernando Perez <fperez@colorado.edu> |
|
1903 | 1926 | |
|
1904 | 1927 | * IPython/genutils.py (page): modified to call curses only for |
|
1905 | 1928 | terminals where TERM=='xterm'. After problems under many other |
|
1906 | 1929 | terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>. |
|
1907 | 1930 | |
|
1908 | 1931 | * IPython/iplib.py (complete): removed spurious 'print "IE"' which |
|
1909 | 1932 | would be triggered when readline was absent. This was just an old |
|
1910 | 1933 | debugging statement I'd forgotten to take out. |
|
1911 | 1934 | |
|
1912 | 1935 | 2003-06-20 Fernando Perez <fperez@colorado.edu> |
|
1913 | 1936 | |
|
1914 | 1937 | * IPython/genutils.py (clock): modified to return only user time |
|
1915 | 1938 | (not counting system time), after a discussion on scipy. While |
|
1916 | 1939 | system time may be a useful quantity occasionally, it may much |
|
1917 | 1940 | more easily be skewed by occasional swapping or other similar |
|
1918 | 1941 | activity. |
|
1919 | 1942 | |
|
1920 | 1943 | 2003-06-05 Fernando Perez <fperez@colorado.edu> |
|
1921 | 1944 | |
|
1922 | 1945 | * IPython/numutils.py (identity): new function, for building |
|
1923 | 1946 | arbitrary rank Kronecker deltas (mostly backwards compatible with |
|
1924 | 1947 | Numeric.identity) |
|
1925 | 1948 | |
|
1926 | 1949 | 2003-06-03 Fernando Perez <fperez@colorado.edu> |
|
1927 | 1950 | |
|
1928 | 1951 | * IPython/iplib.py (InteractiveShell.handle_magic): protect |
|
1929 | 1952 | arguments passed to magics with spaces, to allow trailing '\' to |
|
1930 | 1953 | work normally (mainly for Windows users). |
|
1931 | 1954 | |
|
1932 | 1955 | 2003-05-29 Fernando Perez <fperez@colorado.edu> |
|
1933 | 1956 | |
|
1934 | 1957 | * IPython/ipmaker.py (make_IPython): Load site._Helper() as help |
|
1935 | 1958 | instead of pydoc.help. This fixes a bizarre behavior where |
|
1936 | 1959 | printing '%s' % locals() would trigger the help system. Now |
|
1937 | 1960 | ipython behaves like normal python does. |
|
1938 | 1961 | |
|
1939 | 1962 | Note that if one does 'from pydoc import help', the bizarre |
|
1940 | 1963 | behavior returns, but this will also happen in normal python, so |
|
1941 | 1964 | it's not an ipython bug anymore (it has to do with how pydoc.help |
|
1942 | 1965 | is implemented). |
|
1943 | 1966 | |
|
1944 | 1967 | 2003-05-22 Fernando Perez <fperez@colorado.edu> |
|
1945 | 1968 | |
|
1946 | 1969 | * IPython/FlexCompleter.py (Completer.attr_matches): fixed to |
|
1947 | 1970 | return [] instead of None when nothing matches, also match to end |
|
1948 | 1971 | of line. Patch by Gary Bishop. |
|
1949 | 1972 | |
|
1950 | 1973 | * IPython/ipmaker.py (make_IPython): Added same sys.excepthook |
|
1951 | 1974 | protection as before, for files passed on the command line. This |
|
1952 | 1975 | prevents the CrashHandler from kicking in if user files call into |
|
1953 | 1976 | sys.excepthook (such as PyQt and WxWindows have a nasty habit of |
|
1954 | 1977 | doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr> |
|
1955 | 1978 | |
|
1956 | 1979 | 2003-05-20 *** Released version 0.4.0 |
|
1957 | 1980 | |
|
1958 | 1981 | 2003-05-20 Fernando Perez <fperez@colorado.edu> |
|
1959 | 1982 | |
|
1960 | 1983 | * setup.py: added support for manpages. It's a bit hackish b/c of |
|
1961 | 1984 | a bug in the way the bdist_rpm distutils target handles gzipped |
|
1962 | 1985 | manpages, but it works. After a patch by Jack. |
|
1963 | 1986 | |
|
1964 | 1987 | 2003-05-19 Fernando Perez <fperez@colorado.edu> |
|
1965 | 1988 | |
|
1966 | 1989 | * IPython/numutils.py: added a mockup of the kinds module, since |
|
1967 | 1990 | it was recently removed from Numeric. This way, numutils will |
|
1968 | 1991 | work for all users even if they are missing kinds. |
|
1969 | 1992 | |
|
1970 | 1993 | * IPython/Magic.py (Magic._ofind): Harden against an inspect |
|
1971 | 1994 | failure, which can occur with SWIG-wrapped extensions. After a |
|
1972 | 1995 | crash report from Prabhu. |
|
1973 | 1996 | |
|
1974 | 1997 | 2003-05-16 Fernando Perez <fperez@colorado.edu> |
|
1975 | 1998 | |
|
1976 | 1999 | * IPython/iplib.py (InteractiveShell.excepthook): New method to |
|
1977 | 2000 | protect ipython from user code which may call directly |
|
1978 | 2001 | sys.excepthook (this looks like an ipython crash to the user, even |
|
1979 | 2002 | when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
1980 | 2003 | This is especially important to help users of WxWindows, but may |
|
1981 | 2004 | also be useful in other cases. |
|
1982 | 2005 | |
|
1983 | 2006 | * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow |
|
1984 | 2007 | an optional tb_offset to be specified, and to preserve exception |
|
1985 | 2008 | info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
1986 | 2009 | |
|
1987 | 2010 | * ipython.1 (Default): Thanks to Jack's work, we now have manpages! |
|
1988 | 2011 | |
|
1989 | 2012 | 2003-05-15 Fernando Perez <fperez@colorado.edu> |
|
1990 | 2013 | |
|
1991 | 2014 | * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when |
|
1992 | 2015 | installing for a new user under Windows. |
|
1993 | 2016 | |
|
1994 | 2017 | 2003-05-12 Fernando Perez <fperez@colorado.edu> |
|
1995 | 2018 | |
|
1996 | 2019 | * IPython/iplib.py (InteractiveShell.handle_emacs): New line |
|
1997 | 2020 | handler for Emacs comint-based lines. Currently it doesn't do |
|
1998 | 2021 | much (but importantly, it doesn't update the history cache). In |
|
1999 | 2022 | the future it may be expanded if Alex needs more functionality |
|
2000 | 2023 | there. |
|
2001 | 2024 | |
|
2002 | 2025 | * IPython/CrashHandler.py (CrashHandler.__call__): Added platform |
|
2003 | 2026 | info to crash reports. |
|
2004 | 2027 | |
|
2005 | 2028 | * IPython/iplib.py (InteractiveShell.mainloop): Added -c option, |
|
2006 | 2029 | just like Python's -c. Also fixed crash with invalid -color |
|
2007 | 2030 | option value at startup. Thanks to Will French |
|
2008 | 2031 | <wfrench-AT-bestweb.net> for the bug report. |
|
2009 | 2032 | |
|
2010 | 2033 | 2003-05-09 Fernando Perez <fperez@colorado.edu> |
|
2011 | 2034 | |
|
2012 | 2035 | * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString |
|
2013 | 2036 | to EvalDict (it's a mapping, after all) and simplified its code |
|
2014 | 2037 | quite a bit, after a nice discussion on c.l.py where Gustavo |
|
2015 | 2038 | CΓ³rdova <gcordova-AT-sismex.com> suggested the new version. |
|
2016 | 2039 | |
|
2017 | 2040 | 2003-04-30 Fernando Perez <fperez@colorado.edu> |
|
2018 | 2041 | |
|
2019 | 2042 | * IPython/genutils.py (timings_out): modified it to reduce its |
|
2020 | 2043 | overhead in the common reps==1 case. |
|
2021 | 2044 | |
|
2022 | 2045 | 2003-04-29 Fernando Perez <fperez@colorado.edu> |
|
2023 | 2046 | |
|
2024 | 2047 | * IPython/genutils.py (timings_out): Modified to use the resource |
|
2025 | 2048 | module, which avoids the wraparound problems of time.clock(). |
|
2026 | 2049 | |
|
2027 | 2050 | 2003-04-17 *** Released version 0.2.15pre4 |
|
2028 | 2051 | |
|
2029 | 2052 | 2003-04-17 Fernando Perez <fperez@colorado.edu> |
|
2030 | 2053 | |
|
2031 | 2054 | * setup.py (scriptfiles): Split windows-specific stuff over to a |
|
2032 | 2055 | separate file, in an attempt to have a Windows GUI installer. |
|
2033 | 2056 | That didn't work, but part of the groundwork is done. |
|
2034 | 2057 | |
|
2035 | 2058 | * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for |
|
2036 | 2059 | indent/unindent with 4 spaces. Particularly useful in combination |
|
2037 | 2060 | with the new auto-indent option. |
|
2038 | 2061 | |
|
2039 | 2062 | 2003-04-16 Fernando Perez <fperez@colorado.edu> |
|
2040 | 2063 | |
|
2041 | 2064 | * IPython/Magic.py: various replacements of self.rc for |
|
2042 | 2065 | self.shell.rc. A lot more remains to be done to fully disentangle |
|
2043 | 2066 | this class from the main Shell class. |
|
2044 | 2067 | |
|
2045 | 2068 | * IPython/GnuplotRuntime.py: added checks for mouse support so |
|
2046 | 2069 | that we don't try to enable it if the current gnuplot doesn't |
|
2047 | 2070 | really support it. Also added checks so that we don't try to |
|
2048 | 2071 | enable persist under Windows (where Gnuplot doesn't recognize the |
|
2049 | 2072 | option). |
|
2050 | 2073 | |
|
2051 | 2074 | * IPython/iplib.py (InteractiveShell.interact): Added optional |
|
2052 | 2075 | auto-indenting code, after a patch by King C. Shu |
|
2053 | 2076 | <kingshu-AT-myrealbox.com>. It's off by default because it doesn't |
|
2054 | 2077 | get along well with pasting indented code. If I ever figure out |
|
2055 | 2078 | how to make that part go well, it will become on by default. |
|
2056 | 2079 | |
|
2057 | 2080 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would |
|
2058 | 2081 | crash ipython if there was an unmatched '%' in the user's prompt |
|
2059 | 2082 | string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2060 | 2083 | |
|
2061 | 2084 | * IPython/iplib.py (InteractiveShell.interact): removed the |
|
2062 | 2085 | ability to ask the user whether he wants to crash or not at the |
|
2063 | 2086 | 'last line' exception handler. Calling functions at that point |
|
2064 | 2087 | changes the stack, and the error reports would have incorrect |
|
2065 | 2088 | tracebacks. |
|
2066 | 2089 | |
|
2067 | 2090 | * IPython/Magic.py (Magic.magic_page): Added new @page magic, to |
|
2068 | 2091 | pass through a peger a pretty-printed form of any object. After a |
|
2069 | 2092 | contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr> |
|
2070 | 2093 | |
|
2071 | 2094 | 2003-04-14 Fernando Perez <fperez@colorado.edu> |
|
2072 | 2095 | |
|
2073 | 2096 | * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where |
|
2074 | 2097 | all files in ~ would be modified at first install (instead of |
|
2075 | 2098 | ~/.ipython). This could be potentially disastrous, as the |
|
2076 | 2099 | modification (make line-endings native) could damage binary files. |
|
2077 | 2100 | |
|
2078 | 2101 | 2003-04-10 Fernando Perez <fperez@colorado.edu> |
|
2079 | 2102 | |
|
2080 | 2103 | * IPython/iplib.py (InteractiveShell.handle_help): Modified to |
|
2081 | 2104 | handle only lines which are invalid python. This now means that |
|
2082 | 2105 | lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins |
|
2083 | 2106 | for the bug report. |
|
2084 | 2107 | |
|
2085 | 2108 | 2003-04-01 Fernando Perez <fperez@colorado.edu> |
|
2086 | 2109 | |
|
2087 | 2110 | * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug |
|
2088 | 2111 | where failing to set sys.last_traceback would crash pdb.pm(). |
|
2089 | 2112 | Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug |
|
2090 | 2113 | report. |
|
2091 | 2114 | |
|
2092 | 2115 | 2003-03-25 Fernando Perez <fperez@colorado.edu> |
|
2093 | 2116 | |
|
2094 | 2117 | * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler |
|
2095 | 2118 | before printing it (it had a lot of spurious blank lines at the |
|
2096 | 2119 | end). |
|
2097 | 2120 | |
|
2098 | 2121 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr |
|
2099 | 2122 | output would be sent 21 times! Obviously people don't use this |
|
2100 | 2123 | too often, or I would have heard about it. |
|
2101 | 2124 | |
|
2102 | 2125 | 2003-03-24 Fernando Perez <fperez@colorado.edu> |
|
2103 | 2126 | |
|
2104 | 2127 | * setup.py (scriptfiles): renamed the data_files parameter from |
|
2105 | 2128 | 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink |
|
2106 | 2129 | for the patch. |
|
2107 | 2130 | |
|
2108 | 2131 | 2003-03-20 Fernando Perez <fperez@colorado.edu> |
|
2109 | 2132 | |
|
2110 | 2133 | * IPython/genutils.py (error): added error() and fatal() |
|
2111 | 2134 | functions. |
|
2112 | 2135 | |
|
2113 | 2136 | 2003-03-18 *** Released version 0.2.15pre3 |
|
2114 | 2137 | |
|
2115 | 2138 | 2003-03-18 Fernando Perez <fperez@colorado.edu> |
|
2116 | 2139 | |
|
2117 | 2140 | * setupext/install_data_ext.py |
|
2118 | 2141 | (install_data_ext.initialize_options): Class contributed by Jack |
|
2119 | 2142 | Moffit for fixing the old distutils hack. He is sending this to |
|
2120 | 2143 | the distutils folks so in the future we may not need it as a |
|
2121 | 2144 | private fix. |
|
2122 | 2145 | |
|
2123 | 2146 | * MANIFEST.in: Extensive reorganization, based on Jack Moffit's |
|
2124 | 2147 | changes for Debian packaging. See his patch for full details. |
|
2125 | 2148 | The old distutils hack of making the ipythonrc* files carry a |
|
2126 | 2149 | bogus .py extension is gone, at last. Examples were moved to a |
|
2127 | 2150 | separate subdir under doc/, and the separate executable scripts |
|
2128 | 2151 | now live in their own directory. Overall a great cleanup. The |
|
2129 | 2152 | manual was updated to use the new files, and setup.py has been |
|
2130 | 2153 | fixed for this setup. |
|
2131 | 2154 | |
|
2132 | 2155 | * IPython/PyColorize.py (Parser.usage): made non-executable and |
|
2133 | 2156 | created a pycolor wrapper around it to be included as a script. |
|
2134 | 2157 | |
|
2135 | 2158 | 2003-03-12 *** Released version 0.2.15pre2 |
|
2136 | 2159 | |
|
2137 | 2160 | 2003-03-12 Fernando Perez <fperez@colorado.edu> |
|
2138 | 2161 | |
|
2139 | 2162 | * IPython/ColorANSI.py (make_color_table): Finally fixed the |
|
2140 | 2163 | long-standing problem with garbage characters in some terminals. |
|
2141 | 2164 | The issue was really that the \001 and \002 escapes must _only_ be |
|
2142 | 2165 | passed to input prompts (which call readline), but _never_ to |
|
2143 | 2166 | normal text to be printed on screen. I changed ColorANSI to have |
|
2144 | 2167 | two classes: TermColors and InputTermColors, each with the |
|
2145 | 2168 | appropriate escapes for input prompts or normal text. The code in |
|
2146 | 2169 | Prompts.py got slightly more complicated, but this very old and |
|
2147 | 2170 | annoying bug is finally fixed. |
|
2148 | 2171 | |
|
2149 | 2172 | All the credit for nailing down the real origin of this problem |
|
2150 | 2173 | and the correct solution goes to Jack Moffit <jack-AT-xiph.org>. |
|
2151 | 2174 | *Many* thanks to him for spending quite a bit of effort on this. |
|
2152 | 2175 | |
|
2153 | 2176 | 2003-03-05 *** Released version 0.2.15pre1 |
|
2154 | 2177 | |
|
2155 | 2178 | 2003-03-03 Fernando Perez <fperez@colorado.edu> |
|
2156 | 2179 | |
|
2157 | 2180 | * IPython/FakeModule.py: Moved the former _FakeModule to a |
|
2158 | 2181 | separate file, because it's also needed by Magic (to fix a similar |
|
2159 | 2182 | pickle-related issue in @run). |
|
2160 | 2183 | |
|
2161 | 2184 | 2003-03-02 Fernando Perez <fperez@colorado.edu> |
|
2162 | 2185 | |
|
2163 | 2186 | * IPython/Magic.py (Magic.magic_autocall): new magic to control |
|
2164 | 2187 | the autocall option at runtime. |
|
2165 | 2188 | (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns |
|
2166 | 2189 | across Magic.py to start separating Magic from InteractiveShell. |
|
2167 | 2190 | (Magic._ofind): Fixed to return proper namespace for dotted |
|
2168 | 2191 | names. Before, a dotted name would always return 'not currently |
|
2169 | 2192 | defined', because it would find the 'parent'. s.x would be found, |
|
2170 | 2193 | but since 'x' isn't defined by itself, it would get confused. |
|
2171 | 2194 | (Magic.magic_run): Fixed pickling problems reported by Ralf |
|
2172 | 2195 | Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to |
|
2173 | 2196 | that I'd used when Mike Heeter reported similar issues at the |
|
2174 | 2197 | top-level, but now for @run. It boils down to injecting the |
|
2175 | 2198 | namespace where code is being executed with something that looks |
|
2176 | 2199 | enough like a module to fool pickle.dump(). Since a pickle stores |
|
2177 | 2200 | a named reference to the importing module, we need this for |
|
2178 | 2201 | pickles to save something sensible. |
|
2179 | 2202 | |
|
2180 | 2203 | * IPython/ipmaker.py (make_IPython): added an autocall option. |
|
2181 | 2204 | |
|
2182 | 2205 | * IPython/iplib.py (InteractiveShell._prefilter): reordered all of |
|
2183 | 2206 | the auto-eval code. Now autocalling is an option, and the code is |
|
2184 | 2207 | also vastly safer. There is no more eval() involved at all. |
|
2185 | 2208 | |
|
2186 | 2209 | 2003-03-01 Fernando Perez <fperez@colorado.edu> |
|
2187 | 2210 | |
|
2188 | 2211 | * IPython/Magic.py (Magic._ofind): Changed interface to return a |
|
2189 | 2212 | dict with named keys instead of a tuple. |
|
2190 | 2213 | |
|
2191 | 2214 | * IPython: Started using CVS for IPython as of 0.2.15pre1. |
|
2192 | 2215 | |
|
2193 | 2216 | * setup.py (make_shortcut): Fixed message about directories |
|
2194 | 2217 | created during Windows installation (the directories were ok, just |
|
2195 | 2218 | the printed message was misleading). Thanks to Chris Liechti |
|
2196 | 2219 | <cliechti-AT-gmx.net> for the heads up. |
|
2197 | 2220 | |
|
2198 | 2221 | 2003-02-21 Fernando Perez <fperez@colorado.edu> |
|
2199 | 2222 | |
|
2200 | 2223 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching |
|
2201 | 2224 | of ValueError exception when checking for auto-execution. This |
|
2202 | 2225 | one is raised by things like Numeric arrays arr.flat when the |
|
2203 | 2226 | array is non-contiguous. |
|
2204 | 2227 | |
|
2205 | 2228 | 2003-01-31 Fernando Perez <fperez@colorado.edu> |
|
2206 | 2229 | |
|
2207 | 2230 | * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would |
|
2208 | 2231 | not return any value at all (even though the command would get |
|
2209 | 2232 | executed). |
|
2210 | 2233 | (xsys): Flush stdout right after printing the command to ensure |
|
2211 | 2234 | proper ordering of commands and command output in the total |
|
2212 | 2235 | output. |
|
2213 | 2236 | (SystemExec/xsys/bq): Switched the names of xsys/bq and |
|
2214 | 2237 | system/getoutput as defaults. The old ones are kept for |
|
2215 | 2238 | compatibility reasons, so no code which uses this library needs |
|
2216 | 2239 | changing. |
|
2217 | 2240 | |
|
2218 | 2241 | 2003-01-27 *** Released version 0.2.14 |
|
2219 | 2242 | |
|
2220 | 2243 | 2003-01-25 Fernando Perez <fperez@colorado.edu> |
|
2221 | 2244 | |
|
2222 | 2245 | * IPython/Magic.py (Magic.magic_edit): Fixed problem where |
|
2223 | 2246 | functions defined in previous edit sessions could not be re-edited |
|
2224 | 2247 | (because the temp files were immediately removed). Now temp files |
|
2225 | 2248 | are removed only at IPython's exit. |
|
2226 | 2249 | (Magic.magic_run): Improved @run to perform shell-like expansions |
|
2227 | 2250 | on its arguments (~users and $VARS). With this, @run becomes more |
|
2228 | 2251 | like a normal command-line. |
|
2229 | 2252 | |
|
2230 | 2253 | * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small |
|
2231 | 2254 | bugs related to embedding and cleaned up that code. A fairly |
|
2232 | 2255 | important one was the impossibility to access the global namespace |
|
2233 | 2256 | through the embedded IPython (only local variables were visible). |
|
2234 | 2257 | |
|
2235 | 2258 | 2003-01-14 Fernando Perez <fperez@colorado.edu> |
|
2236 | 2259 | |
|
2237 | 2260 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed |
|
2238 | 2261 | auto-calling to be a bit more conservative. Now it doesn't get |
|
2239 | 2262 | triggered if any of '!=()<>' are in the rest of the input line, to |
|
2240 | 2263 | allow comparing callables. Thanks to Alex for the heads up. |
|
2241 | 2264 | |
|
2242 | 2265 | 2003-01-07 Fernando Perez <fperez@colorado.edu> |
|
2243 | 2266 | |
|
2244 | 2267 | * IPython/genutils.py (page): fixed estimation of the number of |
|
2245 | 2268 | lines in a string to be paged to simply count newlines. This |
|
2246 | 2269 | prevents over-guessing due to embedded escape sequences. A better |
|
2247 | 2270 | long-term solution would involve stripping out the control chars |
|
2248 | 2271 | for the count, but it's potentially so expensive I just don't |
|
2249 | 2272 | think it's worth doing. |
|
2250 | 2273 | |
|
2251 | 2274 | 2002-12-19 *** Released version 0.2.14pre50 |
|
2252 | 2275 | |
|
2253 | 2276 | 2002-12-19 Fernando Perez <fperez@colorado.edu> |
|
2254 | 2277 | |
|
2255 | 2278 | * tools/release (version): Changed release scripts to inform |
|
2256 | 2279 | Andrea and build a NEWS file with a list of recent changes. |
|
2257 | 2280 | |
|
2258 | 2281 | * IPython/ColorANSI.py (__all__): changed terminal detection |
|
2259 | 2282 | code. Seems to work better for xterms without breaking |
|
2260 | 2283 | konsole. Will need more testing to determine if WinXP and Mac OSX |
|
2261 | 2284 | also work ok. |
|
2262 | 2285 | |
|
2263 | 2286 | 2002-12-18 *** Released version 0.2.14pre49 |
|
2264 | 2287 | |
|
2265 | 2288 | 2002-12-18 Fernando Perez <fperez@colorado.edu> |
|
2266 | 2289 | |
|
2267 | 2290 | * Docs: added new info about Mac OSX, from Andrea. |
|
2268 | 2291 | |
|
2269 | 2292 | * IPython/Gnuplot2.py (String): Added a String PlotItem class to |
|
2270 | 2293 | allow direct plotting of python strings whose format is the same |
|
2271 | 2294 | of gnuplot data files. |
|
2272 | 2295 | |
|
2273 | 2296 | 2002-12-16 Fernando Perez <fperez@colorado.edu> |
|
2274 | 2297 | |
|
2275 | 2298 | * IPython/iplib.py (InteractiveShell.interact): fixed default (y) |
|
2276 | 2299 | value of exit question to be acknowledged. |
|
2277 | 2300 | |
|
2278 | 2301 | 2002-12-03 Fernando Perez <fperez@colorado.edu> |
|
2279 | 2302 | |
|
2280 | 2303 | * IPython/ipmaker.py: removed generators, which had been added |
|
2281 | 2304 | by mistake in an earlier debugging run. This was causing trouble |
|
2282 | 2305 | to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu> |
|
2283 | 2306 | for pointing this out. |
|
2284 | 2307 | |
|
2285 | 2308 | 2002-11-17 Fernando Perez <fperez@colorado.edu> |
|
2286 | 2309 | |
|
2287 | 2310 | * Manual: updated the Gnuplot section. |
|
2288 | 2311 | |
|
2289 | 2312 | * IPython/GnuplotRuntime.py: refactored a lot all this code, with |
|
2290 | 2313 | a much better split of what goes in Runtime and what goes in |
|
2291 | 2314 | Interactive. |
|
2292 | 2315 | |
|
2293 | 2316 | * IPython/ipmaker.py: fixed bug where import_fail_info wasn't |
|
2294 | 2317 | being imported from iplib. |
|
2295 | 2318 | |
|
2296 | 2319 | * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc |
|
2297 | 2320 | for command-passing. Now the global Gnuplot instance is called |
|
2298 | 2321 | 'gp' instead of 'g', which was really a far too fragile and |
|
2299 | 2322 | common name. |
|
2300 | 2323 | |
|
2301 | 2324 | * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken |
|
2302 | 2325 | bounding boxes generated by Gnuplot for square plots. |
|
2303 | 2326 | |
|
2304 | 2327 | * IPython/genutils.py (popkey): new function added. I should |
|
2305 | 2328 | suggest this on c.l.py as a dict method, it seems useful. |
|
2306 | 2329 | |
|
2307 | 2330 | * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot |
|
2308 | 2331 | to transparently handle PostScript generation. MUCH better than |
|
2309 | 2332 | the previous plot_eps/replot_eps (which I removed now). The code |
|
2310 | 2333 | is also fairly clean and well documented now (including |
|
2311 | 2334 | docstrings). |
|
2312 | 2335 | |
|
2313 | 2336 | 2002-11-13 Fernando Perez <fperez@colorado.edu> |
|
2314 | 2337 | |
|
2315 | 2338 | * IPython/Magic.py (Magic.magic_edit): fixed docstring |
|
2316 | 2339 | (inconsistent with options). |
|
2317 | 2340 | |
|
2318 | 2341 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been |
|
2319 | 2342 | manually disabled, I don't know why. Fixed it. |
|
2320 | 2343 | (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly |
|
2321 | 2344 | eps output. |
|
2322 | 2345 | |
|
2323 | 2346 | 2002-11-12 Fernando Perez <fperez@colorado.edu> |
|
2324 | 2347 | |
|
2325 | 2348 | * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they |
|
2326 | 2349 | don't propagate up to caller. Fixes crash reported by François |
|
2327 | 2350 | Pinard. |
|
2328 | 2351 | |
|
2329 | 2352 | 2002-11-09 Fernando Perez <fperez@colorado.edu> |
|
2330 | 2353 | |
|
2331 | 2354 | * IPython/ipmaker.py (make_IPython): fixed problem with writing |
|
2332 | 2355 | history file for new users. |
|
2333 | 2356 | (make_IPython): fixed bug where initial install would leave the |
|
2334 | 2357 | user running in the .ipython dir. |
|
2335 | 2358 | (make_IPython): fixed bug where config dir .ipython would be |
|
2336 | 2359 | created regardless of the given -ipythondir option. Thanks to Cory |
|
2337 | 2360 | Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report. |
|
2338 | 2361 | |
|
2339 | 2362 | * IPython/genutils.py (ask_yes_no): new function for asking yes/no |
|
2340 | 2363 | type confirmations. Will need to use it in all of IPython's code |
|
2341 | 2364 | consistently. |
|
2342 | 2365 | |
|
2343 | 2366 | * IPython/CrashHandler.py (CrashHandler.__call__): changed the |
|
2344 | 2367 | context to print 31 lines instead of the default 5. This will make |
|
2345 | 2368 | the crash reports extremely detailed in case the problem is in |
|
2346 | 2369 | libraries I don't have access to. |
|
2347 | 2370 | |
|
2348 | 2371 | * IPython/iplib.py (InteractiveShell.interact): changed the 'last |
|
2349 | 2372 | line of defense' code to still crash, but giving users fair |
|
2350 | 2373 | warning. I don't want internal errors to go unreported: if there's |
|
2351 | 2374 | an internal problem, IPython should crash and generate a full |
|
2352 | 2375 | report. |
|
2353 | 2376 | |
|
2354 | 2377 | 2002-11-08 Fernando Perez <fperez@colorado.edu> |
|
2355 | 2378 | |
|
2356 | 2379 | * IPython/iplib.py (InteractiveShell.interact): added code to trap |
|
2357 | 2380 | otherwise uncaught exceptions which can appear if people set |
|
2358 | 2381 | sys.stdout to something badly broken. Thanks to a crash report |
|
2359 | 2382 | from henni-AT-mail.brainbot.com. |
|
2360 | 2383 | |
|
2361 | 2384 | 2002-11-04 Fernando Perez <fperez@colorado.edu> |
|
2362 | 2385 | |
|
2363 | 2386 | * IPython/iplib.py (InteractiveShell.interact): added |
|
2364 | 2387 | __IPYTHON__active to the builtins. It's a flag which goes on when |
|
2365 | 2388 | the interaction starts and goes off again when it stops. This |
|
2366 | 2389 | allows embedding code to detect being inside IPython. Before this |
|
2367 | 2390 | was done via __IPYTHON__, but that only shows that an IPython |
|
2368 | 2391 | instance has been created. |
|
2369 | 2392 | |
|
2370 | 2393 | * IPython/Magic.py (Magic.magic_env): I realized that in a |
|
2371 | 2394 | UserDict, instance.data holds the data as a normal dict. So I |
|
2372 | 2395 | modified @env to return os.environ.data instead of rebuilding a |
|
2373 | 2396 | dict by hand. |
|
2374 | 2397 | |
|
2375 | 2398 | 2002-11-02 Fernando Perez <fperez@colorado.edu> |
|
2376 | 2399 | |
|
2377 | 2400 | * IPython/genutils.py (warn): changed so that level 1 prints no |
|
2378 | 2401 | header. Level 2 is now the default (with 'WARNING' header, as |
|
2379 | 2402 | before). I think I tracked all places where changes were needed in |
|
2380 | 2403 | IPython, but outside code using the old level numbering may have |
|
2381 | 2404 | broken. |
|
2382 | 2405 | |
|
2383 | 2406 | * IPython/iplib.py (InteractiveShell.runcode): added this to |
|
2384 | 2407 | handle the tracebacks in SystemExit traps correctly. The previous |
|
2385 | 2408 | code (through interact) was printing more of the stack than |
|
2386 | 2409 | necessary, showing IPython internal code to the user. |
|
2387 | 2410 | |
|
2388 | 2411 | * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by |
|
2389 | 2412 | default. Now that the default at the confirmation prompt is yes, |
|
2390 | 2413 | it's not so intrusive. François' argument that ipython sessions |
|
2391 | 2414 | tend to be complex enough not to lose them from an accidental C-d, |
|
2392 | 2415 | is a valid one. |
|
2393 | 2416 | |
|
2394 | 2417 | * IPython/iplib.py (InteractiveShell.interact): added a |
|
2395 | 2418 | showtraceback() call to the SystemExit trap, and modified the exit |
|
2396 | 2419 | confirmation to have yes as the default. |
|
2397 | 2420 | |
|
2398 | 2421 | * IPython/UserConfig/ipythonrc.py: removed 'session' option from |
|
2399 | 2422 | this file. It's been gone from the code for a long time, this was |
|
2400 | 2423 | simply leftover junk. |
|
2401 | 2424 | |
|
2402 | 2425 | 2002-11-01 Fernando Perez <fperez@colorado.edu> |
|
2403 | 2426 | |
|
2404 | 2427 | * IPython/UserConfig/ipythonrc.py: new confirm_exit option |
|
2405 | 2428 | added. If set, IPython now traps EOF and asks for |
|
2406 | 2429 | confirmation. After a request by François Pinard. |
|
2407 | 2430 | |
|
2408 | 2431 | * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead |
|
2409 | 2432 | of @abort, and with a new (better) mechanism for handling the |
|
2410 | 2433 | exceptions. |
|
2411 | 2434 | |
|
2412 | 2435 | 2002-10-27 Fernando Perez <fperez@colorado.edu> |
|
2413 | 2436 | |
|
2414 | 2437 | * IPython/usage.py (__doc__): updated the --help information and |
|
2415 | 2438 | the ipythonrc file to indicate that -log generates |
|
2416 | 2439 | ./ipython.log. Also fixed the corresponding info in @logstart. |
|
2417 | 2440 | This and several other fixes in the manuals thanks to reports by |
|
2418 | 2441 | François Pinard <pinard-AT-iro.umontreal.ca>. |
|
2419 | 2442 | |
|
2420 | 2443 | * IPython/Logger.py (Logger.switch_log): Fixed error message to |
|
2421 | 2444 | refer to @logstart (instead of @log, which doesn't exist). |
|
2422 | 2445 | |
|
2423 | 2446 | * IPython/iplib.py (InteractiveShell._prefilter): fixed |
|
2424 | 2447 | AttributeError crash. Thanks to Christopher Armstrong |
|
2425 | 2448 | <radix-AT-twistedmatrix.com> for the report/fix. This bug had been |
|
2426 | 2449 | introduced recently (in 0.2.14pre37) with the fix to the eval |
|
2427 | 2450 | problem mentioned below. |
|
2428 | 2451 | |
|
2429 | 2452 | 2002-10-17 Fernando Perez <fperez@colorado.edu> |
|
2430 | 2453 | |
|
2431 | 2454 | * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows |
|
2432 | 2455 | installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>. |
|
2433 | 2456 | |
|
2434 | 2457 | * IPython/iplib.py (InteractiveShell._prefilter): Many changes to |
|
2435 | 2458 | this function to fix a problem reported by Alex Schmolck. He saw |
|
2436 | 2459 | it with list comprehensions and generators, which were getting |
|
2437 | 2460 | called twice. The real problem was an 'eval' call in testing for |
|
2438 | 2461 | automagic which was evaluating the input line silently. |
|
2439 | 2462 | |
|
2440 | 2463 | This is a potentially very nasty bug, if the input has side |
|
2441 | 2464 | effects which must not be repeated. The code is much cleaner now, |
|
2442 | 2465 | without any blanket 'except' left and with a regexp test for |
|
2443 | 2466 | actual function names. |
|
2444 | 2467 | |
|
2445 | 2468 | But an eval remains, which I'm not fully comfortable with. I just |
|
2446 | 2469 | don't know how to find out if an expression could be a callable in |
|
2447 | 2470 | the user's namespace without doing an eval on the string. However |
|
2448 | 2471 | that string is now much more strictly checked so that no code |
|
2449 | 2472 | slips by, so the eval should only happen for things that can |
|
2450 | 2473 | really be only function/method names. |
|
2451 | 2474 | |
|
2452 | 2475 | 2002-10-15 Fernando Perez <fperez@colorado.edu> |
|
2453 | 2476 | |
|
2454 | 2477 | * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac |
|
2455 | 2478 | OSX information to main manual, removed README_Mac_OSX file from |
|
2456 | 2479 | distribution. Also updated credits for recent additions. |
|
2457 | 2480 | |
|
2458 | 2481 | 2002-10-10 Fernando Perez <fperez@colorado.edu> |
|
2459 | 2482 | |
|
2460 | 2483 | * README_Mac_OSX: Added a README for Mac OSX users for fixing |
|
2461 | 2484 | terminal-related issues. Many thanks to Andrea Riciputi |
|
2462 | 2485 | <andrea.riciputi-AT-libero.it> for writing it. |
|
2463 | 2486 | |
|
2464 | 2487 | * IPython/UserConfig/ipythonrc.py: Fixes to various small issues, |
|
2465 | 2488 | thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2466 | 2489 | |
|
2467 | 2490 | * setup.py (make_shortcut): Fixes for Windows installation. Thanks |
|
2468 | 2491 | to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad |
|
2469 | 2492 | <syver-en-AT-online.no> who both submitted patches for this problem. |
|
2470 | 2493 | |
|
2471 | 2494 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for |
|
2472 | 2495 | global embedding to make sure that things don't overwrite user |
|
2473 | 2496 | globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com> |
|
2474 | 2497 | |
|
2475 | 2498 | * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6 |
|
2476 | 2499 | compatibility. Thanks to Hayden Callow |
|
2477 | 2500 | <h.callow-AT-elec.canterbury.ac.nz> |
|
2478 | 2501 | |
|
2479 | 2502 | 2002-10-04 Fernando Perez <fperez@colorado.edu> |
|
2480 | 2503 | |
|
2481 | 2504 | * IPython/Gnuplot2.py (PlotItem): Added 'index' option for |
|
2482 | 2505 | Gnuplot.File objects. |
|
2483 | 2506 | |
|
2484 | 2507 | 2002-07-23 Fernando Perez <fperez@colorado.edu> |
|
2485 | 2508 | |
|
2486 | 2509 | * IPython/genutils.py (timing): Added timings() and timing() for |
|
2487 | 2510 | quick access to the most commonly needed data, the execution |
|
2488 | 2511 | times. Old timing() renamed to timings_out(). |
|
2489 | 2512 | |
|
2490 | 2513 | 2002-07-18 Fernando Perez <fperez@colorado.edu> |
|
2491 | 2514 | |
|
2492 | 2515 | * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed |
|
2493 | 2516 | bug with nested instances disrupting the parent's tab completion. |
|
2494 | 2517 | |
|
2495 | 2518 | * IPython/iplib.py (all_completions): Added Alex Schmolck's |
|
2496 | 2519 | all_completions code to begin the emacs integration. |
|
2497 | 2520 | |
|
2498 | 2521 | * IPython/Gnuplot2.py (zip_items): Added optional 'titles' |
|
2499 | 2522 | argument to allow titling individual arrays when plotting. |
|
2500 | 2523 | |
|
2501 | 2524 | 2002-07-15 Fernando Perez <fperez@colorado.edu> |
|
2502 | 2525 | |
|
2503 | 2526 | * setup.py (make_shortcut): changed to retrieve the value of |
|
2504 | 2527 | 'Program Files' directory from the registry (this value changes in |
|
2505 | 2528 | non-english versions of Windows). Thanks to Thomas Fanslau |
|
2506 | 2529 | <tfanslau-AT-gmx.de> for the report. |
|
2507 | 2530 | |
|
2508 | 2531 | 2002-07-10 Fernando Perez <fperez@colorado.edu> |
|
2509 | 2532 | |
|
2510 | 2533 | * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for |
|
2511 | 2534 | a bug in pdb, which crashes if a line with only whitespace is |
|
2512 | 2535 | entered. Bug report submitted to sourceforge. |
|
2513 | 2536 | |
|
2514 | 2537 | 2002-07-09 Fernando Perez <fperez@colorado.edu> |
|
2515 | 2538 | |
|
2516 | 2539 | * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when |
|
2517 | 2540 | reporting exceptions (it's a bug in inspect.py, I just set a |
|
2518 | 2541 | workaround). |
|
2519 | 2542 | |
|
2520 | 2543 | 2002-07-08 Fernando Perez <fperez@colorado.edu> |
|
2521 | 2544 | |
|
2522 | 2545 | * IPython/iplib.py (InteractiveShell.__init__): fixed reference to |
|
2523 | 2546 | __IPYTHON__ in __builtins__ to show up in user_ns. |
|
2524 | 2547 | |
|
2525 | 2548 | 2002-07-03 Fernando Perez <fperez@colorado.edu> |
|
2526 | 2549 | |
|
2527 | 2550 | * IPython/GnuplotInteractive.py (magic_gp_set_default): changed |
|
2528 | 2551 | name from @gp_set_instance to @gp_set_default. |
|
2529 | 2552 | |
|
2530 | 2553 | * IPython/ipmaker.py (make_IPython): default editor value set to |
|
2531 | 2554 | '0' (a string), to match the rc file. Otherwise will crash when |
|
2532 | 2555 | .strip() is called on it. |
|
2533 | 2556 | |
|
2534 | 2557 | |
|
2535 | 2558 | 2002-06-28 Fernando Perez <fperez@colorado.edu> |
|
2536 | 2559 | |
|
2537 | 2560 | * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing |
|
2538 | 2561 | of files in current directory when a file is executed via |
|
2539 | 2562 | @run. Patch also by RA <ralf_ahlbrink-AT-web.de>. |
|
2540 | 2563 | |
|
2541 | 2564 | * setup.py (manfiles): fix for rpm builds, submitted by RA |
|
2542 | 2565 | <ralf_ahlbrink-AT-web.de>. Now we have RPMs! |
|
2543 | 2566 | |
|
2544 | 2567 | * IPython/ipmaker.py (make_IPython): fixed lookup of default |
|
2545 | 2568 | editor when set to '0'. Problem was, '0' evaluates to True (it's a |
|
2546 | 2569 | string!). A. Schmolck caught this one. |
|
2547 | 2570 | |
|
2548 | 2571 | 2002-06-27 Fernando Perez <fperez@colorado.edu> |
|
2549 | 2572 | |
|
2550 | 2573 | * IPython/ipmaker.py (make_IPython): fixed bug when running user |
|
2551 | 2574 | defined files at the cmd line. __name__ wasn't being set to |
|
2552 | 2575 | __main__. |
|
2553 | 2576 | |
|
2554 | 2577 | * IPython/Gnuplot2.py (zip_items): improved it so it can plot also |
|
2555 | 2578 | regular lists and tuples besides Numeric arrays. |
|
2556 | 2579 | |
|
2557 | 2580 | * IPython/Prompts.py (CachedOutput.__call__): Added output |
|
2558 | 2581 | supression for input ending with ';'. Similar to Mathematica and |
|
2559 | 2582 | Matlab. The _* vars and Out[] list are still updated, just like |
|
2560 | 2583 | Mathematica behaves. |
|
2561 | 2584 | |
|
2562 | 2585 | 2002-06-25 Fernando Perez <fperez@colorado.edu> |
|
2563 | 2586 | |
|
2564 | 2587 | * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of |
|
2565 | 2588 | .ini extensions for profiels under Windows. |
|
2566 | 2589 | |
|
2567 | 2590 | * IPython/OInspect.py (Inspector.pinfo): improved alignment of |
|
2568 | 2591 | string form. Fix contributed by Alexander Schmolck |
|
2569 | 2592 | <a.schmolck-AT-gmx.net> |
|
2570 | 2593 | |
|
2571 | 2594 | * IPython/GnuplotRuntime.py (gp_new): new function. Returns a |
|
2572 | 2595 | pre-configured Gnuplot instance. |
|
2573 | 2596 | |
|
2574 | 2597 | 2002-06-21 Fernando Perez <fperez@colorado.edu> |
|
2575 | 2598 | |
|
2576 | 2599 | * IPython/numutils.py (exp_safe): new function, works around the |
|
2577 | 2600 | underflow problems in Numeric. |
|
2578 | 2601 | (log2): New fn. Safe log in base 2: returns exact integer answer |
|
2579 | 2602 | for exact integer powers of 2. |
|
2580 | 2603 | |
|
2581 | 2604 | * IPython/Magic.py (get_py_filename): fixed it not expanding '~' |
|
2582 | 2605 | properly. |
|
2583 | 2606 | |
|
2584 | 2607 | 2002-06-20 Fernando Perez <fperez@colorado.edu> |
|
2585 | 2608 | |
|
2586 | 2609 | * IPython/genutils.py (timing): new function like |
|
2587 | 2610 | Mathematica's. Similar to time_test, but returns more info. |
|
2588 | 2611 | |
|
2589 | 2612 | 2002-06-18 Fernando Perez <fperez@colorado.edu> |
|
2590 | 2613 | |
|
2591 | 2614 | * IPython/Magic.py (Magic.magic_save): modified @save and @r |
|
2592 | 2615 | according to Mike Heeter's suggestions. |
|
2593 | 2616 | |
|
2594 | 2617 | 2002-06-16 Fernando Perez <fperez@colorado.edu> |
|
2595 | 2618 | |
|
2596 | 2619 | * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot |
|
2597 | 2620 | system. GnuplotMagic is gone as a user-directory option. New files |
|
2598 | 2621 | make it easier to use all the gnuplot stuff both from external |
|
2599 | 2622 | programs as well as from IPython. Had to rewrite part of |
|
2600 | 2623 | hardcopy() b/c of a strange bug: often the ps files simply don't |
|
2601 | 2624 | get created, and require a repeat of the command (often several |
|
2602 | 2625 | times). |
|
2603 | 2626 | |
|
2604 | 2627 | * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to |
|
2605 | 2628 | resolve output channel at call time, so that if sys.stderr has |
|
2606 | 2629 | been redirected by user this gets honored. |
|
2607 | 2630 | |
|
2608 | 2631 | 2002-06-13 Fernando Perez <fperez@colorado.edu> |
|
2609 | 2632 | |
|
2610 | 2633 | * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to |
|
2611 | 2634 | IPShell. Kept a copy with the old names to avoid breaking people's |
|
2612 | 2635 | embedded code. |
|
2613 | 2636 | |
|
2614 | 2637 | * IPython/ipython: simplified it to the bare minimum after |
|
2615 | 2638 | Holger's suggestions. Added info about how to use it in |
|
2616 | 2639 | PYTHONSTARTUP. |
|
2617 | 2640 | |
|
2618 | 2641 | * IPython/Shell.py (IPythonShell): changed the options passing |
|
2619 | 2642 | from a string with funky %s replacements to a straight list. Maybe |
|
2620 | 2643 | a bit more typing, but it follows sys.argv conventions, so there's |
|
2621 | 2644 | less special-casing to remember. |
|
2622 | 2645 | |
|
2623 | 2646 | 2002-06-12 Fernando Perez <fperez@colorado.edu> |
|
2624 | 2647 | |
|
2625 | 2648 | * IPython/Magic.py (Magic.magic_r): new magic auto-repeat |
|
2626 | 2649 | command. Thanks to a suggestion by Mike Heeter. |
|
2627 | 2650 | (Magic.magic_pfile): added behavior to look at filenames if given |
|
2628 | 2651 | arg is not a defined object. |
|
2629 | 2652 | (Magic.magic_save): New @save function to save code snippets. Also |
|
2630 | 2653 | a Mike Heeter idea. |
|
2631 | 2654 | |
|
2632 | 2655 | * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to |
|
2633 | 2656 | plot() and replot(). Much more convenient now, especially for |
|
2634 | 2657 | interactive use. |
|
2635 | 2658 | |
|
2636 | 2659 | * IPython/Magic.py (Magic.magic_run): Added .py automatically to |
|
2637 | 2660 | filenames. |
|
2638 | 2661 | |
|
2639 | 2662 | 2002-06-02 Fernando Perez <fperez@colorado.edu> |
|
2640 | 2663 | |
|
2641 | 2664 | * IPython/Struct.py (Struct.__init__): modified to admit |
|
2642 | 2665 | initialization via another struct. |
|
2643 | 2666 | |
|
2644 | 2667 | * IPython/genutils.py (SystemExec.__init__): New stateful |
|
2645 | 2668 | interface to xsys and bq. Useful for writing system scripts. |
|
2646 | 2669 | |
|
2647 | 2670 | 2002-05-30 Fernando Perez <fperez@colorado.edu> |
|
2648 | 2671 | |
|
2649 | 2672 | * MANIFEST.in: Changed docfile selection to exclude all the lyx |
|
2650 | 2673 | documents. This will make the user download smaller (it's getting |
|
2651 | 2674 | too big). |
|
2652 | 2675 | |
|
2653 | 2676 | 2002-05-29 Fernando Perez <fperez@colorado.edu> |
|
2654 | 2677 | |
|
2655 | 2678 | * IPython/iplib.py (_FakeModule.__init__): New class introduced to |
|
2656 | 2679 | fix problems with shelve and pickle. Seems to work, but I don't |
|
2657 | 2680 | know if corner cases break it. Thanks to Mike Heeter |
|
2658 | 2681 | <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases. |
|
2659 | 2682 | |
|
2660 | 2683 | 2002-05-24 Fernando Perez <fperez@colorado.edu> |
|
2661 | 2684 | |
|
2662 | 2685 | * IPython/Magic.py (Macro.__init__): fixed magics embedded in |
|
2663 | 2686 | macros having broken. |
|
2664 | 2687 | |
|
2665 | 2688 | 2002-05-21 Fernando Perez <fperez@colorado.edu> |
|
2666 | 2689 | |
|
2667 | 2690 | * IPython/Magic.py (Magic.magic_logstart): fixed recently |
|
2668 | 2691 | introduced logging bug: all history before logging started was |
|
2669 | 2692 | being written one character per line! This came from the redesign |
|
2670 | 2693 | of the input history as a special list which slices to strings, |
|
2671 | 2694 | not to lists. |
|
2672 | 2695 | |
|
2673 | 2696 | 2002-05-20 Fernando Perez <fperez@colorado.edu> |
|
2674 | 2697 | |
|
2675 | 2698 | * IPython/Prompts.py (CachedOutput.__init__): made the color table |
|
2676 | 2699 | be an attribute of all classes in this module. The design of these |
|
2677 | 2700 | classes needs some serious overhauling. |
|
2678 | 2701 | |
|
2679 | 2702 | * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug |
|
2680 | 2703 | which was ignoring '_' in option names. |
|
2681 | 2704 | |
|
2682 | 2705 | * IPython/ultraTB.py (FormattedTB.__init__): Changed |
|
2683 | 2706 | 'Verbose_novars' to 'Context' and made it the new default. It's a |
|
2684 | 2707 | bit more readable and also safer than verbose. |
|
2685 | 2708 | |
|
2686 | 2709 | * IPython/PyColorize.py (Parser.__call__): Fixed coloring of |
|
2687 | 2710 | triple-quoted strings. |
|
2688 | 2711 | |
|
2689 | 2712 | * IPython/OInspect.py (__all__): new module exposing the object |
|
2690 | 2713 | introspection facilities. Now the corresponding magics are dummy |
|
2691 | 2714 | wrappers around this. Having this module will make it much easier |
|
2692 | 2715 | to put these functions into our modified pdb. |
|
2693 | 2716 | This new object inspector system uses the new colorizing module, |
|
2694 | 2717 | so source code and other things are nicely syntax highlighted. |
|
2695 | 2718 | |
|
2696 | 2719 | 2002-05-18 Fernando Perez <fperez@colorado.edu> |
|
2697 | 2720 | |
|
2698 | 2721 | * IPython/ColorANSI.py: Split the coloring tools into a separate |
|
2699 | 2722 | module so I can use them in other code easier (they were part of |
|
2700 | 2723 | ultraTB). |
|
2701 | 2724 | |
|
2702 | 2725 | 2002-05-17 Fernando Perez <fperez@colorado.edu> |
|
2703 | 2726 | |
|
2704 | 2727 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2705 | 2728 | fixed it to set the global 'g' also to the called instance, as |
|
2706 | 2729 | long as 'g' was still a gnuplot instance (so it doesn't overwrite |
|
2707 | 2730 | user's 'g' variables). |
|
2708 | 2731 | |
|
2709 | 2732 | * IPython/iplib.py (InteractiveShell.__init__): Added In/Out |
|
2710 | 2733 | global variables (aliases to _ih,_oh) so that users which expect |
|
2711 | 2734 | In[5] or Out[7] to work aren't unpleasantly surprised. |
|
2712 | 2735 | (InputList.__getslice__): new class to allow executing slices of |
|
2713 | 2736 | input history directly. Very simple class, complements the use of |
|
2714 | 2737 | macros. |
|
2715 | 2738 | |
|
2716 | 2739 | 2002-05-16 Fernando Perez <fperez@colorado.edu> |
|
2717 | 2740 | |
|
2718 | 2741 | * setup.py (docdirbase): make doc directory be just doc/IPython |
|
2719 | 2742 | without version numbers, it will reduce clutter for users. |
|
2720 | 2743 | |
|
2721 | 2744 | * IPython/Magic.py (Magic.magic_run): Add explicit local dict to |
|
2722 | 2745 | execfile call to prevent possible memory leak. See for details: |
|
2723 | 2746 | http://mail.python.org/pipermail/python-list/2002-February/088476.html |
|
2724 | 2747 | |
|
2725 | 2748 | 2002-05-15 Fernando Perez <fperez@colorado.edu> |
|
2726 | 2749 | |
|
2727 | 2750 | * IPython/Magic.py (Magic.magic_psource): made the object |
|
2728 | 2751 | introspection names be more standard: pdoc, pdef, pfile and |
|
2729 | 2752 | psource. They all print/page their output, and it makes |
|
2730 | 2753 | remembering them easier. Kept old names for compatibility as |
|
2731 | 2754 | aliases. |
|
2732 | 2755 | |
|
2733 | 2756 | 2002-05-14 Fernando Perez <fperez@colorado.edu> |
|
2734 | 2757 | |
|
2735 | 2758 | * IPython/UserConfig/GnuplotMagic.py: I think I finally understood |
|
2736 | 2759 | what the mouse problem was. The trick is to use gnuplot with temp |
|
2737 | 2760 | files and NOT with pipes (for data communication), because having |
|
2738 | 2761 | both pipes and the mouse on is bad news. |
|
2739 | 2762 | |
|
2740 | 2763 | 2002-05-13 Fernando Perez <fperez@colorado.edu> |
|
2741 | 2764 | |
|
2742 | 2765 | * IPython/Magic.py (Magic._ofind): fixed namespace order search |
|
2743 | 2766 | bug. Information would be reported about builtins even when |
|
2744 | 2767 | user-defined functions overrode them. |
|
2745 | 2768 | |
|
2746 | 2769 | 2002-05-11 Fernando Perez <fperez@colorado.edu> |
|
2747 | 2770 | |
|
2748 | 2771 | * IPython/__init__.py (__all__): removed FlexCompleter from |
|
2749 | 2772 | __all__ so that things don't fail in platforms without readline. |
|
2750 | 2773 | |
|
2751 | 2774 | 2002-05-10 Fernando Perez <fperez@colorado.edu> |
|
2752 | 2775 | |
|
2753 | 2776 | * IPython/__init__.py (__all__): removed numutils from __all__ b/c |
|
2754 | 2777 | it requires Numeric, effectively making Numeric a dependency for |
|
2755 | 2778 | IPython. |
|
2756 | 2779 | |
|
2757 | 2780 | * Released 0.2.13 |
|
2758 | 2781 | |
|
2759 | 2782 | * IPython/Magic.py (Magic.magic_prun): big overhaul to the |
|
2760 | 2783 | profiler interface. Now all the major options from the profiler |
|
2761 | 2784 | module are directly supported in IPython, both for single |
|
2762 | 2785 | expressions (@prun) and for full programs (@run -p). |
|
2763 | 2786 | |
|
2764 | 2787 | 2002-05-09 Fernando Perez <fperez@colorado.edu> |
|
2765 | 2788 | |
|
2766 | 2789 | * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of |
|
2767 | 2790 | magic properly formatted for screen. |
|
2768 | 2791 | |
|
2769 | 2792 | * setup.py (make_shortcut): Changed things to put pdf version in |
|
2770 | 2793 | doc/ instead of doc/manual (had to change lyxport a bit). |
|
2771 | 2794 | |
|
2772 | 2795 | * IPython/Magic.py (Profile.string_stats): made profile runs go |
|
2773 | 2796 | through pager (they are long and a pager allows searching, saving, |
|
2774 | 2797 | etc.) |
|
2775 | 2798 | |
|
2776 | 2799 | 2002-05-08 Fernando Perez <fperez@colorado.edu> |
|
2777 | 2800 | |
|
2778 | 2801 | * Released 0.2.12 |
|
2779 | 2802 | |
|
2780 | 2803 | 2002-05-06 Fernando Perez <fperez@colorado.edu> |
|
2781 | 2804 | |
|
2782 | 2805 | * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently |
|
2783 | 2806 | introduced); 'hist n1 n2' was broken. |
|
2784 | 2807 | (Magic.magic_pdb): added optional on/off arguments to @pdb |
|
2785 | 2808 | (Magic.magic_run): added option -i to @run, which executes code in |
|
2786 | 2809 | the IPython namespace instead of a clean one. Also added @irun as |
|
2787 | 2810 | an alias to @run -i. |
|
2788 | 2811 | |
|
2789 | 2812 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2790 | 2813 | fixed (it didn't really do anything, the namespaces were wrong). |
|
2791 | 2814 | |
|
2792 | 2815 | * IPython/Debugger.py (__init__): Added workaround for python 2.1 |
|
2793 | 2816 | |
|
2794 | 2817 | * IPython/__init__.py (__all__): Fixed package namespace, now |
|
2795 | 2818 | 'import IPython' does give access to IPython.<all> as |
|
2796 | 2819 | expected. Also renamed __release__ to Release. |
|
2797 | 2820 | |
|
2798 | 2821 | * IPython/Debugger.py (__license__): created new Pdb class which |
|
2799 | 2822 | functions like a drop-in for the normal pdb.Pdb but does NOT |
|
2800 | 2823 | import readline by default. This way it doesn't muck up IPython's |
|
2801 | 2824 | readline handling, and now tab-completion finally works in the |
|
2802 | 2825 | debugger -- sort of. It completes things globally visible, but the |
|
2803 | 2826 | completer doesn't track the stack as pdb walks it. That's a bit |
|
2804 | 2827 | tricky, and I'll have to implement it later. |
|
2805 | 2828 | |
|
2806 | 2829 | 2002-05-05 Fernando Perez <fperez@colorado.edu> |
|
2807 | 2830 | |
|
2808 | 2831 | * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for |
|
2809 | 2832 | magic docstrings when printed via ? (explicit \'s were being |
|
2810 | 2833 | printed). |
|
2811 | 2834 | |
|
2812 | 2835 | * IPython/ipmaker.py (make_IPython): fixed namespace |
|
2813 | 2836 | identification bug. Now variables loaded via logs or command-line |
|
2814 | 2837 | files are recognized in the interactive namespace by @who. |
|
2815 | 2838 | |
|
2816 | 2839 | * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in |
|
2817 | 2840 | log replay system stemming from the string form of Structs. |
|
2818 | 2841 | |
|
2819 | 2842 | * IPython/Magic.py (Macro.__init__): improved macros to properly |
|
2820 | 2843 | handle magic commands in them. |
|
2821 | 2844 | (Magic.magic_logstart): usernames are now expanded so 'logstart |
|
2822 | 2845 | ~/mylog' now works. |
|
2823 | 2846 | |
|
2824 | 2847 | * IPython/iplib.py (complete): fixed bug where paths starting with |
|
2825 | 2848 | '/' would be completed as magic names. |
|
2826 | 2849 | |
|
2827 | 2850 | 2002-05-04 Fernando Perez <fperez@colorado.edu> |
|
2828 | 2851 | |
|
2829 | 2852 | * IPython/Magic.py (Magic.magic_run): added options -p and -f to |
|
2830 | 2853 | allow running full programs under the profiler's control. |
|
2831 | 2854 | |
|
2832 | 2855 | * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars |
|
2833 | 2856 | mode to report exceptions verbosely but without formatting |
|
2834 | 2857 | variables. This addresses the issue of ipython 'freezing' (it's |
|
2835 | 2858 | not frozen, but caught in an expensive formatting loop) when huge |
|
2836 | 2859 | variables are in the context of an exception. |
|
2837 | 2860 | (VerboseTB.text): Added '--->' markers at line where exception was |
|
2838 | 2861 | triggered. Much clearer to read, especially in NoColor modes. |
|
2839 | 2862 | |
|
2840 | 2863 | * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been |
|
2841 | 2864 | implemented in reverse when changing to the new parse_options(). |
|
2842 | 2865 | |
|
2843 | 2866 | 2002-05-03 Fernando Perez <fperez@colorado.edu> |
|
2844 | 2867 | |
|
2845 | 2868 | * IPython/Magic.py (Magic.parse_options): new function so that |
|
2846 | 2869 | magics can parse options easier. |
|
2847 | 2870 | (Magic.magic_prun): new function similar to profile.run(), |
|
2848 | 2871 | suggested by Chris Hart. |
|
2849 | 2872 | (Magic.magic_cd): fixed behavior so that it only changes if |
|
2850 | 2873 | directory actually is in history. |
|
2851 | 2874 | |
|
2852 | 2875 | * IPython/usage.py (__doc__): added information about potential |
|
2853 | 2876 | slowness of Verbose exception mode when there are huge data |
|
2854 | 2877 | structures to be formatted (thanks to Archie Paulson). |
|
2855 | 2878 | |
|
2856 | 2879 | * IPython/ipmaker.py (make_IPython): Changed default logging |
|
2857 | 2880 | (when simply called with -log) to use curr_dir/ipython.log in |
|
2858 | 2881 | rotate mode. Fixed crash which was occuring with -log before |
|
2859 | 2882 | (thanks to Jim Boyle). |
|
2860 | 2883 | |
|
2861 | 2884 | 2002-05-01 Fernando Perez <fperez@colorado.edu> |
|
2862 | 2885 | |
|
2863 | 2886 | * Released 0.2.11 for these fixes (mainly the ultraTB one which |
|
2864 | 2887 | was nasty -- though somewhat of a corner case). |
|
2865 | 2888 | |
|
2866 | 2889 | * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to |
|
2867 | 2890 | text (was a bug). |
|
2868 | 2891 | |
|
2869 | 2892 | 2002-04-30 Fernando Perez <fperez@colorado.edu> |
|
2870 | 2893 | |
|
2871 | 2894 | * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add |
|
2872 | 2895 | a print after ^D or ^C from the user so that the In[] prompt |
|
2873 | 2896 | doesn't over-run the gnuplot one. |
|
2874 | 2897 | |
|
2875 | 2898 | 2002-04-29 Fernando Perez <fperez@colorado.edu> |
|
2876 | 2899 | |
|
2877 | 2900 | * Released 0.2.10 |
|
2878 | 2901 | |
|
2879 | 2902 | * IPython/__release__.py (version): get date dynamically. |
|
2880 | 2903 | |
|
2881 | 2904 | * Misc. documentation updates thanks to Arnd's comments. Also ran |
|
2882 | 2905 | a full spellcheck on the manual (hadn't been done in a while). |
|
2883 | 2906 | |
|
2884 | 2907 | 2002-04-27 Fernando Perez <fperez@colorado.edu> |
|
2885 | 2908 | |
|
2886 | 2909 | * IPython/Magic.py (Magic.magic_logstart): Fixed bug where |
|
2887 | 2910 | starting a log in mid-session would reset the input history list. |
|
2888 | 2911 | |
|
2889 | 2912 | 2002-04-26 Fernando Perez <fperez@colorado.edu> |
|
2890 | 2913 | |
|
2891 | 2914 | * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not |
|
2892 | 2915 | all files were being included in an update. Now anything in |
|
2893 | 2916 | UserConfig that matches [A-Za-z]*.py will go (this excludes |
|
2894 | 2917 | __init__.py) |
|
2895 | 2918 | |
|
2896 | 2919 | 2002-04-25 Fernando Perez <fperez@colorado.edu> |
|
2897 | 2920 | |
|
2898 | 2921 | * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__ |
|
2899 | 2922 | to __builtins__ so that any form of embedded or imported code can |
|
2900 | 2923 | test for being inside IPython. |
|
2901 | 2924 | |
|
2902 | 2925 | * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance): |
|
2903 | 2926 | changed to GnuplotMagic because it's now an importable module, |
|
2904 | 2927 | this makes the name follow that of the standard Gnuplot module. |
|
2905 | 2928 | GnuplotMagic can now be loaded at any time in mid-session. |
|
2906 | 2929 | |
|
2907 | 2930 | 2002-04-24 Fernando Perez <fperez@colorado.edu> |
|
2908 | 2931 | |
|
2909 | 2932 | * IPython/numutils.py: removed SIUnits. It doesn't properly set |
|
2910 | 2933 | the globals (IPython has its own namespace) and the |
|
2911 | 2934 | PhysicalQuantity stuff is much better anyway. |
|
2912 | 2935 | |
|
2913 | 2936 | * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot |
|
2914 | 2937 | embedding example to standard user directory for |
|
2915 | 2938 | distribution. Also put it in the manual. |
|
2916 | 2939 | |
|
2917 | 2940 | * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot |
|
2918 | 2941 | instance as first argument (so it doesn't rely on some obscure |
|
2919 | 2942 | hidden global). |
|
2920 | 2943 | |
|
2921 | 2944 | * IPython/UserConfig/ipythonrc.py: put () back in accepted |
|
2922 | 2945 | delimiters. While it prevents ().TAB from working, it allows |
|
2923 | 2946 | completions in open (... expressions. This is by far a more common |
|
2924 | 2947 | case. |
|
2925 | 2948 | |
|
2926 | 2949 | 2002-04-23 Fernando Perez <fperez@colorado.edu> |
|
2927 | 2950 | |
|
2928 | 2951 | * IPython/Extensions/InterpreterPasteInput.py: new |
|
2929 | 2952 | syntax-processing module for pasting lines with >>> or ... at the |
|
2930 | 2953 | start. |
|
2931 | 2954 | |
|
2932 | 2955 | * IPython/Extensions/PhysicalQ_Interactive.py |
|
2933 | 2956 | (PhysicalQuantityInteractive.__int__): fixed to work with either |
|
2934 | 2957 | Numeric or math. |
|
2935 | 2958 | |
|
2936 | 2959 | * IPython/UserConfig/ipythonrc-numeric.py: reorganized the |
|
2937 | 2960 | provided profiles. Now we have: |
|
2938 | 2961 | -math -> math module as * and cmath with its own namespace. |
|
2939 | 2962 | -numeric -> Numeric as *, plus gnuplot & grace |
|
2940 | 2963 | -physics -> same as before |
|
2941 | 2964 | |
|
2942 | 2965 | * IPython/Magic.py (Magic.magic_magic): Fixed bug where |
|
2943 | 2966 | user-defined magics wouldn't be found by @magic if they were |
|
2944 | 2967 | defined as class methods. Also cleaned up the namespace search |
|
2945 | 2968 | logic and the string building (to use %s instead of many repeated |
|
2946 | 2969 | string adds). |
|
2947 | 2970 | |
|
2948 | 2971 | * IPython/UserConfig/example-magic.py (magic_foo): updated example |
|
2949 | 2972 | of user-defined magics to operate with class methods (cleaner, in |
|
2950 | 2973 | line with the gnuplot code). |
|
2951 | 2974 | |
|
2952 | 2975 | 2002-04-22 Fernando Perez <fperez@colorado.edu> |
|
2953 | 2976 | |
|
2954 | 2977 | * setup.py: updated dependency list so that manual is updated when |
|
2955 | 2978 | all included files change. |
|
2956 | 2979 | |
|
2957 | 2980 | * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring |
|
2958 | 2981 | the delimiter removal option (the fix is ugly right now). |
|
2959 | 2982 | |
|
2960 | 2983 | * IPython/UserConfig/ipythonrc-physics.py: simplified not to load |
|
2961 | 2984 | all of the math profile (quicker loading, no conflict between |
|
2962 | 2985 | g-9.8 and g-gnuplot). |
|
2963 | 2986 | |
|
2964 | 2987 | * IPython/CrashHandler.py (CrashHandler.__call__): changed default |
|
2965 | 2988 | name of post-mortem files to IPython_crash_report.txt. |
|
2966 | 2989 | |
|
2967 | 2990 | * Cleanup/update of the docs. Added all the new readline info and |
|
2968 | 2991 | formatted all lists as 'real lists'. |
|
2969 | 2992 | |
|
2970 | 2993 | * IPython/ipmaker.py (make_IPython): removed now-obsolete |
|
2971 | 2994 | tab-completion options, since the full readline parse_and_bind is |
|
2972 | 2995 | now accessible. |
|
2973 | 2996 | |
|
2974 | 2997 | * IPython/iplib.py (InteractiveShell.init_readline): Changed |
|
2975 | 2998 | handling of readline options. Now users can specify any string to |
|
2976 | 2999 | be passed to parse_and_bind(), as well as the delimiters to be |
|
2977 | 3000 | removed. |
|
2978 | 3001 | (InteractiveShell.__init__): Added __name__ to the global |
|
2979 | 3002 | namespace so that things like Itpl which rely on its existence |
|
2980 | 3003 | don't crash. |
|
2981 | 3004 | (InteractiveShell._prefilter): Defined the default with a _ so |
|
2982 | 3005 | that prefilter() is easier to override, while the default one |
|
2983 | 3006 | remains available. |
|
2984 | 3007 | |
|
2985 | 3008 | 2002-04-18 Fernando Perez <fperez@colorado.edu> |
|
2986 | 3009 | |
|
2987 | 3010 | * Added information about pdb in the docs. |
|
2988 | 3011 | |
|
2989 | 3012 | 2002-04-17 Fernando Perez <fperez@colorado.edu> |
|
2990 | 3013 | |
|
2991 | 3014 | * IPython/ipmaker.py (make_IPython): added rc_override option to |
|
2992 | 3015 | allow passing config options at creation time which may override |
|
2993 | 3016 | anything set in the config files or command line. This is |
|
2994 | 3017 | particularly useful for configuring embedded instances. |
|
2995 | 3018 | |
|
2996 | 3019 | 2002-04-15 Fernando Perez <fperez@colorado.edu> |
|
2997 | 3020 | |
|
2998 | 3021 | * IPython/Logger.py (Logger.log): Fixed a nasty bug which could |
|
2999 | 3022 | crash embedded instances because of the input cache falling out of |
|
3000 | 3023 | sync with the output counter. |
|
3001 | 3024 | |
|
3002 | 3025 | * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug |
|
3003 | 3026 | mode which calls pdb after an uncaught exception in IPython itself. |
|
3004 | 3027 | |
|
3005 | 3028 | 2002-04-14 Fernando Perez <fperez@colorado.edu> |
|
3006 | 3029 | |
|
3007 | 3030 | * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up |
|
3008 | 3031 | readline, fix it back after each call. |
|
3009 | 3032 | |
|
3010 | 3033 | * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private |
|
3011 | 3034 | method to force all access via __call__(), which guarantees that |
|
3012 | 3035 | traceback references are properly deleted. |
|
3013 | 3036 | |
|
3014 | 3037 | * IPython/Prompts.py (CachedOutput._display): minor fixes to |
|
3015 | 3038 | improve printing when pprint is in use. |
|
3016 | 3039 | |
|
3017 | 3040 | 2002-04-13 Fernando Perez <fperez@colorado.edu> |
|
3018 | 3041 | |
|
3019 | 3042 | * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit |
|
3020 | 3043 | exceptions aren't caught anymore. If the user triggers one, he |
|
3021 | 3044 | should know why he's doing it and it should go all the way up, |
|
3022 | 3045 | just like any other exception. So now @abort will fully kill the |
|
3023 | 3046 | embedded interpreter and the embedding code (unless that happens |
|
3024 | 3047 | to catch SystemExit). |
|
3025 | 3048 | |
|
3026 | 3049 | * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag |
|
3027 | 3050 | and a debugger() method to invoke the interactive pdb debugger |
|
3028 | 3051 | after printing exception information. Also added the corresponding |
|
3029 | 3052 | -pdb option and @pdb magic to control this feature, and updated |
|
3030 | 3053 | the docs. After a suggestion from Christopher Hart |
|
3031 | 3054 | (hart-AT-caltech.edu). |
|
3032 | 3055 | |
|
3033 | 3056 | 2002-04-12 Fernando Perez <fperez@colorado.edu> |
|
3034 | 3057 | |
|
3035 | 3058 | * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use |
|
3036 | 3059 | the exception handlers defined by the user (not the CrashHandler) |
|
3037 | 3060 | so that user exceptions don't trigger an ipython bug report. |
|
3038 | 3061 | |
|
3039 | 3062 | * IPython/ultraTB.py (ColorTB.__init__): made the color scheme |
|
3040 | 3063 | configurable (it should have always been so). |
|
3041 | 3064 | |
|
3042 | 3065 | 2002-03-26 Fernando Perez <fperez@colorado.edu> |
|
3043 | 3066 | |
|
3044 | 3067 | * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here |
|
3045 | 3068 | and there to fix embedding namespace issues. This should all be |
|
3046 | 3069 | done in a more elegant way. |
|
3047 | 3070 | |
|
3048 | 3071 | 2002-03-25 Fernando Perez <fperez@colorado.edu> |
|
3049 | 3072 | |
|
3050 | 3073 | * IPython/genutils.py (get_home_dir): Try to make it work under |
|
3051 | 3074 | win9x also. |
|
3052 | 3075 | |
|
3053 | 3076 | 2002-03-20 Fernando Perez <fperez@colorado.edu> |
|
3054 | 3077 | |
|
3055 | 3078 | * IPython/Shell.py (IPythonShellEmbed.__init__): leave |
|
3056 | 3079 | sys.displayhook untouched upon __init__. |
|
3057 | 3080 | |
|
3058 | 3081 | 2002-03-19 Fernando Perez <fperez@colorado.edu> |
|
3059 | 3082 | |
|
3060 | 3083 | * Released 0.2.9 (for embedding bug, basically). |
|
3061 | 3084 | |
|
3062 | 3085 | * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit |
|
3063 | 3086 | exceptions so that enclosing shell's state can be restored. |
|
3064 | 3087 | |
|
3065 | 3088 | * Changed magic_gnuplot.py to magic-gnuplot.py to standardize |
|
3066 | 3089 | naming conventions in the .ipython/ dir. |
|
3067 | 3090 | |
|
3068 | 3091 | * IPython/iplib.py (InteractiveShell.init_readline): removed '-' |
|
3069 | 3092 | from delimiters list so filenames with - in them get expanded. |
|
3070 | 3093 | |
|
3071 | 3094 | * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with |
|
3072 | 3095 | sys.displayhook not being properly restored after an embedded call. |
|
3073 | 3096 | |
|
3074 | 3097 | 2002-03-18 Fernando Perez <fperez@colorado.edu> |
|
3075 | 3098 | |
|
3076 | 3099 | * Released 0.2.8 |
|
3077 | 3100 | |
|
3078 | 3101 | * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where |
|
3079 | 3102 | some files weren't being included in a -upgrade. |
|
3080 | 3103 | (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous |
|
3081 | 3104 | on' so that the first tab completes. |
|
3082 | 3105 | (InteractiveShell.handle_magic): fixed bug with spaces around |
|
3083 | 3106 | quotes breaking many magic commands. |
|
3084 | 3107 | |
|
3085 | 3108 | * setup.py: added note about ignoring the syntax error messages at |
|
3086 | 3109 | installation. |
|
3087 | 3110 | |
|
3088 | 3111 | * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished |
|
3089 | 3112 | streamlining the gnuplot interface, now there's only one magic @gp. |
|
3090 | 3113 | |
|
3091 | 3114 | 2002-03-17 Fernando Perez <fperez@colorado.edu> |
|
3092 | 3115 | |
|
3093 | 3116 | * IPython/UserConfig/magic_gnuplot.py: new name for the |
|
3094 | 3117 | example-magic_pm.py file. Much enhanced system, now with a shell |
|
3095 | 3118 | for communicating directly with gnuplot, one command at a time. |
|
3096 | 3119 | |
|
3097 | 3120 | * IPython/Magic.py (Magic.magic_run): added option -n to prevent |
|
3098 | 3121 | setting __name__=='__main__'. |
|
3099 | 3122 | |
|
3100 | 3123 | * IPython/UserConfig/example-magic_pm.py (magic_pm): Added |
|
3101 | 3124 | mini-shell for accessing gnuplot from inside ipython. Should |
|
3102 | 3125 | extend it later for grace access too. Inspired by Arnd's |
|
3103 | 3126 | suggestion. |
|
3104 | 3127 | |
|
3105 | 3128 | * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when |
|
3106 | 3129 | calling magic functions with () in their arguments. Thanks to Arnd |
|
3107 | 3130 | Baecker for pointing this to me. |
|
3108 | 3131 | |
|
3109 | 3132 | * IPython/numutils.py (sum_flat): fixed bug. Would recurse |
|
3110 | 3133 | infinitely for integer or complex arrays (only worked with floats). |
|
3111 | 3134 | |
|
3112 | 3135 | 2002-03-16 Fernando Perez <fperez@colorado.edu> |
|
3113 | 3136 | |
|
3114 | 3137 | * setup.py: Merged setup and setup_windows into a single script |
|
3115 | 3138 | which properly handles things for windows users. |
|
3116 | 3139 | |
|
3117 | 3140 | 2002-03-15 Fernando Perez <fperez@colorado.edu> |
|
3118 | 3141 | |
|
3119 | 3142 | * Big change to the manual: now the magics are all automatically |
|
3120 | 3143 | documented. This information is generated from their docstrings |
|
3121 | 3144 | and put in a latex file included by the manual lyx file. This way |
|
3122 | 3145 | we get always up to date information for the magics. The manual |
|
3123 | 3146 | now also has proper version information, also auto-synced. |
|
3124 | 3147 | |
|
3125 | 3148 | For this to work, an undocumented --magic_docstrings option was added. |
|
3126 | 3149 | |
|
3127 | 3150 | 2002-03-13 Fernando Perez <fperez@colorado.edu> |
|
3128 | 3151 | |
|
3129 | 3152 | * IPython/ultraTB.py (TermColors): fixed problem with dark colors |
|
3130 | 3153 | under CDE terminals. An explicit ;2 color reset is needed in the escapes. |
|
3131 | 3154 | |
|
3132 | 3155 | 2002-03-12 Fernando Perez <fperez@colorado.edu> |
|
3133 | 3156 | |
|
3134 | 3157 | * IPython/ultraTB.py (TermColors): changed color escapes again to |
|
3135 | 3158 | fix the (old, reintroduced) line-wrapping bug. Basically, if |
|
3136 | 3159 | \001..\002 aren't given in the color escapes, lines get wrapped |
|
3137 | 3160 | weirdly. But giving those screws up old xterms and emacs terms. So |
|
3138 | 3161 | I added some logic for emacs terms to be ok, but I can't identify old |
|
3139 | 3162 | xterms separately ($TERM=='xterm' for many terminals, like konsole). |
|
3140 | 3163 | |
|
3141 | 3164 | 2002-03-10 Fernando Perez <fperez@colorado.edu> |
|
3142 | 3165 | |
|
3143 | 3166 | * IPython/usage.py (__doc__): Various documentation cleanups and |
|
3144 | 3167 | updates, both in usage docstrings and in the manual. |
|
3145 | 3168 | |
|
3146 | 3169 | * IPython/Prompts.py (CachedOutput.set_colors): cleanups for |
|
3147 | 3170 | handling of caching. Set minimum acceptabe value for having a |
|
3148 | 3171 | cache at 20 values. |
|
3149 | 3172 | |
|
3150 | 3173 | * IPython/iplib.py (InteractiveShell.user_setup): moved the |
|
3151 | 3174 | install_first_time function to a method, renamed it and added an |
|
3152 | 3175 | 'upgrade' mode. Now people can update their config directory with |
|
3153 | 3176 | a simple command line switch (-upgrade, also new). |
|
3154 | 3177 | |
|
3155 | 3178 | * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to |
|
3156 | 3179 | @file (convenient for automagic users under Python >= 2.2). |
|
3157 | 3180 | Removed @files (it seemed more like a plural than an abbrev. of |
|
3158 | 3181 | 'file show'). |
|
3159 | 3182 | |
|
3160 | 3183 | * IPython/iplib.py (install_first_time): Fixed crash if there were |
|
3161 | 3184 | backup files ('~') in .ipython/ install directory. |
|
3162 | 3185 | |
|
3163 | 3186 | * IPython/ipmaker.py (make_IPython): fixes for new prompt |
|
3164 | 3187 | system. Things look fine, but these changes are fairly |
|
3165 | 3188 | intrusive. Test them for a few days. |
|
3166 | 3189 | |
|
3167 | 3190 | * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of |
|
3168 | 3191 | the prompts system. Now all in/out prompt strings are user |
|
3169 | 3192 | controllable. This is particularly useful for embedding, as one |
|
3170 | 3193 | can tag embedded instances with particular prompts. |
|
3171 | 3194 | |
|
3172 | 3195 | Also removed global use of sys.ps1/2, which now allows nested |
|
3173 | 3196 | embeddings without any problems. Added command-line options for |
|
3174 | 3197 | the prompt strings. |
|
3175 | 3198 | |
|
3176 | 3199 | 2002-03-08 Fernando Perez <fperez@colorado.edu> |
|
3177 | 3200 | |
|
3178 | 3201 | * IPython/UserConfig/example-embed-short.py (ipshell): added |
|
3179 | 3202 | example file with the bare minimum code for embedding. |
|
3180 | 3203 | |
|
3181 | 3204 | * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added |
|
3182 | 3205 | functionality for the embeddable shell to be activated/deactivated |
|
3183 | 3206 | either globally or at each call. |
|
3184 | 3207 | |
|
3185 | 3208 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of |
|
3186 | 3209 | rewriting the prompt with '--->' for auto-inputs with proper |
|
3187 | 3210 | coloring. Now the previous UGLY hack in handle_auto() is gone, and |
|
3188 | 3211 | this is handled by the prompts class itself, as it should. |
|
3189 | 3212 | |
|
3190 | 3213 | 2002-03-05 Fernando Perez <fperez@colorado.edu> |
|
3191 | 3214 | |
|
3192 | 3215 | * IPython/Magic.py (Magic.magic_logstart): Changed @log to |
|
3193 | 3216 | @logstart to avoid name clashes with the math log function. |
|
3194 | 3217 | |
|
3195 | 3218 | * Big updates to X/Emacs section of the manual. |
|
3196 | 3219 | |
|
3197 | 3220 | * Removed ipython_emacs. Milan explained to me how to pass |
|
3198 | 3221 | arguments to ipython through Emacs. Some day I'm going to end up |
|
3199 | 3222 | learning some lisp... |
|
3200 | 3223 | |
|
3201 | 3224 | 2002-03-04 Fernando Perez <fperez@colorado.edu> |
|
3202 | 3225 | |
|
3203 | 3226 | * IPython/ipython_emacs: Created script to be used as the |
|
3204 | 3227 | py-python-command Emacs variable so we can pass IPython |
|
3205 | 3228 | parameters. I can't figure out how to tell Emacs directly to pass |
|
3206 | 3229 | parameters to IPython, so a dummy shell script will do it. |
|
3207 | 3230 | |
|
3208 | 3231 | Other enhancements made for things to work better under Emacs' |
|
3209 | 3232 | various types of terminals. Many thanks to Milan Zamazal |
|
3210 | 3233 | <pdm-AT-zamazal.org> for all the suggestions and pointers. |
|
3211 | 3234 | |
|
3212 | 3235 | 2002-03-01 Fernando Perez <fperez@colorado.edu> |
|
3213 | 3236 | |
|
3214 | 3237 | * IPython/ipmaker.py (make_IPython): added a --readline! option so |
|
3215 | 3238 | that loading of readline is now optional. This gives better |
|
3216 | 3239 | control to emacs users. |
|
3217 | 3240 | |
|
3218 | 3241 | * IPython/ultraTB.py (__date__): Modified color escape sequences |
|
3219 | 3242 | and now things work fine under xterm and in Emacs' term buffers |
|
3220 | 3243 | (though not shell ones). Well, in emacs you get colors, but all |
|
3221 | 3244 | seem to be 'light' colors (no difference between dark and light |
|
3222 | 3245 | ones). But the garbage chars are gone, and also in xterms. It |
|
3223 | 3246 | seems that now I'm using 'cleaner' ansi sequences. |
|
3224 | 3247 | |
|
3225 | 3248 | 2002-02-21 Fernando Perez <fperez@colorado.edu> |
|
3226 | 3249 | |
|
3227 | 3250 | * Released 0.2.7 (mainly to publish the scoping fix). |
|
3228 | 3251 | |
|
3229 | 3252 | * IPython/Logger.py (Logger.logstate): added. A corresponding |
|
3230 | 3253 | @logstate magic was created. |
|
3231 | 3254 | |
|
3232 | 3255 | * IPython/Magic.py: fixed nested scoping problem under Python |
|
3233 | 3256 | 2.1.x (automagic wasn't working). |
|
3234 | 3257 | |
|
3235 | 3258 | 2002-02-20 Fernando Perez <fperez@colorado.edu> |
|
3236 | 3259 | |
|
3237 | 3260 | * Released 0.2.6. |
|
3238 | 3261 | |
|
3239 | 3262 | * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet' |
|
3240 | 3263 | option so that logs can come out without any headers at all. |
|
3241 | 3264 | |
|
3242 | 3265 | * IPython/UserConfig/ipythonrc-scipy.py: created a profile for |
|
3243 | 3266 | SciPy. |
|
3244 | 3267 | |
|
3245 | 3268 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so |
|
3246 | 3269 | that embedded IPython calls don't require vars() to be explicitly |
|
3247 | 3270 | passed. Now they are extracted from the caller's frame (code |
|
3248 | 3271 | snatched from Eric Jones' weave). Added better documentation to |
|
3249 | 3272 | the section on embedding and the example file. |
|
3250 | 3273 | |
|
3251 | 3274 | * IPython/genutils.py (page): Changed so that under emacs, it just |
|
3252 | 3275 | prints the string. You can then page up and down in the emacs |
|
3253 | 3276 | buffer itself. This is how the builtin help() works. |
|
3254 | 3277 | |
|
3255 | 3278 | * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with |
|
3256 | 3279 | macro scoping: macros need to be executed in the user's namespace |
|
3257 | 3280 | to work as if they had been typed by the user. |
|
3258 | 3281 | |
|
3259 | 3282 | * IPython/Magic.py (Magic.magic_macro): Changed macros so they |
|
3260 | 3283 | execute automatically (no need to type 'exec...'). They then |
|
3261 | 3284 | behave like 'true macros'. The printing system was also modified |
|
3262 | 3285 | for this to work. |
|
3263 | 3286 | |
|
3264 | 3287 | 2002-02-19 Fernando Perez <fperez@colorado.edu> |
|
3265 | 3288 | |
|
3266 | 3289 | * IPython/genutils.py (page_file): new function for paging files |
|
3267 | 3290 | in an OS-independent way. Also necessary for file viewing to work |
|
3268 | 3291 | well inside Emacs buffers. |
|
3269 | 3292 | (page): Added checks for being in an emacs buffer. |
|
3270 | 3293 | (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed |
|
3271 | 3294 | same bug in iplib. |
|
3272 | 3295 | |
|
3273 | 3296 | 2002-02-18 Fernando Perez <fperez@colorado.edu> |
|
3274 | 3297 | |
|
3275 | 3298 | * IPython/iplib.py (InteractiveShell.init_readline): modified use |
|
3276 | 3299 | of readline so that IPython can work inside an Emacs buffer. |
|
3277 | 3300 | |
|
3278 | 3301 | * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to |
|
3279 | 3302 | method signatures (they weren't really bugs, but it looks cleaner |
|
3280 | 3303 | and keeps PyChecker happy). |
|
3281 | 3304 | |
|
3282 | 3305 | * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP |
|
3283 | 3306 | for implementing various user-defined hooks. Currently only |
|
3284 | 3307 | display is done. |
|
3285 | 3308 | |
|
3286 | 3309 | * IPython/Prompts.py (CachedOutput._display): changed display |
|
3287 | 3310 | functions so that they can be dynamically changed by users easily. |
|
3288 | 3311 | |
|
3289 | 3312 | * IPython/Extensions/numeric_formats.py (num_display): added an |
|
3290 | 3313 | extension for printing NumPy arrays in flexible manners. It |
|
3291 | 3314 | doesn't do anything yet, but all the structure is in |
|
3292 | 3315 | place. Ultimately the plan is to implement output format control |
|
3293 | 3316 | like in Octave. |
|
3294 | 3317 | |
|
3295 | 3318 | * IPython/Magic.py (Magic.lsmagic): changed so that bound magic |
|
3296 | 3319 | methods are found at run-time by all the automatic machinery. |
|
3297 | 3320 | |
|
3298 | 3321 | 2002-02-17 Fernando Perez <fperez@colorado.edu> |
|
3299 | 3322 | |
|
3300 | 3323 | * setup_Windows.py (make_shortcut): documented. Cleaned up the |
|
3301 | 3324 | whole file a little. |
|
3302 | 3325 | |
|
3303 | 3326 | * ToDo: closed this document. Now there's a new_design.lyx |
|
3304 | 3327 | document for all new ideas. Added making a pdf of it for the |
|
3305 | 3328 | end-user distro. |
|
3306 | 3329 | |
|
3307 | 3330 | * IPython/Logger.py (Logger.switch_log): Created this to replace |
|
3308 | 3331 | logon() and logoff(). It also fixes a nasty crash reported by |
|
3309 | 3332 | Philip Hisley <compsys-AT-starpower.net>. Many thanks to him. |
|
3310 | 3333 | |
|
3311 | 3334 | * IPython/iplib.py (complete): got auto-completion to work with |
|
3312 | 3335 | automagic (I had wanted this for a long time). |
|
3313 | 3336 | |
|
3314 | 3337 | * IPython/Magic.py (Magic.magic_files): Added @files as an alias |
|
3315 | 3338 | to @file, since file() is now a builtin and clashes with automagic |
|
3316 | 3339 | for @file. |
|
3317 | 3340 | |
|
3318 | 3341 | * Made some new files: Prompts, CrashHandler, Magic, Logger. All |
|
3319 | 3342 | of this was previously in iplib, which had grown to more than 2000 |
|
3320 | 3343 | lines, way too long. No new functionality, but it makes managing |
|
3321 | 3344 | the code a bit easier. |
|
3322 | 3345 | |
|
3323 | 3346 | * IPython/iplib.py (IPythonCrashHandler.__call__): Added version |
|
3324 | 3347 | information to crash reports. |
|
3325 | 3348 | |
|
3326 | 3349 | 2002-02-12 Fernando Perez <fperez@colorado.edu> |
|
3327 | 3350 | |
|
3328 | 3351 | * Released 0.2.5. |
|
3329 | 3352 | |
|
3330 | 3353 | 2002-02-11 Fernando Perez <fperez@colorado.edu> |
|
3331 | 3354 | |
|
3332 | 3355 | * Wrote a relatively complete Windows installer. It puts |
|
3333 | 3356 | everything in place, creates Start Menu entries and fixes the |
|
3334 | 3357 | color issues. Nothing fancy, but it works. |
|
3335 | 3358 | |
|
3336 | 3359 | 2002-02-10 Fernando Perez <fperez@colorado.edu> |
|
3337 | 3360 | |
|
3338 | 3361 | * IPython/iplib.py (InteractiveShell.safe_execfile): added an |
|
3339 | 3362 | os.path.expanduser() call so that we can type @run ~/myfile.py and |
|
3340 | 3363 | have thigs work as expected. |
|
3341 | 3364 | |
|
3342 | 3365 | * IPython/genutils.py (page): fixed exception handling so things |
|
3343 | 3366 | work both in Unix and Windows correctly. Quitting a pager triggers |
|
3344 | 3367 | an IOError/broken pipe in Unix, and in windows not finding a pager |
|
3345 | 3368 | is also an IOError, so I had to actually look at the return value |
|
3346 | 3369 | of the exception, not just the exception itself. Should be ok now. |
|
3347 | 3370 | |
|
3348 | 3371 | * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme): |
|
3349 | 3372 | modified to allow case-insensitive color scheme changes. |
|
3350 | 3373 | |
|
3351 | 3374 | 2002-02-09 Fernando Perez <fperez@colorado.edu> |
|
3352 | 3375 | |
|
3353 | 3376 | * IPython/genutils.py (native_line_ends): new function to leave |
|
3354 | 3377 | user config files with os-native line-endings. |
|
3355 | 3378 | |
|
3356 | 3379 | * README and manual updates. |
|
3357 | 3380 | |
|
3358 | 3381 | * IPython/genutils.py: fixed unicode bug: use types.StringTypes |
|
3359 | 3382 | instead of StringType to catch Unicode strings. |
|
3360 | 3383 | |
|
3361 | 3384 | * IPython/genutils.py (filefind): fixed bug for paths with |
|
3362 | 3385 | embedded spaces (very common in Windows). |
|
3363 | 3386 | |
|
3364 | 3387 | * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc |
|
3365 | 3388 | files under Windows, so that they get automatically associated |
|
3366 | 3389 | with a text editor. Windows makes it a pain to handle |
|
3367 | 3390 | extension-less files. |
|
3368 | 3391 | |
|
3369 | 3392 | * IPython/iplib.py (InteractiveShell.init_readline): Made the |
|
3370 | 3393 | warning about readline only occur for Posix. In Windows there's no |
|
3371 | 3394 | way to get readline, so why bother with the warning. |
|
3372 | 3395 | |
|
3373 | 3396 | * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__ |
|
3374 | 3397 | for __str__ instead of dir(self), since dir() changed in 2.2. |
|
3375 | 3398 | |
|
3376 | 3399 | * Ported to Windows! Tested on XP, I suspect it should work fine |
|
3377 | 3400 | on NT/2000, but I don't think it will work on 98 et al. That |
|
3378 | 3401 | series of Windows is such a piece of junk anyway that I won't try |
|
3379 | 3402 | porting it there. The XP port was straightforward, showed a few |
|
3380 | 3403 | bugs here and there (fixed all), in particular some string |
|
3381 | 3404 | handling stuff which required considering Unicode strings (which |
|
3382 | 3405 | Windows uses). This is good, but hasn't been too tested :) No |
|
3383 | 3406 | fancy installer yet, I'll put a note in the manual so people at |
|
3384 | 3407 | least make manually a shortcut. |
|
3385 | 3408 | |
|
3386 | 3409 | * IPython/iplib.py (Magic.magic_colors): Unified the color options |
|
3387 | 3410 | into a single one, "colors". This now controls both prompt and |
|
3388 | 3411 | exception color schemes, and can be changed both at startup |
|
3389 | 3412 | (either via command-line switches or via ipythonrc files) and at |
|
3390 | 3413 | runtime, with @colors. |
|
3391 | 3414 | (Magic.magic_run): renamed @prun to @run and removed the old |
|
3392 | 3415 | @run. The two were too similar to warrant keeping both. |
|
3393 | 3416 | |
|
3394 | 3417 | 2002-02-03 Fernando Perez <fperez@colorado.edu> |
|
3395 | 3418 | |
|
3396 | 3419 | * IPython/iplib.py (install_first_time): Added comment on how to |
|
3397 | 3420 | configure the color options for first-time users. Put a <return> |
|
3398 | 3421 | request at the end so that small-terminal users get a chance to |
|
3399 | 3422 | read the startup info. |
|
3400 | 3423 | |
|
3401 | 3424 | 2002-01-23 Fernando Perez <fperez@colorado.edu> |
|
3402 | 3425 | |
|
3403 | 3426 | * IPython/iplib.py (CachedOutput.update): Changed output memory |
|
3404 | 3427 | variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For |
|
3405 | 3428 | input history we still use _i. Did this b/c these variable are |
|
3406 | 3429 | very commonly used in interactive work, so the less we need to |
|
3407 | 3430 | type the better off we are. |
|
3408 | 3431 | (Magic.magic_prun): updated @prun to better handle the namespaces |
|
3409 | 3432 | the file will run in, including a fix for __name__ not being set |
|
3410 | 3433 | before. |
|
3411 | 3434 | |
|
3412 | 3435 | 2002-01-20 Fernando Perez <fperez@colorado.edu> |
|
3413 | 3436 | |
|
3414 | 3437 | * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of |
|
3415 | 3438 | extra garbage for Python 2.2. Need to look more carefully into |
|
3416 | 3439 | this later. |
|
3417 | 3440 | |
|
3418 | 3441 | 2002-01-19 Fernando Perez <fperez@colorado.edu> |
|
3419 | 3442 | |
|
3420 | 3443 | * IPython/iplib.py (InteractiveShell.showtraceback): fixed to |
|
3421 | 3444 | display SyntaxError exceptions properly formatted when they occur |
|
3422 | 3445 | (they can be triggered by imported code). |
|
3423 | 3446 | |
|
3424 | 3447 | 2002-01-18 Fernando Perez <fperez@colorado.edu> |
|
3425 | 3448 | |
|
3426 | 3449 | * IPython/iplib.py (InteractiveShell.safe_execfile): now |
|
3427 | 3450 | SyntaxError exceptions are reported nicely formatted, instead of |
|
3428 | 3451 | spitting out only offset information as before. |
|
3429 | 3452 | (Magic.magic_prun): Added the @prun function for executing |
|
3430 | 3453 | programs with command line args inside IPython. |
|
3431 | 3454 | |
|
3432 | 3455 | 2002-01-16 Fernando Perez <fperez@colorado.edu> |
|
3433 | 3456 | |
|
3434 | 3457 | * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist |
|
3435 | 3458 | to *not* include the last item given in a range. This brings their |
|
3436 | 3459 | behavior in line with Python's slicing: |
|
3437 | 3460 | a[n1:n2] -> a[n1]...a[n2-1] |
|
3438 | 3461 | It may be a bit less convenient, but I prefer to stick to Python's |
|
3439 | 3462 | conventions *everywhere*, so users never have to wonder. |
|
3440 | 3463 | (Magic.magic_macro): Added @macro function to ease the creation of |
|
3441 | 3464 | macros. |
|
3442 | 3465 | |
|
3443 | 3466 | 2002-01-05 Fernando Perez <fperez@colorado.edu> |
|
3444 | 3467 | |
|
3445 | 3468 | * Released 0.2.4. |
|
3446 | 3469 | |
|
3447 | 3470 | * IPython/iplib.py (Magic.magic_pdef): |
|
3448 | 3471 | (InteractiveShell.safe_execfile): report magic lines and error |
|
3449 | 3472 | lines without line numbers so one can easily copy/paste them for |
|
3450 | 3473 | re-execution. |
|
3451 | 3474 | |
|
3452 | 3475 | * Updated manual with recent changes. |
|
3453 | 3476 | |
|
3454 | 3477 | * IPython/iplib.py (Magic.magic_oinfo): added constructor |
|
3455 | 3478 | docstring printing when class? is called. Very handy for knowing |
|
3456 | 3479 | how to create class instances (as long as __init__ is well |
|
3457 | 3480 | documented, of course :) |
|
3458 | 3481 | (Magic.magic_doc): print both class and constructor docstrings. |
|
3459 | 3482 | (Magic.magic_pdef): give constructor info if passed a class and |
|
3460 | 3483 | __call__ info for callable object instances. |
|
3461 | 3484 | |
|
3462 | 3485 | 2002-01-04 Fernando Perez <fperez@colorado.edu> |
|
3463 | 3486 | |
|
3464 | 3487 | * Made deep_reload() off by default. It doesn't always work |
|
3465 | 3488 | exactly as intended, so it's probably safer to have it off. It's |
|
3466 | 3489 | still available as dreload() anyway, so nothing is lost. |
|
3467 | 3490 | |
|
3468 | 3491 | 2002-01-02 Fernando Perez <fperez@colorado.edu> |
|
3469 | 3492 | |
|
3470 | 3493 | * Released 0.2.3 (contacted R.Singh at CU about biopython course, |
|
3471 | 3494 | so I wanted an updated release). |
|
3472 | 3495 | |
|
3473 | 3496 | 2001-12-27 Fernando Perez <fperez@colorado.edu> |
|
3474 | 3497 | |
|
3475 | 3498 | * IPython/iplib.py (InteractiveShell.interact): Added the original |
|
3476 | 3499 | code from 'code.py' for this module in order to change the |
|
3477 | 3500 | handling of a KeyboardInterrupt. This was necessary b/c otherwise |
|
3478 | 3501 | the history cache would break when the user hit Ctrl-C, and |
|
3479 | 3502 | interact() offers no way to add any hooks to it. |
|
3480 | 3503 | |
|
3481 | 3504 | 2001-12-23 Fernando Perez <fperez@colorado.edu> |
|
3482 | 3505 | |
|
3483 | 3506 | * setup.py: added check for 'MANIFEST' before trying to remove |
|
3484 | 3507 | it. Thanks to Sean Reifschneider. |
|
3485 | 3508 | |
|
3486 | 3509 | 2001-12-22 Fernando Perez <fperez@colorado.edu> |
|
3487 | 3510 | |
|
3488 | 3511 | * Released 0.2.2. |
|
3489 | 3512 | |
|
3490 | 3513 | * Finished (reasonably) writing the manual. Later will add the |
|
3491 | 3514 | python-standard navigation stylesheets, but for the time being |
|
3492 | 3515 | it's fairly complete. Distribution will include html and pdf |
|
3493 | 3516 | versions. |
|
3494 | 3517 | |
|
3495 | 3518 | * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu |
|
3496 | 3519 | (MayaVi author). |
|
3497 | 3520 | |
|
3498 | 3521 | 2001-12-21 Fernando Perez <fperez@colorado.edu> |
|
3499 | 3522 | |
|
3500 | 3523 | * Released 0.2.1. Barring any nasty bugs, this is it as far as a |
|
3501 | 3524 | good public release, I think (with the manual and the distutils |
|
3502 | 3525 | installer). The manual can use some work, but that can go |
|
3503 | 3526 | slowly. Otherwise I think it's quite nice for end users. Next |
|
3504 | 3527 | summer, rewrite the guts of it... |
|
3505 | 3528 | |
|
3506 | 3529 | * Changed format of ipythonrc files to use whitespace as the |
|
3507 | 3530 | separator instead of an explicit '='. Cleaner. |
|
3508 | 3531 | |
|
3509 | 3532 | 2001-12-20 Fernando Perez <fperez@colorado.edu> |
|
3510 | 3533 | |
|
3511 | 3534 | * Started a manual in LyX. For now it's just a quick merge of the |
|
3512 | 3535 | various internal docstrings and READMEs. Later it may grow into a |
|
3513 | 3536 | nice, full-blown manual. |
|
3514 | 3537 | |
|
3515 | 3538 | * Set up a distutils based installer. Installation should now be |
|
3516 | 3539 | trivially simple for end-users. |
|
3517 | 3540 | |
|
3518 | 3541 | 2001-12-11 Fernando Perez <fperez@colorado.edu> |
|
3519 | 3542 | |
|
3520 | 3543 | * Released 0.2.0. First public release, announced it at |
|
3521 | 3544 | comp.lang.python. From now on, just bugfixes... |
|
3522 | 3545 | |
|
3523 | 3546 | * Went through all the files, set copyright/license notices and |
|
3524 | 3547 | cleaned up things. Ready for release. |
|
3525 | 3548 | |
|
3526 | 3549 | 2001-12-10 Fernando Perez <fperez@colorado.edu> |
|
3527 | 3550 | |
|
3528 | 3551 | * Changed the first-time installer not to use tarfiles. It's more |
|
3529 | 3552 | robust now and less unix-dependent. Also makes it easier for |
|
3530 | 3553 | people to later upgrade versions. |
|
3531 | 3554 | |
|
3532 | 3555 | * Changed @exit to @abort to reflect the fact that it's pretty |
|
3533 | 3556 | brutal (a sys.exit()). The difference between @abort and Ctrl-D |
|
3534 | 3557 | becomes significant only when IPyhton is embedded: in that case, |
|
3535 | 3558 | C-D closes IPython only, but @abort kills the enclosing program |
|
3536 | 3559 | too (unless it had called IPython inside a try catching |
|
3537 | 3560 | SystemExit). |
|
3538 | 3561 | |
|
3539 | 3562 | * Created Shell module which exposes the actuall IPython Shell |
|
3540 | 3563 | classes, currently the normal and the embeddable one. This at |
|
3541 | 3564 | least offers a stable interface we won't need to change when |
|
3542 | 3565 | (later) the internals are rewritten. That rewrite will be confined |
|
3543 | 3566 | to iplib and ipmaker, but the Shell interface should remain as is. |
|
3544 | 3567 | |
|
3545 | 3568 | * Added embed module which offers an embeddable IPShell object, |
|
3546 | 3569 | useful to fire up IPython *inside* a running program. Great for |
|
3547 | 3570 | debugging or dynamical data analysis. |
|
3548 | 3571 | |
|
3549 | 3572 | 2001-12-08 Fernando Perez <fperez@colorado.edu> |
|
3550 | 3573 | |
|
3551 | 3574 | * Fixed small bug preventing seeing info from methods of defined |
|
3552 | 3575 | objects (incorrect namespace in _ofind()). |
|
3553 | 3576 | |
|
3554 | 3577 | * Documentation cleanup. Moved the main usage docstrings to a |
|
3555 | 3578 | separate file, usage.py (cleaner to maintain, and hopefully in the |
|
3556 | 3579 | future some perlpod-like way of producing interactive, man and |
|
3557 | 3580 | html docs out of it will be found). |
|
3558 | 3581 | |
|
3559 | 3582 | * Added @profile to see your profile at any time. |
|
3560 | 3583 | |
|
3561 | 3584 | * Added @p as an alias for 'print'. It's especially convenient if |
|
3562 | 3585 | using automagic ('p x' prints x). |
|
3563 | 3586 | |
|
3564 | 3587 | * Small cleanups and fixes after a pychecker run. |
|
3565 | 3588 | |
|
3566 | 3589 | * Changed the @cd command to handle @cd - and @cd -<n> for |
|
3567 | 3590 | visiting any directory in _dh. |
|
3568 | 3591 | |
|
3569 | 3592 | * Introduced _dh, a history of visited directories. @dhist prints |
|
3570 | 3593 | it out with numbers. |
|
3571 | 3594 | |
|
3572 | 3595 | 2001-12-07 Fernando Perez <fperez@colorado.edu> |
|
3573 | 3596 | |
|
3574 | 3597 | * Released 0.1.22 |
|
3575 | 3598 | |
|
3576 | 3599 | * Made initialization a bit more robust against invalid color |
|
3577 | 3600 | options in user input (exit, not traceback-crash). |
|
3578 | 3601 | |
|
3579 | 3602 | * Changed the bug crash reporter to write the report only in the |
|
3580 | 3603 | user's .ipython directory. That way IPython won't litter people's |
|
3581 | 3604 | hard disks with crash files all over the place. Also print on |
|
3582 | 3605 | screen the necessary mail command. |
|
3583 | 3606 | |
|
3584 | 3607 | * With the new ultraTB, implemented LightBG color scheme for light |
|
3585 | 3608 | background terminals. A lot of people like white backgrounds, so I |
|
3586 | 3609 | guess we should at least give them something readable. |
|
3587 | 3610 | |
|
3588 | 3611 | 2001-12-06 Fernando Perez <fperez@colorado.edu> |
|
3589 | 3612 | |
|
3590 | 3613 | * Modified the structure of ultraTB. Now there's a proper class |
|
3591 | 3614 | for tables of color schemes which allow adding schemes easily and |
|
3592 | 3615 | switching the active scheme without creating a new instance every |
|
3593 | 3616 | time (which was ridiculous). The syntax for creating new schemes |
|
3594 | 3617 | is also cleaner. I think ultraTB is finally done, with a clean |
|
3595 | 3618 | class structure. Names are also much cleaner (now there's proper |
|
3596 | 3619 | color tables, no need for every variable to also have 'color' in |
|
3597 | 3620 | its name). |
|
3598 | 3621 | |
|
3599 | 3622 | * Broke down genutils into separate files. Now genutils only |
|
3600 | 3623 | contains utility functions, and classes have been moved to their |
|
3601 | 3624 | own files (they had enough independent functionality to warrant |
|
3602 | 3625 | it): ConfigLoader, OutputTrap, Struct. |
|
3603 | 3626 | |
|
3604 | 3627 | 2001-12-05 Fernando Perez <fperez@colorado.edu> |
|
3605 | 3628 | |
|
3606 | 3629 | * IPython turns 21! Released version 0.1.21, as a candidate for |
|
3607 | 3630 | public consumption. If all goes well, release in a few days. |
|
3608 | 3631 | |
|
3609 | 3632 | * Fixed path bug (files in Extensions/ directory wouldn't be found |
|
3610 | 3633 | unless IPython/ was explicitly in sys.path). |
|
3611 | 3634 | |
|
3612 | 3635 | * Extended the FlexCompleter class as MagicCompleter to allow |
|
3613 | 3636 | completion of @-starting lines. |
|
3614 | 3637 | |
|
3615 | 3638 | * Created __release__.py file as a central repository for release |
|
3616 | 3639 | info that other files can read from. |
|
3617 | 3640 | |
|
3618 | 3641 | * Fixed small bug in logging: when logging was turned on in |
|
3619 | 3642 | mid-session, old lines with special meanings (!@?) were being |
|
3620 | 3643 | logged without the prepended comment, which is necessary since |
|
3621 | 3644 | they are not truly valid python syntax. This should make session |
|
3622 | 3645 | restores produce less errors. |
|
3623 | 3646 | |
|
3624 | 3647 | * The namespace cleanup forced me to make a FlexCompleter class |
|
3625 | 3648 | which is nothing but a ripoff of rlcompleter, but with selectable |
|
3626 | 3649 | namespace (rlcompleter only works in __main__.__dict__). I'll try |
|
3627 | 3650 | to submit a note to the authors to see if this change can be |
|
3628 | 3651 | incorporated in future rlcompleter releases (Dec.6: done) |
|
3629 | 3652 | |
|
3630 | 3653 | * More fixes to namespace handling. It was a mess! Now all |
|
3631 | 3654 | explicit references to __main__.__dict__ are gone (except when |
|
3632 | 3655 | really needed) and everything is handled through the namespace |
|
3633 | 3656 | dicts in the IPython instance. We seem to be getting somewhere |
|
3634 | 3657 | with this, finally... |
|
3635 | 3658 | |
|
3636 | 3659 | * Small documentation updates. |
|
3637 | 3660 | |
|
3638 | 3661 | * Created the Extensions directory under IPython (with an |
|
3639 | 3662 | __init__.py). Put the PhysicalQ stuff there. This directory should |
|
3640 | 3663 | be used for all special-purpose extensions. |
|
3641 | 3664 | |
|
3642 | 3665 | * File renaming: |
|
3643 | 3666 | ipythonlib --> ipmaker |
|
3644 | 3667 | ipplib --> iplib |
|
3645 | 3668 | This makes a bit more sense in terms of what these files actually do. |
|
3646 | 3669 | |
|
3647 | 3670 | * Moved all the classes and functions in ipythonlib to ipplib, so |
|
3648 | 3671 | now ipythonlib only has make_IPython(). This will ease up its |
|
3649 | 3672 | splitting in smaller functional chunks later. |
|
3650 | 3673 | |
|
3651 | 3674 | * Cleaned up (done, I think) output of @whos. Better column |
|
3652 | 3675 | formatting, and now shows str(var) for as much as it can, which is |
|
3653 | 3676 | typically what one gets with a 'print var'. |
|
3654 | 3677 | |
|
3655 | 3678 | 2001-12-04 Fernando Perez <fperez@colorado.edu> |
|
3656 | 3679 | |
|
3657 | 3680 | * Fixed namespace problems. Now builtin/IPyhton/user names get |
|
3658 | 3681 | properly reported in their namespace. Internal namespace handling |
|
3659 | 3682 | is finally getting decent (not perfect yet, but much better than |
|
3660 | 3683 | the ad-hoc mess we had). |
|
3661 | 3684 | |
|
3662 | 3685 | * Removed -exit option. If people just want to run a python |
|
3663 | 3686 | script, that's what the normal interpreter is for. Less |
|
3664 | 3687 | unnecessary options, less chances for bugs. |
|
3665 | 3688 | |
|
3666 | 3689 | * Added a crash handler which generates a complete post-mortem if |
|
3667 | 3690 | IPython crashes. This will help a lot in tracking bugs down the |
|
3668 | 3691 | road. |
|
3669 | 3692 | |
|
3670 | 3693 | * Fixed nasty bug in auto-evaluation part of prefilter(). Names |
|
3671 | 3694 | which were boud to functions being reassigned would bypass the |
|
3672 | 3695 | logger, breaking the sync of _il with the prompt counter. This |
|
3673 | 3696 | would then crash IPython later when a new line was logged. |
|
3674 | 3697 | |
|
3675 | 3698 | 2001-12-02 Fernando Perez <fperez@colorado.edu> |
|
3676 | 3699 | |
|
3677 | 3700 | * Made IPython a package. This means people don't have to clutter |
|
3678 | 3701 | their sys.path with yet another directory. Changed the INSTALL |
|
3679 | 3702 | file accordingly. |
|
3680 | 3703 | |
|
3681 | 3704 | * Cleaned up the output of @who_ls, @who and @whos. @who_ls now |
|
3682 | 3705 | sorts its output (so @who shows it sorted) and @whos formats the |
|
3683 | 3706 | table according to the width of the first column. Nicer, easier to |
|
3684 | 3707 | read. Todo: write a generic table_format() which takes a list of |
|
3685 | 3708 | lists and prints it nicely formatted, with optional row/column |
|
3686 | 3709 | separators and proper padding and justification. |
|
3687 | 3710 | |
|
3688 | 3711 | * Released 0.1.20 |
|
3689 | 3712 | |
|
3690 | 3713 | * Fixed bug in @log which would reverse the inputcache list (a |
|
3691 | 3714 | copy operation was missing). |
|
3692 | 3715 | |
|
3693 | 3716 | * Code cleanup. @config was changed to use page(). Better, since |
|
3694 | 3717 | its output is always quite long. |
|
3695 | 3718 | |
|
3696 | 3719 | * Itpl is back as a dependency. I was having too many problems |
|
3697 | 3720 | getting the parametric aliases to work reliably, and it's just |
|
3698 | 3721 | easier to code weird string operations with it than playing %()s |
|
3699 | 3722 | games. It's only ~6k, so I don't think it's too big a deal. |
|
3700 | 3723 | |
|
3701 | 3724 | * Found (and fixed) a very nasty bug with history. !lines weren't |
|
3702 | 3725 | getting cached, and the out of sync caches would crash |
|
3703 | 3726 | IPython. Fixed it by reorganizing the prefilter/handlers/logger |
|
3704 | 3727 | division of labor a bit better. Bug fixed, cleaner structure. |
|
3705 | 3728 | |
|
3706 | 3729 | 2001-12-01 Fernando Perez <fperez@colorado.edu> |
|
3707 | 3730 | |
|
3708 | 3731 | * Released 0.1.19 |
|
3709 | 3732 | |
|
3710 | 3733 | * Added option -n to @hist to prevent line number printing. Much |
|
3711 | 3734 | easier to copy/paste code this way. |
|
3712 | 3735 | |
|
3713 | 3736 | * Created global _il to hold the input list. Allows easy |
|
3714 | 3737 | re-execution of blocks of code by slicing it (inspired by Janko's |
|
3715 | 3738 | comment on 'macros'). |
|
3716 | 3739 | |
|
3717 | 3740 | * Small fixes and doc updates. |
|
3718 | 3741 | |
|
3719 | 3742 | * Rewrote @history function (was @h). Renamed it to @hist, @h is |
|
3720 | 3743 | much too fragile with automagic. Handles properly multi-line |
|
3721 | 3744 | statements and takes parameters. |
|
3722 | 3745 | |
|
3723 | 3746 | 2001-11-30 Fernando Perez <fperez@colorado.edu> |
|
3724 | 3747 | |
|
3725 | 3748 | * Version 0.1.18 released. |
|
3726 | 3749 | |
|
3727 | 3750 | * Fixed nasty namespace bug in initial module imports. |
|
3728 | 3751 | |
|
3729 | 3752 | * Added copyright/license notes to all code files (except |
|
3730 | 3753 | DPyGetOpt). For the time being, LGPL. That could change. |
|
3731 | 3754 | |
|
3732 | 3755 | * Rewrote a much nicer README, updated INSTALL, cleaned up |
|
3733 | 3756 | ipythonrc-* samples. |
|
3734 | 3757 | |
|
3735 | 3758 | * Overall code/documentation cleanup. Basically ready for |
|
3736 | 3759 | release. Only remaining thing: licence decision (LGPL?). |
|
3737 | 3760 | |
|
3738 | 3761 | * Converted load_config to a class, ConfigLoader. Now recursion |
|
3739 | 3762 | control is better organized. Doesn't include the same file twice. |
|
3740 | 3763 | |
|
3741 | 3764 | 2001-11-29 Fernando Perez <fperez@colorado.edu> |
|
3742 | 3765 | |
|
3743 | 3766 | * Got input history working. Changed output history variables from |
|
3744 | 3767 | _p to _o so that _i is for input and _o for output. Just cleaner |
|
3745 | 3768 | convention. |
|
3746 | 3769 | |
|
3747 | 3770 | * Implemented parametric aliases. This pretty much allows the |
|
3748 | 3771 | alias system to offer full-blown shell convenience, I think. |
|
3749 | 3772 | |
|
3750 | 3773 | * Version 0.1.17 released, 0.1.18 opened. |
|
3751 | 3774 | |
|
3752 | 3775 | * dot_ipython/ipythonrc (alias): added documentation. |
|
3753 | 3776 | (xcolor): Fixed small bug (xcolors -> xcolor) |
|
3754 | 3777 | |
|
3755 | 3778 | * Changed the alias system. Now alias is a magic command to define |
|
3756 | 3779 | aliases just like the shell. Rationale: the builtin magics should |
|
3757 | 3780 | be there for things deeply connected to IPython's |
|
3758 | 3781 | architecture. And this is a much lighter system for what I think |
|
3759 | 3782 | is the really important feature: allowing users to define quickly |
|
3760 | 3783 | magics that will do shell things for them, so they can customize |
|
3761 | 3784 | IPython easily to match their work habits. If someone is really |
|
3762 | 3785 | desperate to have another name for a builtin alias, they can |
|
3763 | 3786 | always use __IP.magic_newname = __IP.magic_oldname. Hackish but |
|
3764 | 3787 | works. |
|
3765 | 3788 | |
|
3766 | 3789 | 2001-11-28 Fernando Perez <fperez@colorado.edu> |
|
3767 | 3790 | |
|
3768 | 3791 | * Changed @file so that it opens the source file at the proper |
|
3769 | 3792 | line. Since it uses less, if your EDITOR environment is |
|
3770 | 3793 | configured, typing v will immediately open your editor of choice |
|
3771 | 3794 | right at the line where the object is defined. Not as quick as |
|
3772 | 3795 | having a direct @edit command, but for all intents and purposes it |
|
3773 | 3796 | works. And I don't have to worry about writing @edit to deal with |
|
3774 | 3797 | all the editors, less does that. |
|
3775 | 3798 | |
|
3776 | 3799 | * Version 0.1.16 released, 0.1.17 opened. |
|
3777 | 3800 | |
|
3778 | 3801 | * Fixed some nasty bugs in the page/page_dumb combo that could |
|
3779 | 3802 | crash IPython. |
|
3780 | 3803 | |
|
3781 | 3804 | 2001-11-27 Fernando Perez <fperez@colorado.edu> |
|
3782 | 3805 | |
|
3783 | 3806 | * Version 0.1.15 released, 0.1.16 opened. |
|
3784 | 3807 | |
|
3785 | 3808 | * Finally got ? and ?? to work for undefined things: now it's |
|
3786 | 3809 | possible to type {}.get? and get information about the get method |
|
3787 | 3810 | of dicts, or os.path? even if only os is defined (so technically |
|
3788 | 3811 | os.path isn't). Works at any level. For example, after import os, |
|
3789 | 3812 | os?, os.path?, os.path.abspath? all work. This is great, took some |
|
3790 | 3813 | work in _ofind. |
|
3791 | 3814 | |
|
3792 | 3815 | * Fixed more bugs with logging. The sanest way to do it was to add |
|
3793 | 3816 | to @log a 'mode' parameter. Killed two in one shot (this mode |
|
3794 | 3817 | option was a request of Janko's). I think it's finally clean |
|
3795 | 3818 | (famous last words). |
|
3796 | 3819 | |
|
3797 | 3820 | * Added a page_dumb() pager which does a decent job of paging on |
|
3798 | 3821 | screen, if better things (like less) aren't available. One less |
|
3799 | 3822 | unix dependency (someday maybe somebody will port this to |
|
3800 | 3823 | windows). |
|
3801 | 3824 | |
|
3802 | 3825 | * Fixed problem in magic_log: would lock of logging out if log |
|
3803 | 3826 | creation failed (because it would still think it had succeeded). |
|
3804 | 3827 | |
|
3805 | 3828 | * Improved the page() function using curses to auto-detect screen |
|
3806 | 3829 | size. Now it can make a much better decision on whether to print |
|
3807 | 3830 | or page a string. Option screen_length was modified: a value 0 |
|
3808 | 3831 | means auto-detect, and that's the default now. |
|
3809 | 3832 | |
|
3810 | 3833 | * Version 0.1.14 released, 0.1.15 opened. I think this is ready to |
|
3811 | 3834 | go out. I'll test it for a few days, then talk to Janko about |
|
3812 | 3835 | licences and announce it. |
|
3813 | 3836 | |
|
3814 | 3837 | * Fixed the length of the auto-generated ---> prompt which appears |
|
3815 | 3838 | for auto-parens and auto-quotes. Getting this right isn't trivial, |
|
3816 | 3839 | with all the color escapes, different prompt types and optional |
|
3817 | 3840 | separators. But it seems to be working in all the combinations. |
|
3818 | 3841 | |
|
3819 | 3842 | 2001-11-26 Fernando Perez <fperez@colorado.edu> |
|
3820 | 3843 | |
|
3821 | 3844 | * Wrote a regexp filter to get option types from the option names |
|
3822 | 3845 | string. This eliminates the need to manually keep two duplicate |
|
3823 | 3846 | lists. |
|
3824 | 3847 | |
|
3825 | 3848 | * Removed the unneeded check_option_names. Now options are handled |
|
3826 | 3849 | in a much saner manner and it's easy to visually check that things |
|
3827 | 3850 | are ok. |
|
3828 | 3851 | |
|
3829 | 3852 | * Updated version numbers on all files I modified to carry a |
|
3830 | 3853 | notice so Janko and Nathan have clear version markers. |
|
3831 | 3854 | |
|
3832 | 3855 | * Updated docstring for ultraTB with my changes. I should send |
|
3833 | 3856 | this to Nathan. |
|
3834 | 3857 | |
|
3835 | 3858 | * Lots of small fixes. Ran everything through pychecker again. |
|
3836 | 3859 | |
|
3837 | 3860 | * Made loading of deep_reload an cmd line option. If it's not too |
|
3838 | 3861 | kosher, now people can just disable it. With -nodeep_reload it's |
|
3839 | 3862 | still available as dreload(), it just won't overwrite reload(). |
|
3840 | 3863 | |
|
3841 | 3864 | * Moved many options to the no| form (-opt and -noopt |
|
3842 | 3865 | accepted). Cleaner. |
|
3843 | 3866 | |
|
3844 | 3867 | * Changed magic_log so that if called with no parameters, it uses |
|
3845 | 3868 | 'rotate' mode. That way auto-generated logs aren't automatically |
|
3846 | 3869 | over-written. For normal logs, now a backup is made if it exists |
|
3847 | 3870 | (only 1 level of backups). A new 'backup' mode was added to the |
|
3848 | 3871 | Logger class to support this. This was a request by Janko. |
|
3849 | 3872 | |
|
3850 | 3873 | * Added @logoff/@logon to stop/restart an active log. |
|
3851 | 3874 | |
|
3852 | 3875 | * Fixed a lot of bugs in log saving/replay. It was pretty |
|
3853 | 3876 | broken. Now special lines (!@,/) appear properly in the command |
|
3854 | 3877 | history after a log replay. |
|
3855 | 3878 | |
|
3856 | 3879 | * Tried and failed to implement full session saving via pickle. My |
|
3857 | 3880 | idea was to pickle __main__.__dict__, but modules can't be |
|
3858 | 3881 | pickled. This would be a better alternative to replaying logs, but |
|
3859 | 3882 | seems quite tricky to get to work. Changed -session to be called |
|
3860 | 3883 | -logplay, which more accurately reflects what it does. And if we |
|
3861 | 3884 | ever get real session saving working, -session is now available. |
|
3862 | 3885 | |
|
3863 | 3886 | * Implemented color schemes for prompts also. As for tracebacks, |
|
3864 | 3887 | currently only NoColor and Linux are supported. But now the |
|
3865 | 3888 | infrastructure is in place, based on a generic ColorScheme |
|
3866 | 3889 | class. So writing and activating new schemes both for the prompts |
|
3867 | 3890 | and the tracebacks should be straightforward. |
|
3868 | 3891 | |
|
3869 | 3892 | * Version 0.1.13 released, 0.1.14 opened. |
|
3870 | 3893 | |
|
3871 | 3894 | * Changed handling of options for output cache. Now counter is |
|
3872 | 3895 | hardwired starting at 1 and one specifies the maximum number of |
|
3873 | 3896 | entries *in the outcache* (not the max prompt counter). This is |
|
3874 | 3897 | much better, since many statements won't increase the cache |
|
3875 | 3898 | count. It also eliminated some confusing options, now there's only |
|
3876 | 3899 | one: cache_size. |
|
3877 | 3900 | |
|
3878 | 3901 | * Added 'alias' magic function and magic_alias option in the |
|
3879 | 3902 | ipythonrc file. Now the user can easily define whatever names he |
|
3880 | 3903 | wants for the magic functions without having to play weird |
|
3881 | 3904 | namespace games. This gives IPython a real shell-like feel. |
|
3882 | 3905 | |
|
3883 | 3906 | * Fixed doc/?/?? for magics. Now all work, in all forms (explicit |
|
3884 | 3907 | @ or not). |
|
3885 | 3908 | |
|
3886 | 3909 | This was one of the last remaining 'visible' bugs (that I know |
|
3887 | 3910 | of). I think if I can clean up the session loading so it works |
|
3888 | 3911 | 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first |
|
3889 | 3912 | about licensing). |
|
3890 | 3913 | |
|
3891 | 3914 | 2001-11-25 Fernando Perez <fperez@colorado.edu> |
|
3892 | 3915 | |
|
3893 | 3916 | * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and |
|
3894 | 3917 | there's a cleaner distinction between what ? and ?? show. |
|
3895 | 3918 | |
|
3896 | 3919 | * Added screen_length option. Now the user can define his own |
|
3897 | 3920 | screen size for page() operations. |
|
3898 | 3921 | |
|
3899 | 3922 | * Implemented magic shell-like functions with automatic code |
|
3900 | 3923 | generation. Now adding another function is just a matter of adding |
|
3901 | 3924 | an entry to a dict, and the function is dynamically generated at |
|
3902 | 3925 | run-time. Python has some really cool features! |
|
3903 | 3926 | |
|
3904 | 3927 | * Renamed many options to cleanup conventions a little. Now all |
|
3905 | 3928 | are lowercase, and only underscores where needed. Also in the code |
|
3906 | 3929 | option name tables are clearer. |
|
3907 | 3930 | |
|
3908 | 3931 | * Changed prompts a little. Now input is 'In [n]:' instead of |
|
3909 | 3932 | 'In[n]:='. This allows it the numbers to be aligned with the |
|
3910 | 3933 | Out[n] numbers, and removes usage of ':=' which doesn't exist in |
|
3911 | 3934 | Python (it was a Mathematica thing). The '...' continuation prompt |
|
3912 | 3935 | was also changed a little to align better. |
|
3913 | 3936 | |
|
3914 | 3937 | * Fixed bug when flushing output cache. Not all _p<n> variables |
|
3915 | 3938 | exist, so their deletion needs to be wrapped in a try: |
|
3916 | 3939 | |
|
3917 | 3940 | * Figured out how to properly use inspect.formatargspec() (it |
|
3918 | 3941 | requires the args preceded by *). So I removed all the code from |
|
3919 | 3942 | _get_pdef in Magic, which was just replicating that. |
|
3920 | 3943 | |
|
3921 | 3944 | * Added test to prefilter to allow redefining magic function names |
|
3922 | 3945 | as variables. This is ok, since the @ form is always available, |
|
3923 | 3946 | but whe should allow the user to define a variable called 'ls' if |
|
3924 | 3947 | he needs it. |
|
3925 | 3948 | |
|
3926 | 3949 | * Moved the ToDo information from README into a separate ToDo. |
|
3927 | 3950 | |
|
3928 | 3951 | * General code cleanup and small bugfixes. I think it's close to a |
|
3929 | 3952 | state where it can be released, obviously with a big 'beta' |
|
3930 | 3953 | warning on it. |
|
3931 | 3954 | |
|
3932 | 3955 | * Got the magic function split to work. Now all magics are defined |
|
3933 | 3956 | in a separate class. It just organizes things a bit, and now |
|
3934 | 3957 | Xemacs behaves nicer (it was choking on InteractiveShell b/c it |
|
3935 | 3958 | was too long). |
|
3936 | 3959 | |
|
3937 | 3960 | * Changed @clear to @reset to avoid potential confusions with |
|
3938 | 3961 | the shell command clear. Also renamed @cl to @clear, which does |
|
3939 | 3962 | exactly what people expect it to from their shell experience. |
|
3940 | 3963 | |
|
3941 | 3964 | Added a check to the @reset command (since it's so |
|
3942 | 3965 | destructive, it's probably a good idea to ask for confirmation). |
|
3943 | 3966 | But now reset only works for full namespace resetting. Since the |
|
3944 | 3967 | del keyword is already there for deleting a few specific |
|
3945 | 3968 | variables, I don't see the point of having a redundant magic |
|
3946 | 3969 | function for the same task. |
|
3947 | 3970 | |
|
3948 | 3971 | 2001-11-24 Fernando Perez <fperez@colorado.edu> |
|
3949 | 3972 | |
|
3950 | 3973 | * Updated the builtin docs (esp. the ? ones). |
|
3951 | 3974 | |
|
3952 | 3975 | * Ran all the code through pychecker. Not terribly impressed with |
|
3953 | 3976 | it: lots of spurious warnings and didn't really find anything of |
|
3954 | 3977 | substance (just a few modules being imported and not used). |
|
3955 | 3978 | |
|
3956 | 3979 | * Implemented the new ultraTB functionality into IPython. New |
|
3957 | 3980 | option: xcolors. This chooses color scheme. xmode now only selects |
|
3958 | 3981 | between Plain and Verbose. Better orthogonality. |
|
3959 | 3982 | |
|
3960 | 3983 | * Large rewrite of ultraTB. Much cleaner now, with a separation of |
|
3961 | 3984 | mode and color scheme for the exception handlers. Now it's |
|
3962 | 3985 | possible to have the verbose traceback with no coloring. |
|
3963 | 3986 | |
|
3964 | 3987 | 2001-11-23 Fernando Perez <fperez@colorado.edu> |
|
3965 | 3988 | |
|
3966 | 3989 | * Version 0.1.12 released, 0.1.13 opened. |
|
3967 | 3990 | |
|
3968 | 3991 | * Removed option to set auto-quote and auto-paren escapes by |
|
3969 | 3992 | user. The chances of breaking valid syntax are just too high. If |
|
3970 | 3993 | someone *really* wants, they can always dig into the code. |
|
3971 | 3994 | |
|
3972 | 3995 | * Made prompt separators configurable. |
|
3973 | 3996 | |
|
3974 | 3997 | 2001-11-22 Fernando Perez <fperez@colorado.edu> |
|
3975 | 3998 | |
|
3976 | 3999 | * Small bugfixes in many places. |
|
3977 | 4000 | |
|
3978 | 4001 | * Removed the MyCompleter class from ipplib. It seemed redundant |
|
3979 | 4002 | with the C-p,C-n history search functionality. Less code to |
|
3980 | 4003 | maintain. |
|
3981 | 4004 | |
|
3982 | 4005 | * Moved all the original ipython.py code into ipythonlib.py. Right |
|
3983 | 4006 | now it's just one big dump into a function called make_IPython, so |
|
3984 | 4007 | no real modularity has been gained. But at least it makes the |
|
3985 | 4008 | wrapper script tiny, and since ipythonlib is a module, it gets |
|
3986 | 4009 | compiled and startup is much faster. |
|
3987 | 4010 | |
|
3988 | 4011 | This is a reasobably 'deep' change, so we should test it for a |
|
3989 | 4012 | while without messing too much more with the code. |
|
3990 | 4013 | |
|
3991 | 4014 | 2001-11-21 Fernando Perez <fperez@colorado.edu> |
|
3992 | 4015 | |
|
3993 | 4016 | * Version 0.1.11 released, 0.1.12 opened for further work. |
|
3994 | 4017 | |
|
3995 | 4018 | * Removed dependency on Itpl. It was only needed in one place. It |
|
3996 | 4019 | would be nice if this became part of python, though. It makes life |
|
3997 | 4020 | *a lot* easier in some cases. |
|
3998 | 4021 | |
|
3999 | 4022 | * Simplified the prefilter code a bit. Now all handlers are |
|
4000 | 4023 | expected to explicitly return a value (at least a blank string). |
|
4001 | 4024 | |
|
4002 | 4025 | * Heavy edits in ipplib. Removed the help system altogether. Now |
|
4003 | 4026 | obj?/?? is used for inspecting objects, a magic @doc prints |
|
4004 | 4027 | docstrings, and full-blown Python help is accessed via the 'help' |
|
4005 | 4028 | keyword. This cleans up a lot of code (less to maintain) and does |
|
4006 | 4029 | the job. Since 'help' is now a standard Python component, might as |
|
4007 | 4030 | well use it and remove duplicate functionality. |
|
4008 | 4031 | |
|
4009 | 4032 | Also removed the option to use ipplib as a standalone program. By |
|
4010 | 4033 | now it's too dependent on other parts of IPython to function alone. |
|
4011 | 4034 | |
|
4012 | 4035 | * Fixed bug in genutils.pager. It would crash if the pager was |
|
4013 | 4036 | exited immediately after opening (broken pipe). |
|
4014 | 4037 | |
|
4015 | 4038 | * Trimmed down the VerboseTB reporting a little. The header is |
|
4016 | 4039 | much shorter now and the repeated exception arguments at the end |
|
4017 | 4040 | have been removed. For interactive use the old header seemed a bit |
|
4018 | 4041 | excessive. |
|
4019 | 4042 | |
|
4020 | 4043 | * Fixed small bug in output of @whos for variables with multi-word |
|
4021 | 4044 | types (only first word was displayed). |
|
4022 | 4045 | |
|
4023 | 4046 | 2001-11-17 Fernando Perez <fperez@colorado.edu> |
|
4024 | 4047 | |
|
4025 | 4048 | * Version 0.1.10 released, 0.1.11 opened for further work. |
|
4026 | 4049 | |
|
4027 | 4050 | * Modified dirs and friends. dirs now *returns* the stack (not |
|
4028 | 4051 | prints), so one can manipulate it as a variable. Convenient to |
|
4029 | 4052 | travel along many directories. |
|
4030 | 4053 | |
|
4031 | 4054 | * Fixed bug in magic_pdef: would only work with functions with |
|
4032 | 4055 | arguments with default values. |
|
4033 | 4056 | |
|
4034 | 4057 | 2001-11-14 Fernando Perez <fperez@colorado.edu> |
|
4035 | 4058 | |
|
4036 | 4059 | * Added the PhysicsInput stuff to dot_ipython so it ships as an |
|
4037 | 4060 | example with IPython. Various other minor fixes and cleanups. |
|
4038 | 4061 | |
|
4039 | 4062 | * Version 0.1.9 released, 0.1.10 opened for further work. |
|
4040 | 4063 | |
|
4041 | 4064 | * Added sys.path to the list of directories searched in the |
|
4042 | 4065 | execfile= option. It used to be the current directory and the |
|
4043 | 4066 | user's IPYTHONDIR only. |
|
4044 | 4067 | |
|
4045 | 4068 | 2001-11-13 Fernando Perez <fperez@colorado.edu> |
|
4046 | 4069 | |
|
4047 | 4070 | * Reinstated the raw_input/prefilter separation that Janko had |
|
4048 | 4071 | initially. This gives a more convenient setup for extending the |
|
4049 | 4072 | pre-processor from the outside: raw_input always gets a string, |
|
4050 | 4073 | and prefilter has to process it. We can then redefine prefilter |
|
4051 | 4074 | from the outside and implement extensions for special |
|
4052 | 4075 | purposes. |
|
4053 | 4076 | |
|
4054 | 4077 | Today I got one for inputting PhysicalQuantity objects |
|
4055 | 4078 | (from Scientific) without needing any function calls at |
|
4056 | 4079 | all. Extremely convenient, and it's all done as a user-level |
|
4057 | 4080 | extension (no IPython code was touched). Now instead of: |
|
4058 | 4081 | a = PhysicalQuantity(4.2,'m/s**2') |
|
4059 | 4082 | one can simply say |
|
4060 | 4083 | a = 4.2 m/s**2 |
|
4061 | 4084 | or even |
|
4062 | 4085 | a = 4.2 m/s^2 |
|
4063 | 4086 | |
|
4064 | 4087 | I use this, but it's also a proof of concept: IPython really is |
|
4065 | 4088 | fully user-extensible, even at the level of the parsing of the |
|
4066 | 4089 | command line. It's not trivial, but it's perfectly doable. |
|
4067 | 4090 | |
|
4068 | 4091 | * Added 'add_flip' method to inclusion conflict resolver. Fixes |
|
4069 | 4092 | the problem of modules being loaded in the inverse order in which |
|
4070 | 4093 | they were defined in |
|
4071 | 4094 | |
|
4072 | 4095 | * Version 0.1.8 released, 0.1.9 opened for further work. |
|
4073 | 4096 | |
|
4074 | 4097 | * Added magics pdef, source and file. They respectively show the |
|
4075 | 4098 | definition line ('prototype' in C), source code and full python |
|
4076 | 4099 | file for any callable object. The object inspector oinfo uses |
|
4077 | 4100 | these to show the same information. |
|
4078 | 4101 | |
|
4079 | 4102 | * Version 0.1.7 released, 0.1.8 opened for further work. |
|
4080 | 4103 | |
|
4081 | 4104 | * Separated all the magic functions into a class called Magic. The |
|
4082 | 4105 | InteractiveShell class was becoming too big for Xemacs to handle |
|
4083 | 4106 | (de-indenting a line would lock it up for 10 seconds while it |
|
4084 | 4107 | backtracked on the whole class!) |
|
4085 | 4108 | |
|
4086 | 4109 | FIXME: didn't work. It can be done, but right now namespaces are |
|
4087 | 4110 | all messed up. Do it later (reverted it for now, so at least |
|
4088 | 4111 | everything works as before). |
|
4089 | 4112 | |
|
4090 | 4113 | * Got the object introspection system (magic_oinfo) working! I |
|
4091 | 4114 | think this is pretty much ready for release to Janko, so he can |
|
4092 | 4115 | test it for a while and then announce it. Pretty much 100% of what |
|
4093 | 4116 | I wanted for the 'phase 1' release is ready. Happy, tired. |
|
4094 | 4117 | |
|
4095 | 4118 | 2001-11-12 Fernando Perez <fperez@colorado.edu> |
|
4096 | 4119 | |
|
4097 | 4120 | * Version 0.1.6 released, 0.1.7 opened for further work. |
|
4098 | 4121 | |
|
4099 | 4122 | * Fixed bug in printing: it used to test for truth before |
|
4100 | 4123 | printing, so 0 wouldn't print. Now checks for None. |
|
4101 | 4124 | |
|
4102 | 4125 | * Fixed bug where auto-execs increase the prompt counter by 2 (b/c |
|
4103 | 4126 | they have to call len(str(sys.ps1)) ). But the fix is ugly, it |
|
4104 | 4127 | reaches by hand into the outputcache. Think of a better way to do |
|
4105 | 4128 | this later. |
|
4106 | 4129 | |
|
4107 | 4130 | * Various small fixes thanks to Nathan's comments. |
|
4108 | 4131 | |
|
4109 | 4132 | * Changed magic_pprint to magic_Pprint. This way it doesn't |
|
4110 | 4133 | collide with pprint() and the name is consistent with the command |
|
4111 | 4134 | line option. |
|
4112 | 4135 | |
|
4113 | 4136 | * Changed prompt counter behavior to be fully like |
|
4114 | 4137 | Mathematica's. That is, even input that doesn't return a result |
|
4115 | 4138 | raises the prompt counter. The old behavior was kind of confusing |
|
4116 | 4139 | (getting the same prompt number several times if the operation |
|
4117 | 4140 | didn't return a result). |
|
4118 | 4141 | |
|
4119 | 4142 | * Fixed Nathan's last name in a couple of places (Gray, not Graham). |
|
4120 | 4143 | |
|
4121 | 4144 | * Fixed -Classic mode (wasn't working anymore). |
|
4122 | 4145 | |
|
4123 | 4146 | * Added colored prompts using Nathan's new code. Colors are |
|
4124 | 4147 | currently hardwired, they can be user-configurable. For |
|
4125 | 4148 | developers, they can be chosen in file ipythonlib.py, at the |
|
4126 | 4149 | beginning of the CachedOutput class def. |
|
4127 | 4150 | |
|
4128 | 4151 | 2001-11-11 Fernando Perez <fperez@colorado.edu> |
|
4129 | 4152 | |
|
4130 | 4153 | * Version 0.1.5 released, 0.1.6 opened for further work. |
|
4131 | 4154 | |
|
4132 | 4155 | * Changed magic_env to *return* the environment as a dict (not to |
|
4133 | 4156 | print it). This way it prints, but it can also be processed. |
|
4134 | 4157 | |
|
4135 | 4158 | * Added Verbose exception reporting to interactive |
|
4136 | 4159 | exceptions. Very nice, now even 1/0 at the prompt gives a verbose |
|
4137 | 4160 | traceback. Had to make some changes to the ultraTB file. This is |
|
4138 | 4161 | probably the last 'big' thing in my mental todo list. This ties |
|
4139 | 4162 | in with the next entry: |
|
4140 | 4163 | |
|
4141 | 4164 | * Changed -Xi and -Xf to a single -xmode option. Now all the user |
|
4142 | 4165 | has to specify is Plain, Color or Verbose for all exception |
|
4143 | 4166 | handling. |
|
4144 | 4167 | |
|
4145 | 4168 | * Removed ShellServices option. All this can really be done via |
|
4146 | 4169 | the magic system. It's easier to extend, cleaner and has automatic |
|
4147 | 4170 | namespace protection and documentation. |
|
4148 | 4171 | |
|
4149 | 4172 | 2001-11-09 Fernando Perez <fperez@colorado.edu> |
|
4150 | 4173 | |
|
4151 | 4174 | * Fixed bug in output cache flushing (missing parameter to |
|
4152 | 4175 | __init__). Other small bugs fixed (found using pychecker). |
|
4153 | 4176 | |
|
4154 | 4177 | * Version 0.1.4 opened for bugfixing. |
|
4155 | 4178 | |
|
4156 | 4179 | 2001-11-07 Fernando Perez <fperez@colorado.edu> |
|
4157 | 4180 | |
|
4158 | 4181 | * Version 0.1.3 released, mainly because of the raw_input bug. |
|
4159 | 4182 | |
|
4160 | 4183 | * Fixed NASTY bug in raw_input: input line wasn't properly parsed |
|
4161 | 4184 | and when testing for whether things were callable, a call could |
|
4162 | 4185 | actually be made to certain functions. They would get called again |
|
4163 | 4186 | once 'really' executed, with a resulting double call. A disaster |
|
4164 | 4187 | in many cases (list.reverse() would never work!). |
|
4165 | 4188 | |
|
4166 | 4189 | * Removed prefilter() function, moved its code to raw_input (which |
|
4167 | 4190 | after all was just a near-empty caller for prefilter). This saves |
|
4168 | 4191 | a function call on every prompt, and simplifies the class a tiny bit. |
|
4169 | 4192 | |
|
4170 | 4193 | * Fix _ip to __ip name in magic example file. |
|
4171 | 4194 | |
|
4172 | 4195 | * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should |
|
4173 | 4196 | work with non-gnu versions of tar. |
|
4174 | 4197 | |
|
4175 | 4198 | 2001-11-06 Fernando Perez <fperez@colorado.edu> |
|
4176 | 4199 | |
|
4177 | 4200 | * Version 0.1.2. Just to keep track of the recent changes. |
|
4178 | 4201 | |
|
4179 | 4202 | * Fixed nasty bug in output prompt routine. It used to check 'if |
|
4180 | 4203 | arg != None...'. Problem is, this fails if arg implements a |
|
4181 | 4204 | special comparison (__cmp__) which disallows comparing to |
|
4182 | 4205 | None. Found it when trying to use the PhysicalQuantity module from |
|
4183 | 4206 | ScientificPython. |
|
4184 | 4207 | |
|
4185 | 4208 | 2001-11-05 Fernando Perez <fperez@colorado.edu> |
|
4186 | 4209 | |
|
4187 | 4210 | * Also added dirs. Now the pushd/popd/dirs family functions |
|
4188 | 4211 | basically like the shell, with the added convenience of going home |
|
4189 | 4212 | when called with no args. |
|
4190 | 4213 | |
|
4191 | 4214 | * pushd/popd slightly modified to mimic shell behavior more |
|
4192 | 4215 | closely. |
|
4193 | 4216 | |
|
4194 | 4217 | * Added env,pushd,popd from ShellServices as magic functions. I |
|
4195 | 4218 | think the cleanest will be to port all desired functions from |
|
4196 | 4219 | ShellServices as magics and remove ShellServices altogether. This |
|
4197 | 4220 | will provide a single, clean way of adding functionality |
|
4198 | 4221 | (shell-type or otherwise) to IP. |
|
4199 | 4222 | |
|
4200 | 4223 | 2001-11-04 Fernando Perez <fperez@colorado.edu> |
|
4201 | 4224 | |
|
4202 | 4225 | * Added .ipython/ directory to sys.path. This way users can keep |
|
4203 | 4226 | customizations there and access them via import. |
|
4204 | 4227 | |
|
4205 | 4228 | 2001-11-03 Fernando Perez <fperez@colorado.edu> |
|
4206 | 4229 | |
|
4207 | 4230 | * Opened version 0.1.1 for new changes. |
|
4208 | 4231 | |
|
4209 | 4232 | * Changed version number to 0.1.0: first 'public' release, sent to |
|
4210 | 4233 | Nathan and Janko. |
|
4211 | 4234 | |
|
4212 | 4235 | * Lots of small fixes and tweaks. |
|
4213 | 4236 | |
|
4214 | 4237 | * Minor changes to whos format. Now strings are shown, snipped if |
|
4215 | 4238 | too long. |
|
4216 | 4239 | |
|
4217 | 4240 | * Changed ShellServices to work on __main__ so they show up in @who |
|
4218 | 4241 | |
|
4219 | 4242 | * Help also works with ? at the end of a line: |
|
4220 | 4243 | ?sin and sin? |
|
4221 | 4244 | both produce the same effect. This is nice, as often I use the |
|
4222 | 4245 | tab-complete to find the name of a method, but I used to then have |
|
4223 | 4246 | to go to the beginning of the line to put a ? if I wanted more |
|
4224 | 4247 | info. Now I can just add the ? and hit return. Convenient. |
|
4225 | 4248 | |
|
4226 | 4249 | 2001-11-02 Fernando Perez <fperez@colorado.edu> |
|
4227 | 4250 | |
|
4228 | 4251 | * Python version check (>=2.1) added. |
|
4229 | 4252 | |
|
4230 | 4253 | * Added LazyPython documentation. At this point the docs are quite |
|
4231 | 4254 | a mess. A cleanup is in order. |
|
4232 | 4255 | |
|
4233 | 4256 | * Auto-installer created. For some bizarre reason, the zipfiles |
|
4234 | 4257 | module isn't working on my system. So I made a tar version |
|
4235 | 4258 | (hopefully the command line options in various systems won't kill |
|
4236 | 4259 | me). |
|
4237 | 4260 | |
|
4238 | 4261 | * Fixes to Struct in genutils. Now all dictionary-like methods are |
|
4239 | 4262 | protected (reasonably). |
|
4240 | 4263 | |
|
4241 | 4264 | * Added pager function to genutils and changed ? to print usage |
|
4242 | 4265 | note through it (it was too long). |
|
4243 | 4266 | |
|
4244 | 4267 | * Added the LazyPython functionality. Works great! I changed the |
|
4245 | 4268 | auto-quote escape to ';', it's on home row and next to '. But |
|
4246 | 4269 | both auto-quote and auto-paren (still /) escapes are command-line |
|
4247 | 4270 | parameters. |
|
4248 | 4271 | |
|
4249 | 4272 | |
|
4250 | 4273 | 2001-11-01 Fernando Perez <fperez@colorado.edu> |
|
4251 | 4274 | |
|
4252 | 4275 | * Version changed to 0.0.7. Fairly large change: configuration now |
|
4253 | 4276 | is all stored in a directory, by default .ipython. There, all |
|
4254 | 4277 | config files have normal looking names (not .names) |
|
4255 | 4278 | |
|
4256 | 4279 | * Version 0.0.6 Released first to Lucas and Archie as a test |
|
4257 | 4280 | run. Since it's the first 'semi-public' release, change version to |
|
4258 | 4281 | > 0.0.6 for any changes now. |
|
4259 | 4282 | |
|
4260 | 4283 | * Stuff I had put in the ipplib.py changelog: |
|
4261 | 4284 | |
|
4262 | 4285 | Changes to InteractiveShell: |
|
4263 | 4286 | |
|
4264 | 4287 | - Made the usage message a parameter. |
|
4265 | 4288 | |
|
4266 | 4289 | - Require the name of the shell variable to be given. It's a bit |
|
4267 | 4290 | of a hack, but allows the name 'shell' not to be hardwire in the |
|
4268 | 4291 | magic (@) handler, which is problematic b/c it requires |
|
4269 | 4292 | polluting the global namespace with 'shell'. This in turn is |
|
4270 | 4293 | fragile: if a user redefines a variable called shell, things |
|
4271 | 4294 | break. |
|
4272 | 4295 | |
|
4273 | 4296 | - magic @: all functions available through @ need to be defined |
|
4274 | 4297 | as magic_<name>, even though they can be called simply as |
|
4275 | 4298 | @<name>. This allows the special command @magic to gather |
|
4276 | 4299 | information automatically about all existing magic functions, |
|
4277 | 4300 | even if they are run-time user extensions, by parsing the shell |
|
4278 | 4301 | instance __dict__ looking for special magic_ names. |
|
4279 | 4302 | |
|
4280 | 4303 | - mainloop: added *two* local namespace parameters. This allows |
|
4281 | 4304 | the class to differentiate between parameters which were there |
|
4282 | 4305 | before and after command line initialization was processed. This |
|
4283 | 4306 | way, later @who can show things loaded at startup by the |
|
4284 | 4307 | user. This trick was necessary to make session saving/reloading |
|
4285 | 4308 | really work: ideally after saving/exiting/reloading a session, |
|
4286 | 4309 | *everythin* should look the same, including the output of @who. I |
|
4287 | 4310 | was only able to make this work with this double namespace |
|
4288 | 4311 | trick. |
|
4289 | 4312 | |
|
4290 | 4313 | - added a header to the logfile which allows (almost) full |
|
4291 | 4314 | session restoring. |
|
4292 | 4315 | |
|
4293 | 4316 | - prepend lines beginning with @ or !, with a and log |
|
4294 | 4317 | them. Why? !lines: may be useful to know what you did @lines: |
|
4295 | 4318 | they may affect session state. So when restoring a session, at |
|
4296 | 4319 | least inform the user of their presence. I couldn't quite get |
|
4297 | 4320 | them to properly re-execute, but at least the user is warned. |
|
4298 | 4321 | |
|
4299 | 4322 | * Started ChangeLog. |
General Comments 0
You need to be logged in to leave comments.
Login now