Show More
@@ -1,2592 +1,2620 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Magic functions for InteractiveShell. |
|
3 | 3 | |
|
4 |
$Id: Magic.py 96 |
|
|
4 | $Id: Magic.py 965 2005-12-28 23:23:09Z fperez $""" | |
|
5 | 5 | |
|
6 | 6 | #***************************************************************************** |
|
7 | 7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
8 | 8 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #***************************************************************************** |
|
13 | 13 | |
|
14 | 14 | #**************************************************************************** |
|
15 | 15 | # Modules and globals |
|
16 | 16 | |
|
17 | 17 | from IPython import Release |
|
18 | 18 | __author__ = '%s <%s>\n%s <%s>' % \ |
|
19 | 19 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) |
|
20 | 20 | __license__ = Release.license |
|
21 | 21 | |
|
22 | 22 | # Python standard modules |
|
23 | 23 | import __builtin__ |
|
24 | 24 | import bdb |
|
25 | 25 | import inspect |
|
26 | 26 | import os |
|
27 | 27 | import pdb |
|
28 | 28 | import pydoc |
|
29 | 29 | import sys |
|
30 | 30 | import re |
|
31 | 31 | import tempfile |
|
32 | 32 | import time |
|
33 | 33 | from cStringIO import StringIO |
|
34 | 34 | from getopt import getopt |
|
35 | 35 | from pprint import pprint, pformat |
|
36 | 36 | |
|
37 | 37 | # profile isn't bundled by default in Debian for license reasons |
|
38 | 38 | try: |
|
39 | 39 | import profile,pstats |
|
40 | 40 | except ImportError: |
|
41 | 41 | profile = pstats = None |
|
42 | 42 | |
|
43 | 43 | # Homebrewed |
|
44 | 44 | from IPython import Debugger, OInspect, wildcard |
|
45 | 45 | from IPython.FakeModule import FakeModule |
|
46 | 46 | from IPython.Itpl import Itpl, itpl, printpl,itplns |
|
47 | 47 | from IPython.PyColorize import Parser |
|
48 | 48 | from IPython.Struct import Struct |
|
49 | 49 | from IPython.genutils import * |
|
50 | 50 | |
|
51 | 51 | # Globals to be set later by Magic constructor |
|
52 | 52 | MAGIC_PREFIX = '' |
|
53 | 53 | MAGIC_ESCAPE = '' |
|
54 | 54 | |
|
55 | 55 | #*************************************************************************** |
|
56 | 56 | # Utility functions |
|
57 | 57 | def magic2python(cmd): |
|
58 | 58 | """Convert a command string of magic syntax to valid Python code.""" |
|
59 | 59 | |
|
60 | 60 | if cmd.startswith('#'+MAGIC_ESCAPE) or \ |
|
61 | 61 | cmd.startswith(MAGIC_ESCAPE): |
|
62 | 62 | if cmd[0]=='#': |
|
63 | 63 | cmd = cmd[1:] |
|
64 | 64 | # we need to return the proper line end later |
|
65 | 65 | if cmd[-1] == '\n': |
|
66 | 66 | endl = '\n' |
|
67 | 67 | else: |
|
68 | 68 | endl = '' |
|
69 | 69 | try: |
|
70 | 70 | func,args = cmd[1:].split(' ',1) |
|
71 | 71 | except: |
|
72 | 72 | func,args = cmd[1:].rstrip(),'' |
|
73 | 73 | args = args.replace('"','\\"').replace("'","\\'").rstrip() |
|
74 | 74 | return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl) |
|
75 | 75 | else: |
|
76 | 76 | return cmd |
|
77 | 77 | |
|
78 | 78 | def on_off(tag): |
|
79 | 79 | """Return an ON/OFF string for a 1/0 input. Simple utility function.""" |
|
80 | 80 | return ['OFF','ON'][tag] |
|
81 | 81 | |
|
82 | 82 | |
|
83 | 83 | #**************************************************************************** |
|
84 | 84 | # Utility classes |
|
85 | 85 | class Macro: |
|
86 | 86 | """Simple class to store the value of macros as strings. |
|
87 | 87 | |
|
88 | 88 | This allows us to later exec them by checking when something is an |
|
89 | 89 | instance of this class.""" |
|
90 | 90 | |
|
91 | 91 | def __init__(self,cmds): |
|
92 | 92 | """Build a macro from a list of commands.""" |
|
93 | 93 | |
|
94 | 94 | # Since the list may include multi-line entries, first make sure that |
|
95 | 95 | # they've been all broken up before passing it to magic2python |
|
96 | 96 | cmdlist = map(magic2python,''.join(cmds).split('\n')) |
|
97 | 97 | self.value = '\n'.join(cmdlist) |
|
98 | 98 | |
|
99 | 99 | def __str__(self): |
|
100 | 100 | return self.value |
|
101 | 101 | |
|
102 | 102 | #*************************************************************************** |
|
103 | 103 | # Main class implementing Magic functionality |
|
104 | 104 | class Magic: |
|
105 | 105 | """Magic functions for InteractiveShell. |
|
106 | 106 | |
|
107 | 107 | Shell functions which can be reached as %function_name. All magic |
|
108 | 108 | functions should accept a string, which they can parse for their own |
|
109 | 109 | needs. This can make some functions easier to type, eg `%cd ../` |
|
110 | 110 | vs. `%cd("../")` |
|
111 | 111 | |
|
112 | 112 | ALL definitions MUST begin with the prefix magic_. The user won't need it |
|
113 | 113 | at the command line, but it is is needed in the definition. """ |
|
114 | 114 | |
|
115 | 115 | # class globals |
|
116 | 116 | auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.', |
|
117 | 117 | 'Automagic is ON, % prefix NOT needed for magic functions.'] |
|
118 | 118 | |
|
119 | 119 | #...................................................................... |
|
120 | 120 | # some utility functions |
|
121 | 121 | |
|
122 | 122 | def __init__(self,shell): |
|
123 | 123 | # XXX This is hackish, clean up later to avoid these messy globals |
|
124 | 124 | global MAGIC_PREFIX, MAGIC_ESCAPE |
|
125 | 125 | |
|
126 | 126 | self.options_table = {} |
|
127 | 127 | MAGIC_PREFIX = shell.name+'.magic_' |
|
128 | 128 | MAGIC_ESCAPE = shell.ESC_MAGIC |
|
129 | 129 | if profile is None: |
|
130 | 130 | self.magic_prun = self.profile_missing_notice |
|
131 | 131 | |
|
132 | 132 | def profile_missing_notice(self, *args, **kwargs): |
|
133 | 133 | error("""\ |
|
134 | 134 | The profile module could not be found. If you are a Debian user, |
|
135 | 135 | it has been removed from the standard Debian package because of its non-free |
|
136 | 136 | license. To use profiling, please install"python2.3-profiler" from non-free.""") |
|
137 | 137 | |
|
138 | 138 | def default_option(self,fn,optstr): |
|
139 | 139 | """Make an entry in the options_table for fn, with value optstr""" |
|
140 | 140 | |
|
141 | 141 | if fn not in self.lsmagic(): |
|
142 | 142 | error("%s is not a magic function" % fn) |
|
143 | 143 | self.options_table[fn] = optstr |
|
144 | 144 | |
|
145 | 145 | def lsmagic(self): |
|
146 | 146 | """Return a list of currently available magic functions. |
|
147 | 147 | |
|
148 | 148 | Gives a list of the bare names after mangling (['ls','cd', ...], not |
|
149 | 149 | ['magic_ls','magic_cd',...]""" |
|
150 | 150 | |
|
151 | 151 | # FIXME. This needs a cleanup, in the way the magics list is built. |
|
152 | 152 | |
|
153 | 153 | # magics in class definition |
|
154 | 154 | class_magic = lambda fn: fn.startswith('magic_') and \ |
|
155 | 155 | callable(Magic.__dict__[fn]) |
|
156 | 156 | # in instance namespace (run-time user additions) |
|
157 | 157 | inst_magic = lambda fn: fn.startswith('magic_') and \ |
|
158 | 158 | callable(self.__dict__[fn]) |
|
159 | 159 | # and bound magics by user (so they can access self): |
|
160 | 160 | inst_bound_magic = lambda fn: fn.startswith('magic_') and \ |
|
161 | 161 | callable(self.__class__.__dict__[fn]) |
|
162 | 162 | magics = filter(class_magic,Magic.__dict__.keys()) + \ |
|
163 | 163 | filter(inst_magic,self.__dict__.keys()) + \ |
|
164 | 164 | filter(inst_bound_magic,self.__class__.__dict__.keys()) |
|
165 | 165 | out = [] |
|
166 | 166 | for fn in magics: |
|
167 | 167 | out.append(fn.replace('magic_','',1)) |
|
168 | 168 | out.sort() |
|
169 | 169 | return out |
|
170 | 170 | |
|
171 | 171 | def set_shell(self,shell): |
|
172 | 172 | self.shell = shell |
|
173 | 173 | self.alias_table = shell.alias_table |
|
174 | 174 | |
|
175 | 175 | def extract_input_slices(self,slices): |
|
176 | 176 | """Return as a string a set of input history slices. |
|
177 | 177 | |
|
178 | 178 | The set of slices is given as a list of strings (like ['1','4:8','9'], |
|
179 | 179 | since this function is for use by magic functions which get their |
|
180 | 180 | arguments as strings.""" |
|
181 | 181 | |
|
182 | 182 | cmds = [] |
|
183 | 183 | for chunk in slices: |
|
184 | 184 | if ':' in chunk: |
|
185 | 185 | ini,fin = map(int,chunk.split(':')) |
|
186 | 186 | else: |
|
187 | 187 | ini = int(chunk) |
|
188 | 188 | fin = ini+1 |
|
189 | 189 | cmds.append(self.shell.input_hist[ini:fin]) |
|
190 | 190 | return cmds |
|
191 | 191 | |
|
192 | 192 | def _ofind(self,oname): |
|
193 | 193 | """Find an object in the available namespaces. |
|
194 | 194 | |
|
195 | 195 | self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic |
|
196 | 196 | |
|
197 | 197 | Has special code to detect magic functions. |
|
198 | 198 | """ |
|
199 | 199 | |
|
200 | 200 | oname = oname.strip() |
|
201 | 201 | |
|
202 | 202 | # Namespaces to search in: |
|
203 | 203 | user_ns = self.shell.user_ns |
|
204 | 204 | internal_ns = self.shell.internal_ns |
|
205 | 205 | builtin_ns = __builtin__.__dict__ |
|
206 | 206 | alias_ns = self.shell.alias_table |
|
207 | 207 | |
|
208 | 208 | # Put them in a list. The order is important so that we find things in |
|
209 | 209 | # the same order that Python finds them. |
|
210 | 210 | namespaces = [ ('Interactive',user_ns), |
|
211 | 211 | ('IPython internal',internal_ns), |
|
212 | 212 | ('Python builtin',builtin_ns), |
|
213 | 213 | ('Alias',alias_ns), |
|
214 | 214 | ] |
|
215 | 215 | |
|
216 | 216 | # initialize results to 'null' |
|
217 | 217 | found = 0; obj = None; ospace = None; ds = None; |
|
218 | 218 | ismagic = 0; isalias = 0 |
|
219 | 219 | |
|
220 | 220 | # Look for the given name by splitting it in parts. If the head is |
|
221 | 221 | # found, then we look for all the remaining parts as members, and only |
|
222 | 222 | # declare success if we can find them all. |
|
223 | 223 | oname_parts = oname.split('.') |
|
224 | 224 | oname_head, oname_rest = oname_parts[0],oname_parts[1:] |
|
225 | 225 | for nsname,ns in namespaces: |
|
226 | 226 | try: |
|
227 | 227 | obj = ns[oname_head] |
|
228 | 228 | except KeyError: |
|
229 | 229 | continue |
|
230 | 230 | else: |
|
231 | 231 | for part in oname_rest: |
|
232 | 232 | try: |
|
233 | 233 | obj = getattr(obj,part) |
|
234 | 234 | except: |
|
235 | 235 | # Blanket except b/c some badly implemented objects |
|
236 | 236 | # allow __getattr__ to raise exceptions other than |
|
237 | 237 | # AttributeError, which then crashes IPython. |
|
238 | 238 | break |
|
239 | 239 | else: |
|
240 | 240 | # If we finish the for loop (no break), we got all members |
|
241 | 241 | found = 1 |
|
242 | 242 | ospace = nsname |
|
243 | 243 | if ns == alias_ns: |
|
244 | 244 | isalias = 1 |
|
245 | 245 | break # namespace loop |
|
246 | 246 | |
|
247 | 247 | # Try to see if it's magic |
|
248 | 248 | if not found: |
|
249 | 249 | if oname.startswith(self.shell.ESC_MAGIC): |
|
250 | 250 | oname = oname[1:] |
|
251 | 251 | obj = getattr(self,'magic_'+oname,None) |
|
252 | 252 | if obj is not None: |
|
253 | 253 | found = 1 |
|
254 | 254 | ospace = 'IPython internal' |
|
255 | 255 | ismagic = 1 |
|
256 | 256 | |
|
257 | 257 | # Last try: special-case some literals like '', [], {}, etc: |
|
258 | 258 | if not found and oname_head in ["''",'""','[]','{}','()']: |
|
259 | 259 | obj = eval(oname_head) |
|
260 | 260 | found = 1 |
|
261 | 261 | ospace = 'Interactive' |
|
262 | 262 | |
|
263 | 263 | return {'found':found, 'obj':obj, 'namespace':ospace, |
|
264 | 264 | 'ismagic':ismagic, 'isalias':isalias} |
|
265 | 265 | |
|
266 | 266 | def arg_err(self,func): |
|
267 | 267 | """Print docstring if incorrect arguments were passed""" |
|
268 | 268 | print 'Error in arguments:' |
|
269 | 269 | print OInspect.getdoc(func) |
|
270 | 270 | |
|
271 | 271 | |
|
272 | 272 | def format_latex(self,str): |
|
273 | 273 | """Format a string for latex inclusion.""" |
|
274 | 274 | |
|
275 | 275 | # Characters that need to be escaped for latex: |
|
276 | 276 | escape_re = re.compile(r'(%|_|\$)',re.MULTILINE) |
|
277 | 277 | # Magic command names as headers: |
|
278 | 278 | cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC, |
|
279 | 279 | re.MULTILINE) |
|
280 | 280 | # Magic commands |
|
281 | 281 | cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC, |
|
282 | 282 | re.MULTILINE) |
|
283 | 283 | # Paragraph continue |
|
284 | 284 | par_re = re.compile(r'\\$',re.MULTILINE) |
|
285 | 285 | |
|
286 | 286 | str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str) |
|
287 | 287 | str = cmd_re.sub(r'\\texttt{\g<cmd>}',str) |
|
288 | 288 | str = par_re.sub(r'\\\\',str) |
|
289 | 289 | str = escape_re.sub(r'\\\1',str) |
|
290 | 290 | return str |
|
291 | 291 | |
|
292 | 292 | def format_screen(self,str): |
|
293 | 293 | """Format a string for screen printing. |
|
294 | 294 | |
|
295 | 295 | This removes some latex-type format codes.""" |
|
296 | 296 | # Paragraph continue |
|
297 | 297 | par_re = re.compile(r'\\$',re.MULTILINE) |
|
298 | 298 | str = par_re.sub('',str) |
|
299 | 299 | return str |
|
300 | 300 | |
|
301 | 301 | def parse_options(self,arg_str,opt_str,*long_opts,**kw): |
|
302 | 302 | """Parse options passed to an argument string. |
|
303 | 303 | |
|
304 | 304 | The interface is similar to that of getopt(), but it returns back a |
|
305 | 305 | Struct with the options as keys and the stripped argument string still |
|
306 | 306 | as a string. |
|
307 | 307 | |
|
308 | 308 | arg_str is quoted as a true sys.argv vector by using shlex.split. |
|
309 | 309 | This allows us to easily expand variables, glob files, quote |
|
310 | 310 | arguments, etc. |
|
311 | 311 | |
|
312 | 312 | Options: |
|
313 | 313 | -mode: default 'string'. If given as 'list', the argument string is |
|
314 | 314 | returned as a list (split on whitespace) instead of a string. |
|
315 | 315 | |
|
316 | 316 | -list_all: put all option values in lists. Normally only options |
|
317 | 317 | appearing more than once are put in a list.""" |
|
318 | 318 | |
|
319 | 319 | # inject default options at the beginning of the input line |
|
320 | 320 | caller = sys._getframe(1).f_code.co_name.replace('magic_','') |
|
321 | 321 | arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str) |
|
322 | 322 | |
|
323 | 323 | mode = kw.get('mode','string') |
|
324 | 324 | if mode not in ['string','list']: |
|
325 | 325 | raise ValueError,'incorrect mode given: %s' % mode |
|
326 | 326 | # Get options |
|
327 | 327 | list_all = kw.get('list_all',0) |
|
328 | 328 | |
|
329 | 329 | # Check if we have more than one argument to warrant extra processing: |
|
330 | 330 | odict = {} # Dictionary with options |
|
331 | 331 | args = arg_str.split() |
|
332 | 332 | if len(args) >= 1: |
|
333 | 333 | # If the list of inputs only has 0 or 1 thing in it, there's no |
|
334 | 334 | # need to look for options |
|
335 | 335 | argv = shlex_split(arg_str) |
|
336 | 336 | # Do regular option processing |
|
337 | 337 | opts,args = getopt(argv,opt_str,*long_opts) |
|
338 | 338 | for o,a in opts: |
|
339 | 339 | if o.startswith('--'): |
|
340 | 340 | o = o[2:] |
|
341 | 341 | else: |
|
342 | 342 | o = o[1:] |
|
343 | 343 | try: |
|
344 | 344 | odict[o].append(a) |
|
345 | 345 | except AttributeError: |
|
346 | 346 | odict[o] = [odict[o],a] |
|
347 | 347 | except KeyError: |
|
348 | 348 | if list_all: |
|
349 | 349 | odict[o] = [a] |
|
350 | 350 | else: |
|
351 | 351 | odict[o] = a |
|
352 | 352 | |
|
353 | 353 | # Prepare opts,args for return |
|
354 | 354 | opts = Struct(odict) |
|
355 | 355 | if mode == 'string': |
|
356 | 356 | args = ' '.join(args) |
|
357 | 357 | |
|
358 | 358 | return opts,args |
|
359 | 359 | |
|
360 | 360 | #...................................................................... |
|
361 | 361 | # And now the actual magic functions |
|
362 | 362 | |
|
363 | 363 | # Functions for IPython shell work (vars,funcs, config, etc) |
|
364 | 364 | def magic_lsmagic(self, parameter_s = ''): |
|
365 | 365 | """List currently available magic functions.""" |
|
366 | 366 | mesc = self.shell.ESC_MAGIC |
|
367 | 367 | print 'Available magic functions:\n'+mesc+\ |
|
368 | 368 | (' '+mesc).join(self.lsmagic()) |
|
369 | 369 | print '\n' + Magic.auto_status[self.shell.rc.automagic] |
|
370 | 370 | return None |
|
371 | 371 | |
|
372 | 372 | def magic_magic(self, parameter_s = ''): |
|
373 | 373 | """Print information about the magic function system.""" |
|
374 | 374 | |
|
375 | 375 | mode = '' |
|
376 | 376 | try: |
|
377 | 377 | if parameter_s.split()[0] == '-latex': |
|
378 | 378 | mode = 'latex' |
|
379 | 379 | except: |
|
380 | 380 | pass |
|
381 | 381 | |
|
382 | 382 | magic_docs = [] |
|
383 | 383 | for fname in self.lsmagic(): |
|
384 | 384 | mname = 'magic_' + fname |
|
385 | 385 | for space in (Magic,self,self.__class__): |
|
386 | 386 | try: |
|
387 | 387 | fn = space.__dict__[mname] |
|
388 | 388 | except KeyError: |
|
389 | 389 | pass |
|
390 | 390 | else: |
|
391 | 391 | break |
|
392 | 392 | magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC, |
|
393 | 393 | fname,fn.__doc__)) |
|
394 | 394 | magic_docs = ''.join(magic_docs) |
|
395 | 395 | |
|
396 | 396 | if mode == 'latex': |
|
397 | 397 | print self.format_latex(magic_docs) |
|
398 | 398 | return |
|
399 | 399 | else: |
|
400 | 400 | magic_docs = self.format_screen(magic_docs) |
|
401 | 401 | |
|
402 | 402 | outmsg = """ |
|
403 | 403 | IPython's 'magic' functions |
|
404 | 404 | =========================== |
|
405 | 405 | |
|
406 | 406 | The magic function system provides a series of functions which allow you to |
|
407 | 407 | control the behavior of IPython itself, plus a lot of system-type |
|
408 | 408 | features. All these functions are prefixed with a % character, but parameters |
|
409 | 409 | are given without parentheses or quotes. |
|
410 | 410 | |
|
411 | 411 | NOTE: If you have 'automagic' enabled (via the command line option or with the |
|
412 | 412 | %automagic function), you don't need to type in the % explicitly. By default, |
|
413 | 413 | IPython ships with automagic on, so you should only rarely need the % escape. |
|
414 | 414 | |
|
415 | 415 | Example: typing '%cd mydir' (without the quotes) changes you working directory |
|
416 | 416 | to 'mydir', if it exists. |
|
417 | 417 | |
|
418 | 418 | You can define your own magic functions to extend the system. See the supplied |
|
419 | 419 | ipythonrc and example-magic.py files for details (in your ipython |
|
420 | 420 | configuration directory, typically $HOME/.ipython/). |
|
421 | 421 | |
|
422 | 422 | You can also define your own aliased names for magic functions. In your |
|
423 | 423 | ipythonrc file, placing a line like: |
|
424 | 424 | |
|
425 | 425 | execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile |
|
426 | 426 | |
|
427 | 427 | will define %pf as a new name for %profile. |
|
428 | 428 | |
|
429 | 429 | You can also call magics in code using the ipmagic() function, which IPython |
|
430 | 430 | automatically adds to the builtin namespace. Type 'ipmagic?' for details. |
|
431 | 431 | |
|
432 | 432 | For a list of the available magic functions, use %lsmagic. For a description |
|
433 | 433 | of any of them, type %magic_name?, e.g. '%cd?'. |
|
434 | 434 | |
|
435 | 435 | Currently the magic system has the following functions:\n""" |
|
436 | 436 | |
|
437 | 437 | mesc = self.shell.ESC_MAGIC |
|
438 | 438 | outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):" |
|
439 | 439 | "\n\n%s%s\n\n%s" % (outmsg, |
|
440 | 440 | magic_docs,mesc,mesc, |
|
441 | 441 | (' '+mesc).join(self.lsmagic()), |
|
442 | 442 | Magic.auto_status[self.shell.rc.automagic] ) ) |
|
443 | 443 | |
|
444 | 444 | page(outmsg,screen_lines=self.shell.rc.screen_length) |
|
445 | 445 | |
|
446 | 446 | def magic_automagic(self, parameter_s = ''): |
|
447 | 447 | """Make magic functions callable without having to type the initial %. |
|
448 | 448 | |
|
449 | 449 | Toggles on/off (when off, you must call it as %automagic, of |
|
450 | 450 | course). Note that magic functions have lowest priority, so if there's |
|
451 | 451 | a variable whose name collides with that of a magic fn, automagic |
|
452 | 452 | won't work for that function (you get the variable instead). However, |
|
453 | 453 | if you delete the variable (del var), the previously shadowed magic |
|
454 | 454 | function becomes visible to automagic again.""" |
|
455 | 455 | |
|
456 | 456 | rc = self.shell.rc |
|
457 | 457 | rc.automagic = not rc.automagic |
|
458 | 458 | print '\n' + Magic.auto_status[rc.automagic] |
|
459 | 459 | |
|
460 | 460 | def magic_autocall(self, parameter_s = ''): |
|
461 | 461 | """Make functions callable without having to type parentheses. |
|
462 | 462 | |
|
463 | 463 | This toggles the autocall command line option on and off.""" |
|
464 | 464 | |
|
465 | 465 | rc = self.shell.rc |
|
466 | 466 | rc.autocall = not rc.autocall |
|
467 | 467 | print "Automatic calling is:",['OFF','ON'][rc.autocall] |
|
468 | 468 | |
|
469 | 469 | def magic_autoindent(self, parameter_s = ''): |
|
470 | 470 | """Toggle autoindent on/off (if available).""" |
|
471 | 471 | |
|
472 | 472 | self.shell.set_autoindent() |
|
473 | 473 | print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent] |
|
474 | 474 | |
|
475 | 475 | def magic_system_verbose(self, parameter_s = ''): |
|
476 | 476 | """Toggle verbose printing of system calls on/off.""" |
|
477 | 477 | |
|
478 | 478 | self.shell.rc_set_toggle('system_verbose') |
|
479 | 479 | print "System verbose printing is:",\ |
|
480 | 480 | ['OFF','ON'][self.shell.rc.system_verbose] |
|
481 | 481 | |
|
482 | 482 | def magic_history(self, parameter_s = ''): |
|
483 | 483 | """Print input history (_i<n> variables), with most recent last. |
|
484 | 484 | |
|
485 | 485 | %history [-n] -> print at most 40 inputs (some may be multi-line)\\ |
|
486 | 486 | %history [-n] n -> print at most n inputs\\ |
|
487 | 487 | %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\ |
|
488 | 488 | |
|
489 | 489 | Each input's number <n> is shown, and is accessible as the |
|
490 | 490 | automatically generated variable _i<n>. Multi-line statements are |
|
491 | 491 | printed starting at a new line for easy copy/paste. |
|
492 | 492 | |
|
493 | 493 | If option -n is used, input numbers are not printed. This is useful if |
|
494 | 494 | you want to get a printout of many lines which can be directly pasted |
|
495 | 495 | into a text editor. |
|
496 | 496 | |
|
497 | 497 | This feature is only available if numbered prompts are in use.""" |
|
498 | 498 | |
|
499 | 499 | if not self.do_full_cache: |
|
500 | 500 | print 'This feature is only available if numbered prompts are in use.' |
|
501 | 501 | return |
|
502 | 502 | opts,args = self.parse_options(parameter_s,'n',mode='list') |
|
503 | 503 | |
|
504 | 504 | default_length = 40 |
|
505 | 505 | if len(args) == 0: |
|
506 | 506 | final = self.outputcache.prompt_count |
|
507 | 507 | init = max(1,final-default_length) |
|
508 | 508 | elif len(args) == 1: |
|
509 | 509 | final = self.outputcache.prompt_count |
|
510 | 510 | init = max(1,final-int(args[0])) |
|
511 | 511 | elif len(args) == 2: |
|
512 | 512 | init,final = map(int,args) |
|
513 | 513 | else: |
|
514 | 514 | warn('%hist takes 0, 1 or 2 arguments separated by spaces.') |
|
515 | 515 | print self.magic_hist.__doc__ |
|
516 | 516 | return |
|
517 | 517 | width = len(str(final)) |
|
518 | 518 | line_sep = ['','\n'] |
|
519 | 519 | input_hist = self.shell.input_hist |
|
520 | 520 | print_nums = not opts.has_key('n') |
|
521 | 521 | for in_num in range(init,final): |
|
522 | 522 | inline = input_hist[in_num] |
|
523 | 523 | multiline = inline.count('\n') > 1 |
|
524 | 524 | if print_nums: |
|
525 | 525 | print str(in_num).ljust(width)+':'+ line_sep[multiline], |
|
526 | 526 | if inline.startswith('#'+self.shell.ESC_MAGIC) or \ |
|
527 | 527 | inline.startswith('#!'): |
|
528 | 528 | print inline[1:], |
|
529 | 529 | else: |
|
530 | 530 | print inline, |
|
531 | 531 | |
|
532 | 532 | def magic_hist(self, parameter_s=''): |
|
533 | 533 | """Alternate name for %history.""" |
|
534 | 534 | return self.magic_history(parameter_s) |
|
535 | 535 | |
|
536 | 536 | def magic_p(self, parameter_s=''): |
|
537 | 537 | """Just a short alias for Python's 'print'.""" |
|
538 | 538 | exec 'print ' + parameter_s in self.shell.user_ns |
|
539 | 539 | |
|
540 | 540 | def magic_r(self, parameter_s=''): |
|
541 | 541 | """Repeat previous input. |
|
542 | 542 | |
|
543 | 543 | If given an argument, repeats the previous command which starts with |
|
544 | 544 | the same string, otherwise it just repeats the previous input. |
|
545 | 545 | |
|
546 | 546 | Shell escaped commands (with ! as first character) are not recognized |
|
547 | 547 | by this system, only pure python code and magic commands. |
|
548 | 548 | """ |
|
549 | 549 | |
|
550 | 550 | start = parameter_s.strip() |
|
551 | 551 | esc_magic = self.shell.ESC_MAGIC |
|
552 | 552 | # Identify magic commands even if automagic is on (which means |
|
553 | 553 | # the in-memory version is different from that typed by the user). |
|
554 | 554 | if self.shell.rc.automagic: |
|
555 | 555 | start_magic = esc_magic+start |
|
556 | 556 | else: |
|
557 | 557 | start_magic = start |
|
558 | 558 | # Look through the input history in reverse |
|
559 | 559 | for n in range(len(self.shell.input_hist)-2,0,-1): |
|
560 | 560 | input = self.shell.input_hist[n] |
|
561 | 561 | # skip plain 'r' lines so we don't recurse to infinity |
|
562 | 562 | if input != 'ipmagic("r")\n' and \ |
|
563 | 563 | (input.startswith(start) or input.startswith(start_magic)): |
|
564 | 564 | #print 'match',`input` # dbg |
|
565 | 565 | if input.startswith(esc_magic): |
|
566 | 566 | input = magic2python(input) |
|
567 | 567 | #print 'modified',`input` # dbg |
|
568 | 568 | print 'Executing:',input, |
|
569 | 569 | exec input in self.shell.user_ns |
|
570 | 570 | return |
|
571 | 571 | print 'No previous input matching `%s` found.' % start |
|
572 | 572 | |
|
573 | 573 | def magic_page(self, parameter_s=''): |
|
574 | 574 | """Pretty print the object and display it through a pager. |
|
575 | 575 | |
|
576 | 576 | If no parameter is given, use _ (last output).""" |
|
577 | 577 | # After a function contributed by Olivier Aubert, slightly modified. |
|
578 | 578 | |
|
579 | 579 | oname = parameter_s and parameter_s or '_' |
|
580 | 580 | info = self._ofind(oname) |
|
581 | 581 | if info['found']: |
|
582 | 582 | page(pformat(info['obj'])) |
|
583 | 583 | else: |
|
584 | 584 | print 'Object `%s` not found' % oname |
|
585 | 585 | |
|
586 | 586 | def magic_profile(self, parameter_s=''): |
|
587 | 587 | """Print your currently active IPyhton profile.""" |
|
588 | 588 | if self.shell.rc.profile: |
|
589 | 589 | printpl('Current IPython profile: $self.shell.rc.profile.') |
|
590 | 590 | else: |
|
591 | 591 | print 'No profile active.' |
|
592 | 592 | |
|
593 | 593 | def _inspect(self,meth,oname,**kw): |
|
594 | 594 | """Generic interface to the inspector system. |
|
595 | 595 | |
|
596 | 596 | This function is meant to be called by pdef, pdoc & friends.""" |
|
597 | 597 | |
|
598 | 598 | oname = oname.strip() |
|
599 | 599 | info = Struct(self._ofind(oname)) |
|
600 | 600 | if info.found: |
|
601 | 601 | pmethod = getattr(self.shell.inspector,meth) |
|
602 | 602 | formatter = info.ismagic and self.format_screen or None |
|
603 | 603 | if meth == 'pdoc': |
|
604 | 604 | pmethod(info.obj,oname,formatter) |
|
605 | 605 | elif meth == 'pinfo': |
|
606 | 606 | pmethod(info.obj,oname,formatter,info,**kw) |
|
607 | 607 | else: |
|
608 | 608 | pmethod(info.obj,oname) |
|
609 | 609 | else: |
|
610 | 610 | print 'Object `%s` not found.' % oname |
|
611 | 611 | return 'not found' # so callers can take other action |
|
612 | 612 | |
|
613 | 613 | def magic_pdef(self, parameter_s=''): |
|
614 | 614 | """Print the definition header for any callable object. |
|
615 | 615 | |
|
616 | 616 | If the object is a class, print the constructor information.""" |
|
617 | 617 | self._inspect('pdef',parameter_s) |
|
618 | 618 | |
|
619 | 619 | def magic_pdoc(self, parameter_s=''): |
|
620 | 620 | """Print the docstring for an object. |
|
621 | 621 | |
|
622 | 622 | If the given object is a class, it will print both the class and the |
|
623 | 623 | constructor docstrings.""" |
|
624 | 624 | self._inspect('pdoc',parameter_s) |
|
625 | 625 | |
|
626 | 626 | def magic_psource(self, parameter_s=''): |
|
627 | 627 | """Print (or run through pager) the source code for an object.""" |
|
628 | 628 | self._inspect('psource',parameter_s) |
|
629 | 629 | |
|
630 | 630 | def magic_pfile(self, parameter_s=''): |
|
631 | 631 | """Print (or run through pager) the file where an object is defined. |
|
632 | 632 | |
|
633 | 633 | The file opens at the line where the object definition begins. IPython |
|
634 | 634 | will honor the environment variable PAGER if set, and otherwise will |
|
635 | 635 | do its best to print the file in a convenient form. |
|
636 | 636 | |
|
637 | 637 | If the given argument is not an object currently defined, IPython will |
|
638 | 638 | try to interpret it as a filename (automatically adding a .py extension |
|
639 | 639 | if needed). You can thus use %pfile as a syntax highlighting code |
|
640 | 640 | viewer.""" |
|
641 | 641 | |
|
642 | 642 | # first interpret argument as an object name |
|
643 | 643 | out = self._inspect('pfile',parameter_s) |
|
644 | 644 | # if not, try the input as a filename |
|
645 | 645 | if out == 'not found': |
|
646 | 646 | try: |
|
647 | 647 | filename = get_py_filename(parameter_s) |
|
648 | 648 | except IOError,msg: |
|
649 | 649 | print msg |
|
650 | 650 | return |
|
651 | 651 | page(self.shell.inspector.format(file(filename).read())) |
|
652 | 652 | |
|
653 | 653 | def magic_pinfo(self, parameter_s=''): |
|
654 | 654 | """Provide detailed information about an object. |
|
655 | 655 | |
|
656 | 656 | '%pinfo object' is just a synonym for object? or ?object.""" |
|
657 | 657 | |
|
658 | 658 | #print 'pinfo par: <%s>' % parameter_s # dbg |
|
659 | 659 | |
|
660 | 660 | # detail_level: 0 -> obj? , 1 -> obj?? |
|
661 | 661 | detail_level = 0 |
|
662 | 662 | # We need to detect if we got called as 'pinfo pinfo foo', which can |
|
663 | 663 | # happen if the user types 'pinfo foo?' at the cmd line. |
|
664 | 664 | pinfo,qmark1,oname,qmark2 = \ |
|
665 | 665 | re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups() |
|
666 | 666 | if pinfo or qmark1 or qmark2: |
|
667 | 667 | detail_level = 1 |
|
668 | 668 | if "*" in oname: |
|
669 | 669 | self.magic_psearch(oname) |
|
670 | 670 | else: |
|
671 | 671 | self._inspect('pinfo',oname,detail_level=detail_level) |
|
672 | 672 | |
|
673 | 673 | def magic_psearch(self, parameter_s=''): |
|
674 | 674 | """Search for object in namespaces by wildcard. |
|
675 | 675 | |
|
676 | 676 | %psearch [options] PATTERN [OBJECT TYPE] |
|
677 | 677 | |
|
678 | 678 | Note: ? can be used as a synonym for %psearch, at the beginning or at |
|
679 | 679 | the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the |
|
680 | 680 | rest of the command line must be unchanged (options come first), so |
|
681 | 681 | for example the following forms are equivalent |
|
682 | 682 | |
|
683 | 683 | %psearch -i a* function |
|
684 | 684 | -i a* function? |
|
685 | 685 | ?-i a* function |
|
686 | 686 | |
|
687 | 687 | Arguments: |
|
688 | 688 | |
|
689 | 689 | PATTERN |
|
690 | 690 | |
|
691 | 691 | where PATTERN is a string containing * as a wildcard similar to its |
|
692 | 692 | use in a shell. The pattern is matched in all namespaces on the |
|
693 | 693 | search path. By default objects starting with a single _ are not |
|
694 | 694 | matched, many IPython generated objects have a single |
|
695 | 695 | underscore. The default is case insensitive matching. Matching is |
|
696 | 696 | also done on the attributes of objects and not only on the objects |
|
697 | 697 | in a module. |
|
698 | 698 | |
|
699 | 699 | [OBJECT TYPE] |
|
700 | 700 | |
|
701 | 701 | Is the name of a python type from the types module. The name is |
|
702 | 702 | given in lowercase without the ending type, ex. StringType is |
|
703 | 703 | written string. By adding a type here only objects matching the |
|
704 | 704 | given type are matched. Using all here makes the pattern match all |
|
705 | 705 | types (this is the default). |
|
706 | 706 | |
|
707 | 707 | Options: |
|
708 | 708 | |
|
709 | 709 | -a: makes the pattern match even objects whose names start with a |
|
710 | 710 | single underscore. These names are normally ommitted from the |
|
711 | 711 | search. |
|
712 | 712 | |
|
713 | 713 | -i/-c: make the pattern case insensitive/sensitive. If neither of |
|
714 | 714 | these options is given, the default is read from your ipythonrc |
|
715 | 715 | file. The option name which sets this value is |
|
716 | 716 | 'wildcards_case_sensitive'. If this option is not specified in your |
|
717 | 717 | ipythonrc file, IPython's internal default is to do a case sensitive |
|
718 | 718 | search. |
|
719 | 719 | |
|
720 | 720 | -e/-s NAMESPACE: exclude/search a given namespace. The pattern you |
|
721 | 721 | specifiy can be searched in any of the following namespaces: |
|
722 | 722 | 'builtin', 'user', 'user_global','internal', 'alias', where |
|
723 | 723 | 'builtin' and 'user' are the search defaults. Note that you should |
|
724 | 724 | not use quotes when specifying namespaces. |
|
725 | 725 | |
|
726 | 726 | 'Builtin' contains the python module builtin, 'user' contains all |
|
727 | 727 | user data, 'alias' only contain the shell aliases and no python |
|
728 | 728 | objects, 'internal' contains objects used by IPython. The |
|
729 | 729 | 'user_global' namespace is only used by embedded IPython instances, |
|
730 | 730 | and it contains module-level globals. You can add namespaces to the |
|
731 | 731 | search with -s or exclude them with -e (these options can be given |
|
732 | 732 | more than once). |
|
733 | 733 | |
|
734 | 734 | Examples: |
|
735 | 735 | |
|
736 | 736 | %psearch a* -> objects beginning with an a |
|
737 | 737 | %psearch -e builtin a* -> objects NOT in the builtin space starting in a |
|
738 | 738 | %psearch a* function -> all functions beginning with an a |
|
739 | 739 | %psearch re.e* -> objects beginning with an e in module re |
|
740 | 740 | %psearch r*.e* -> objects that start with e in modules starting in r |
|
741 | 741 | %psearch r*.* string -> all strings in modules beginning with r |
|
742 | 742 | |
|
743 | 743 | Case sensitve search: |
|
744 | 744 | |
|
745 | 745 | %psearch -c a* list all object beginning with lower case a |
|
746 | 746 | |
|
747 | 747 | Show objects beginning with a single _: |
|
748 | 748 | |
|
749 | 749 | %psearch -a _* list objects beginning with a single underscore""" |
|
750 | 750 | |
|
751 | 751 | # default namespaces to be searched |
|
752 | 752 | def_search = ['user','builtin'] |
|
753 | 753 | |
|
754 | 754 | # Process options/args |
|
755 | 755 | opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True) |
|
756 | 756 | opt = opts.get |
|
757 | 757 | shell = self.shell |
|
758 | 758 | psearch = shell.inspector.psearch |
|
759 | 759 | |
|
760 | 760 | # select case options |
|
761 | 761 | if opts.has_key('i'): |
|
762 | 762 | ignore_case = True |
|
763 | 763 | elif opts.has_key('c'): |
|
764 | 764 | ignore_case = False |
|
765 | 765 | else: |
|
766 | 766 | ignore_case = not shell.rc.wildcards_case_sensitive |
|
767 | 767 | |
|
768 | 768 | # Build list of namespaces to search from user options |
|
769 | 769 | def_search.extend(opt('s',[])) |
|
770 | 770 | ns_exclude = ns_exclude=opt('e',[]) |
|
771 | 771 | ns_search = [nm for nm in def_search if nm not in ns_exclude] |
|
772 | 772 | |
|
773 | 773 | # Call the actual search |
|
774 | 774 | try: |
|
775 | 775 | psearch(args,shell.ns_table,ns_search, |
|
776 | 776 | show_all=opt('a'),ignore_case=ignore_case) |
|
777 | 777 | except: |
|
778 | 778 | shell.showtraceback() |
|
779 | 779 | |
|
780 | 780 | def magic_who_ls(self, parameter_s=''): |
|
781 | 781 | """Return a sorted list of all interactive variables. |
|
782 | 782 | |
|
783 | 783 | If arguments are given, only variables of types matching these |
|
784 | 784 | arguments are returned.""" |
|
785 | 785 | |
|
786 | 786 | user_ns = self.shell.user_ns |
|
787 | 787 | out = [] |
|
788 | 788 | typelist = parameter_s.split() |
|
789 | 789 | for i in self.shell.user_ns.keys(): |
|
790 | 790 | if not (i.startswith('_') or i.startswith('_i')) \ |
|
791 | 791 | and not (self.internal_ns.has_key(i) or |
|
792 | 792 | self.user_config_ns.has_key(i)): |
|
793 | 793 | if typelist: |
|
794 | 794 | if type(user_ns[i]).__name__ in typelist: |
|
795 | 795 | out.append(i) |
|
796 | 796 | else: |
|
797 | 797 | out.append(i) |
|
798 | 798 | out.sort() |
|
799 | 799 | return out |
|
800 | 800 | |
|
801 | 801 | def magic_who(self, parameter_s=''): |
|
802 | 802 | """Print all interactive variables, with some minimal formatting. |
|
803 | 803 | |
|
804 | 804 | If any arguments are given, only variables whose type matches one of |
|
805 | 805 | these are printed. For example: |
|
806 | 806 | |
|
807 | 807 | %who function str |
|
808 | 808 | |
|
809 | 809 | will only list functions and strings, excluding all other types of |
|
810 | 810 | variables. To find the proper type names, simply use type(var) at a |
|
811 | 811 | command line to see how python prints type names. For example: |
|
812 | 812 | |
|
813 | 813 | In [1]: type('hello')\\ |
|
814 | 814 | Out[1]: <type 'str'> |
|
815 | 815 | |
|
816 | 816 | indicates that the type name for strings is 'str'. |
|
817 | 817 | |
|
818 | 818 | %who always excludes executed names loaded through your configuration |
|
819 | 819 | file and things which are internal to IPython. |
|
820 | 820 | |
|
821 | 821 | This is deliberate, as typically you may load many modules and the |
|
822 | 822 | purpose of %who is to show you only what you've manually defined.""" |
|
823 | 823 | |
|
824 | 824 | varlist = self.magic_who_ls(parameter_s) |
|
825 | 825 | if not varlist: |
|
826 | 826 | print 'Interactive namespace is empty.' |
|
827 | 827 | return |
|
828 | 828 | |
|
829 | 829 | # if we have variables, move on... |
|
830 | 830 | |
|
831 | 831 | # stupid flushing problem: when prompts have no separators, stdout is |
|
832 | 832 | # getting lost. I'm starting to think this is a python bug. I'm having |
|
833 | 833 | # to force a flush with a print because even a sys.stdout.flush |
|
834 | 834 | # doesn't seem to do anything! |
|
835 | 835 | |
|
836 | 836 | count = 0 |
|
837 | 837 | for i in varlist: |
|
838 | 838 | print i+'\t', |
|
839 | 839 | count += 1 |
|
840 | 840 | if count > 8: |
|
841 | 841 | count = 0 |
|
842 | 842 | |
|
843 | 843 | sys.stdout.flush() # FIXME. Why the hell isn't this flushing??? |
|
844 | 844 | |
|
845 | 845 | print # well, this does force a flush at the expense of an extra \n |
|
846 | 846 | |
|
847 | 847 | def magic_whos(self, parameter_s=''): |
|
848 | 848 | """Like %who, but gives some extra information about each variable. |
|
849 | 849 | |
|
850 | 850 | The same type filtering of %who can be applied here. |
|
851 | 851 | |
|
852 | 852 | For all variables, the type is printed. Additionally it prints: |
|
853 | 853 | |
|
854 | 854 | - For {},[],(): their length. |
|
855 | 855 | |
|
856 | 856 | - For Numeric arrays, a summary with shape, number of elements, |
|
857 | 857 | typecode and size in memory. |
|
858 | 858 | |
|
859 | 859 | - Everything else: a string representation, snipping their middle if |
|
860 | 860 | too long.""" |
|
861 | 861 | |
|
862 | 862 | varnames = self.magic_who_ls(parameter_s) |
|
863 | 863 | if not varnames: |
|
864 | 864 | print 'Interactive namespace is empty.' |
|
865 | 865 | return |
|
866 | 866 | |
|
867 | 867 | # if we have variables, move on... |
|
868 | 868 | |
|
869 | 869 | # for these types, show len() instead of data: |
|
870 | 870 | seq_types = [types.DictType,types.ListType,types.TupleType] |
|
871 | 871 | |
|
872 | 872 | # for Numeric arrays, display summary info |
|
873 | 873 | try: |
|
874 | 874 | import Numeric |
|
875 | 875 | except ImportError: |
|
876 | 876 | array_type = None |
|
877 | 877 | else: |
|
878 | 878 | array_type = Numeric.ArrayType.__name__ |
|
879 | 879 | |
|
880 | 880 | # Find all variable names and types so we can figure out column sizes |
|
881 | 881 | get_vars = lambda i: self.shell.user_ns[i] |
|
882 | 882 | type_name = lambda v: type(v).__name__ |
|
883 | 883 | varlist = map(get_vars,varnames) |
|
884 | 884 | typelist = map(type_name,varlist) |
|
885 | 885 | # column labels and # of spaces as separator |
|
886 | 886 | varlabel = 'Variable' |
|
887 | 887 | typelabel = 'Type' |
|
888 | 888 | datalabel = 'Data/Info' |
|
889 | 889 | colsep = 3 |
|
890 | 890 | # variable format strings |
|
891 | 891 | vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)" |
|
892 | 892 | vfmt_short = '$vstr[:25]<...>$vstr[-25:]' |
|
893 | 893 | aformat = "%s: %s elems, type `%s`, %s bytes" |
|
894 | 894 | # find the size of the columns to format the output nicely |
|
895 | 895 | varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep |
|
896 | 896 | typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep |
|
897 | 897 | # table header |
|
898 | 898 | print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \ |
|
899 | 899 | ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1) |
|
900 | 900 | # and the table itself |
|
901 | 901 | kb = 1024 |
|
902 | 902 | Mb = 1048576 # kb**2 |
|
903 | 903 | for vname,var,vtype in zip(varnames,varlist,typelist): |
|
904 | 904 | print itpl(vformat), |
|
905 | 905 | if vtype in seq_types: |
|
906 | 906 | print len(var) |
|
907 | 907 | elif vtype==array_type: |
|
908 | 908 | vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1] |
|
909 | 909 | vsize = Numeric.size(var) |
|
910 | 910 | vbytes = vsize*var.itemsize() |
|
911 | 911 | if vbytes < 100000: |
|
912 | 912 | print aformat % (vshape,vsize,var.typecode(),vbytes) |
|
913 | 913 | else: |
|
914 | 914 | print aformat % (vshape,vsize,var.typecode(),vbytes), |
|
915 | 915 | if vbytes < Mb: |
|
916 | 916 | print '(%s kb)' % (vbytes/kb,) |
|
917 | 917 | else: |
|
918 | 918 | print '(%s Mb)' % (vbytes/Mb,) |
|
919 | 919 | else: |
|
920 | 920 | vstr = str(var) |
|
921 | 921 | if len(vstr) < 50: |
|
922 | 922 | print vstr |
|
923 | 923 | else: |
|
924 | 924 | printpl(vfmt_short) |
|
925 | 925 | |
|
926 | 926 | def magic_reset(self, parameter_s=''): |
|
927 | 927 | """Resets the namespace by removing all names defined by the user. |
|
928 | 928 | |
|
929 | 929 | Input/Output history are left around in case you need them.""" |
|
930 | 930 | |
|
931 | 931 | ans = raw_input( |
|
932 | 932 | "Once deleted, variables cannot be recovered. Proceed (y/n)? ") |
|
933 | 933 | if not ans.lower() == 'y': |
|
934 | 934 | print 'Nothing done.' |
|
935 | 935 | return |
|
936 | 936 | user_ns = self.shell.user_ns |
|
937 | 937 | for i in self.magic_who_ls(): |
|
938 | 938 | del(user_ns[i]) |
|
939 | 939 | |
|
940 | 940 | def magic_config(self,parameter_s=''): |
|
941 | 941 | """Show IPython's internal configuration.""" |
|
942 | 942 | |
|
943 | 943 | page('Current configuration structure:\n'+ |
|
944 | 944 | pformat(self.shell.rc.dict())) |
|
945 | 945 | |
|
946 | 946 | def magic_logstart(self,parameter_s=''): |
|
947 | 947 | """Start logging anywhere in a session. |
|
948 | 948 | |
|
949 | 949 | %logstart [log_name [log_mode]] |
|
950 | 950 | |
|
951 | 951 | If no name is given, it defaults to a file named 'ipython.log' in your |
|
952 | 952 | current directory, in 'rotate' mode (see below). |
|
953 | 953 | |
|
954 | 954 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
|
955 | 955 | history up to that point and then continues logging. |
|
956 | 956 | |
|
957 | 957 | %logstart takes a second optional parameter: logging mode. This can be one |
|
958 | 958 | of (note that the modes are given unquoted):\\ |
|
959 | 959 | over: overwrite existing log.\\ |
|
960 | 960 | backup: rename (if exists) to name~ and start name.\\ |
|
961 | 961 | append: well, that says it.\\ |
|
962 | 962 | rotate: create rotating logs name.1~, name.2~, etc. |
|
963 | 963 | """ |
|
964 | 964 | |
|
965 | 965 | #FIXME. This function should all be moved to the Logger class. |
|
966 | 966 | |
|
967 | 967 | valid_modes = qw('over backup append rotate') |
|
968 | 968 | if self.LOG: |
|
969 | 969 | print 'Logging is already in place. Logfile:',self.LOG |
|
970 | 970 | return |
|
971 | 971 | |
|
972 | 972 | par = parameter_s.strip() |
|
973 | 973 | if not par: |
|
974 | 974 | logname = self.LOGDEF |
|
975 | 975 | logmode = 'rotate' # use rotate for the auto-generated logs |
|
976 | 976 | else: |
|
977 | 977 | try: |
|
978 | 978 | logname,logmode = par.split() |
|
979 | 979 | except: |
|
980 | 980 | try: |
|
981 | 981 | logname = par |
|
982 | 982 | logmode = 'backup' |
|
983 | 983 | except: |
|
984 | 984 | warn('Usage: %log [log_name [log_mode]]') |
|
985 | 985 | return |
|
986 | 986 | if not logmode in valid_modes: |
|
987 | 987 | warn('Logging NOT activated.\n' |
|
988 | 988 | 'Usage: %log [log_name [log_mode]]\n' |
|
989 | 989 | 'Valid modes: '+str(valid_modes)) |
|
990 | 990 | return |
|
991 | 991 | |
|
992 | 992 | # If we made it this far, I think we're ok: |
|
993 | 993 | print 'Activating auto-logging.' |
|
994 | 994 | print 'Current session state plus future input saved to:',logname |
|
995 | 995 | print 'Logging mode: ',logmode |
|
996 | 996 | # put logname into rc struct as if it had been called on the command line, |
|
997 | 997 | # so it ends up saved in the log header |
|
998 | 998 | # Save it in case we need to restore it... |
|
999 | 999 | old_logfile = self.shell.rc.opts.get('logfile','') |
|
1000 | 1000 | logname = os.path.expanduser(logname) |
|
1001 | 1001 | self.shell.rc.opts.logfile = logname |
|
1002 | 1002 | self.LOGMODE = logmode # FIXME: this should be set through a function. |
|
1003 | 1003 | try: |
|
1004 | 1004 | header = str(self.LOGHEAD) |
|
1005 | 1005 | self.create_log(header,logname) |
|
1006 | 1006 | self.logstart(header,logname) |
|
1007 | 1007 | except: |
|
1008 | 1008 | self.LOG = '' # we are NOT logging, something went wrong |
|
1009 | 1009 | self.shell.rc.opts.logfile = old_logfile |
|
1010 | 1010 | warn("Couldn't start log: "+str(sys.exc_info()[1])) |
|
1011 | 1011 | else: # log input history up to this point |
|
1012 | 1012 | self.logfile.write(self.shell.user_ns['_ih'][1:]) |
|
1013 | 1013 | self.logfile.flush() |
|
1014 | 1014 | |
|
1015 | 1015 | def magic_logoff(self,parameter_s=''): |
|
1016 | 1016 | """Temporarily stop logging. |
|
1017 | 1017 | |
|
1018 | 1018 | You must have previously started logging.""" |
|
1019 | 1019 | self.switch_log(0) |
|
1020 | 1020 | |
|
1021 | 1021 | def magic_logon(self,parameter_s=''): |
|
1022 | 1022 | """Restart logging. |
|
1023 | 1023 | |
|
1024 | 1024 | This function is for restarting logging which you've temporarily |
|
1025 | 1025 | stopped with %logoff. For starting logging for the first time, you |
|
1026 | 1026 | must use the %logstart function, which allows you to specify an |
|
1027 | 1027 | optional log filename.""" |
|
1028 | 1028 | |
|
1029 | 1029 | self.switch_log(1) |
|
1030 | 1030 | |
|
1031 | 1031 | def magic_logstate(self,parameter_s=''): |
|
1032 | 1032 | """Print the status of the logging system.""" |
|
1033 | 1033 | |
|
1034 | 1034 | self.logstate() |
|
1035 | 1035 | |
|
1036 | 1036 | def magic_pdb(self, parameter_s=''): |
|
1037 | 1037 | """Control the calling of the pdb interactive debugger. |
|
1038 | 1038 | |
|
1039 | 1039 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
|
1040 | 1040 | argument it works as a toggle. |
|
1041 | 1041 | |
|
1042 | 1042 | When an exception is triggered, IPython can optionally call the |
|
1043 | 1043 | interactive pdb debugger after the traceback printout. %pdb toggles |
|
1044 | 1044 | this feature on and off.""" |
|
1045 | 1045 | |
|
1046 | 1046 | par = parameter_s.strip().lower() |
|
1047 | 1047 | |
|
1048 | 1048 | if par: |
|
1049 | 1049 | try: |
|
1050 | 1050 | pdb = {'off':0,'0':0,'on':1,'1':1}[par] |
|
1051 | 1051 | except KeyError: |
|
1052 | print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.' | |
|
1052 | print 'Incorrect argument. Use on/1, off/0, or nothing for a toggle.' | |
|
1053 | 1053 | return |
|
1054 | 1054 | else: |
|
1055 | 1055 | self.shell.InteractiveTB.call_pdb = pdb |
|
1056 | 1056 | else: |
|
1057 |
|
|
|
1058 | print 'Automatic pdb calling has been turned',\ | |
|
1059 |
|
|
|
1057 | new_pdb = not self.shell.InteractiveTB.call_pdb | |
|
1058 | self.shell.InteractiveTB.call_pdb = new_pdb | |
|
1059 | if self.shell.isthreaded: | |
|
1060 | try: | |
|
1061 | self.sys_excepthook.call_pdb = new_pdb | |
|
1062 | except: | |
|
1063 | warn('Failed to activate pdb for threaded exception handler') | |
|
1064 | ||
|
1065 | print 'Automatic pdb calling has been turned',on_off(new_pdb) | |
|
1066 | ||
|
1060 | 1067 | |
|
1061 | 1068 | |
|
1062 | 1069 | def magic_prun(self, parameter_s ='',user_mode=1, |
|
1063 | 1070 | opts=None,arg_lst=None,prog_ns=None): |
|
1064 | 1071 | |
|
1065 | 1072 | """Run a statement through the python code profiler. |
|
1066 | 1073 | |
|
1067 | 1074 | Usage:\\ |
|
1068 | 1075 | %prun [options] statement |
|
1069 | 1076 | |
|
1070 | 1077 | The given statement (which doesn't require quote marks) is run via the |
|
1071 | 1078 | python profiler in a manner similar to the profile.run() function. |
|
1072 | 1079 | Namespaces are internally managed to work correctly; profile.run |
|
1073 | 1080 | cannot be used in IPython because it makes certain assumptions about |
|
1074 | 1081 | namespaces which do not hold under IPython. |
|
1075 | 1082 | |
|
1076 | 1083 | Options: |
|
1077 | 1084 | |
|
1078 | 1085 | -l <limit>: you can place restrictions on what or how much of the |
|
1079 | 1086 | profile gets printed. The limit value can be: |
|
1080 | 1087 | |
|
1081 | 1088 | * A string: only information for function names containing this string |
|
1082 | 1089 | is printed. |
|
1083 | 1090 | |
|
1084 | 1091 | * An integer: only these many lines are printed. |
|
1085 | 1092 | |
|
1086 | 1093 | * A float (between 0 and 1): this fraction of the report is printed |
|
1087 | 1094 | (for example, use a limit of 0.4 to see the topmost 40% only). |
|
1088 | 1095 | |
|
1089 | 1096 | You can combine several limits with repeated use of the option. For |
|
1090 | 1097 | example, '-l __init__ -l 5' will print only the topmost 5 lines of |
|
1091 | 1098 | information about class constructors. |
|
1092 | 1099 | |
|
1093 | 1100 | -r: return the pstats.Stats object generated by the profiling. This |
|
1094 | 1101 | object has all the information about the profile in it, and you can |
|
1095 | 1102 | later use it for further analysis or in other functions. |
|
1096 | 1103 | |
|
1097 | 1104 | Since magic functions have a particular form of calling which prevents |
|
1098 | 1105 | you from writing something like:\\ |
|
1099 | 1106 | In [1]: p = %prun -r print 4 # invalid!\\ |
|
1100 | 1107 | you must instead use IPython's automatic variables to assign this:\\ |
|
1101 | 1108 | In [1]: %prun -r print 4 \\ |
|
1102 | 1109 | Out[1]: <pstats.Stats instance at 0x8222cec>\\ |
|
1103 | 1110 | In [2]: stats = _ |
|
1104 | 1111 | |
|
1105 | 1112 | If you really need to assign this value via an explicit function call, |
|
1106 | 1113 | you can always tap directly into the true name of the magic function |
|
1107 | 1114 | by using the ipmagic function (which IPython automatically adds to the |
|
1108 | 1115 | builtins):\\ |
|
1109 | 1116 | In [3]: stats = ipmagic('prun','-r print 4') |
|
1110 | 1117 | |
|
1111 | 1118 | You can type ipmagic? for more details on ipmagic. |
|
1112 | 1119 | |
|
1113 | 1120 | -s <key>: sort profile by given key. You can provide more than one key |
|
1114 | 1121 | by using the option several times: '-s key1 -s key2 -s key3...'. The |
|
1115 | 1122 | default sorting key is 'time'. |
|
1116 | 1123 | |
|
1117 | 1124 | The following is copied verbatim from the profile documentation |
|
1118 | 1125 | referenced below: |
|
1119 | 1126 | |
|
1120 | 1127 | When more than one key is provided, additional keys are used as |
|
1121 | 1128 | secondary criteria when the there is equality in all keys selected |
|
1122 | 1129 | before them. |
|
1123 | 1130 | |
|
1124 | 1131 | Abbreviations can be used for any key names, as long as the |
|
1125 | 1132 | abbreviation is unambiguous. The following are the keys currently |
|
1126 | 1133 | defined: |
|
1127 | 1134 | |
|
1128 | 1135 | Valid Arg Meaning\\ |
|
1129 | 1136 | "calls" call count\\ |
|
1130 | 1137 | "cumulative" cumulative time\\ |
|
1131 | 1138 | "file" file name\\ |
|
1132 | 1139 | "module" file name\\ |
|
1133 | 1140 | "pcalls" primitive call count\\ |
|
1134 | 1141 | "line" line number\\ |
|
1135 | 1142 | "name" function name\\ |
|
1136 | 1143 | "nfl" name/file/line\\ |
|
1137 | 1144 | "stdname" standard name\\ |
|
1138 | 1145 | "time" internal time |
|
1139 | 1146 | |
|
1140 | 1147 | Note that all sorts on statistics are in descending order (placing |
|
1141 | 1148 | most time consuming items first), where as name, file, and line number |
|
1142 | 1149 | searches are in ascending order (i.e., alphabetical). The subtle |
|
1143 | 1150 | distinction between "nfl" and "stdname" is that the standard name is a |
|
1144 | 1151 | sort of the name as printed, which means that the embedded line |
|
1145 | 1152 | numbers get compared in an odd way. For example, lines 3, 20, and 40 |
|
1146 | 1153 | would (if the file names were the same) appear in the string order |
|
1147 | 1154 | "20" "3" and "40". In contrast, "nfl" does a numeric compare of the |
|
1148 | 1155 | line numbers. In fact, sort_stats("nfl") is the same as |
|
1149 | 1156 | sort_stats("name", "file", "line"). |
|
1150 | 1157 | |
|
1151 | 1158 | -T <filename>: save profile results as shown on screen to a text |
|
1152 | 1159 | file. The profile is still shown on screen. |
|
1153 | 1160 | |
|
1154 | 1161 | -D <filename>: save (via dump_stats) profile statistics to given |
|
1155 | 1162 | filename. This data is in a format understod by the pstats module, and |
|
1156 | 1163 | is generated by a call to the dump_stats() method of profile |
|
1157 | 1164 | objects. The profile is still shown on screen. |
|
1158 | 1165 | |
|
1159 | 1166 | If you want to run complete programs under the profiler's control, use |
|
1160 | 1167 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts |
|
1161 | 1168 | contains profiler specific options as described here. |
|
1162 | 1169 | |
|
1163 | 1170 | You can read the complete documentation for the profile module with:\\ |
|
1164 | 1171 | In [1]: import profile; profile.help() """ |
|
1165 | 1172 | |
|
1166 | 1173 | opts_def = Struct(D=[''],l=[],s=['time'],T=['']) |
|
1167 | 1174 | # protect user quote marks |
|
1168 | 1175 | parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'") |
|
1169 | 1176 | |
|
1170 | 1177 | if user_mode: # regular user call |
|
1171 | 1178 | opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:', |
|
1172 | 1179 | list_all=1) |
|
1173 | 1180 | namespace = self.shell.user_ns |
|
1174 | 1181 | else: # called to run a program by %run -p |
|
1175 | 1182 | try: |
|
1176 | 1183 | filename = get_py_filename(arg_lst[0]) |
|
1177 | 1184 | except IOError,msg: |
|
1178 | 1185 | error(msg) |
|
1179 | 1186 | return |
|
1180 | 1187 | |
|
1181 | 1188 | arg_str = 'execfile(filename,prog_ns)' |
|
1182 | 1189 | namespace = locals() |
|
1183 | 1190 | |
|
1184 | 1191 | opts.merge(opts_def) |
|
1185 | 1192 | |
|
1186 | 1193 | prof = profile.Profile() |
|
1187 | 1194 | try: |
|
1188 | 1195 | prof = prof.runctx(arg_str,namespace,namespace) |
|
1189 | 1196 | sys_exit = '' |
|
1190 | 1197 | except SystemExit: |
|
1191 | 1198 | sys_exit = """*** SystemExit exception caught in code being profiled.""" |
|
1192 | 1199 | |
|
1193 | 1200 | stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s) |
|
1194 | 1201 | |
|
1195 | 1202 | lims = opts.l |
|
1196 | 1203 | if lims: |
|
1197 | 1204 | lims = [] # rebuild lims with ints/floats/strings |
|
1198 | 1205 | for lim in opts.l: |
|
1199 | 1206 | try: |
|
1200 | 1207 | lims.append(int(lim)) |
|
1201 | 1208 | except ValueError: |
|
1202 | 1209 | try: |
|
1203 | 1210 | lims.append(float(lim)) |
|
1204 | 1211 | except ValueError: |
|
1205 | 1212 | lims.append(lim) |
|
1206 | 1213 | |
|
1207 | 1214 | # trap output |
|
1208 | 1215 | sys_stdout = sys.stdout |
|
1209 | 1216 | stdout_trap = StringIO() |
|
1210 | 1217 | try: |
|
1211 | 1218 | sys.stdout = stdout_trap |
|
1212 | 1219 | stats.print_stats(*lims) |
|
1213 | 1220 | finally: |
|
1214 | 1221 | sys.stdout = sys_stdout |
|
1215 | 1222 | output = stdout_trap.getvalue() |
|
1216 | 1223 | output = output.rstrip() |
|
1217 | 1224 | |
|
1218 | 1225 | page(output,screen_lines=self.shell.rc.screen_length) |
|
1219 | 1226 | print sys_exit, |
|
1220 | 1227 | |
|
1221 | 1228 | dump_file = opts.D[0] |
|
1222 | 1229 | text_file = opts.T[0] |
|
1223 | 1230 | if dump_file: |
|
1224 | 1231 | prof.dump_stats(dump_file) |
|
1225 | 1232 | print '\n*** Profile stats marshalled to file',\ |
|
1226 | 1233 | `dump_file`+'.',sys_exit |
|
1227 | 1234 | if text_file: |
|
1228 | 1235 | file(text_file,'w').write(output) |
|
1229 | 1236 | print '\n*** Profile printout saved to text file',\ |
|
1230 | 1237 | `text_file`+'.',sys_exit |
|
1231 | 1238 | |
|
1232 | 1239 | if opts.has_key('r'): |
|
1233 | 1240 | return stats |
|
1234 | 1241 | else: |
|
1235 | 1242 | return None |
|
1236 | 1243 | |
|
1237 | 1244 | def magic_run(self, parameter_s ='',runner=None): |
|
1238 | 1245 | """Run the named file inside IPython as a program. |
|
1239 | 1246 | |
|
1240 | 1247 | Usage:\\ |
|
1241 | 1248 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] |
|
1242 | 1249 | |
|
1243 | 1250 | Parameters after the filename are passed as command-line arguments to |
|
1244 | 1251 | the program (put in sys.argv). Then, control returns to IPython's |
|
1245 | 1252 | prompt. |
|
1246 | 1253 | |
|
1247 | 1254 | This is similar to running at a system prompt:\\ |
|
1248 | 1255 | $ python file args\\ |
|
1249 | 1256 | but with the advantage of giving you IPython's tracebacks, and of |
|
1250 | 1257 | loading all variables into your interactive namespace for further use |
|
1251 | 1258 | (unless -p is used, see below). |
|
1252 | 1259 | |
|
1253 | 1260 | The file is executed in a namespace initially consisting only of |
|
1254 | 1261 | __name__=='__main__' and sys.argv constructed as indicated. It thus |
|
1255 | 1262 | sees its environment as if it were being run as a stand-alone |
|
1256 | 1263 | program. But after execution, the IPython interactive namespace gets |
|
1257 | 1264 | updated with all variables defined in the program (except for __name__ |
|
1258 | 1265 | and sys.argv). This allows for very convenient loading of code for |
|
1259 | 1266 | interactive work, while giving each program a 'clean sheet' to run in. |
|
1260 | 1267 | |
|
1261 | 1268 | Options: |
|
1262 | 1269 | |
|
1263 | 1270 | -n: __name__ is NOT set to '__main__', but to the running file's name |
|
1264 | 1271 | without extension (as python does under import). This allows running |
|
1265 | 1272 | scripts and reloading the definitions in them without calling code |
|
1266 | 1273 | protected by an ' if __name__ == "__main__" ' clause. |
|
1267 | 1274 | |
|
1268 | 1275 | -i: run the file in IPython's namespace instead of an empty one. This |
|
1269 | 1276 | is useful if you are experimenting with code written in a text editor |
|
1270 | 1277 | which depends on variables defined interactively. |
|
1271 | 1278 | |
|
1272 | 1279 | -e: ignore sys.exit() calls or SystemExit exceptions in the script |
|
1273 | 1280 | being run. This is particularly useful if IPython is being used to |
|
1274 | 1281 | run unittests, which always exit with a sys.exit() call. In such |
|
1275 | 1282 | cases you are interested in the output of the test results, not in |
|
1276 | 1283 | seeing a traceback of the unittest module. |
|
1277 | 1284 | |
|
1278 | 1285 | -t: print timing information at the end of the run. IPython will give |
|
1279 | 1286 | you an estimated CPU time consumption for your script, which under |
|
1280 | 1287 | Unix uses the resource module to avoid the wraparound problems of |
|
1281 | 1288 | time.clock(). Under Unix, an estimate of time spent on system tasks |
|
1282 | 1289 | is also given (for Windows platforms this is reported as 0.0). |
|
1283 | 1290 | |
|
1284 | 1291 | If -t is given, an additional -N<N> option can be given, where <N> |
|
1285 | 1292 | must be an integer indicating how many times you want the script to |
|
1286 | 1293 | run. The final timing report will include total and per run results. |
|
1287 | 1294 | |
|
1288 | 1295 | For example (testing the script uniq_stable.py): |
|
1289 | 1296 | |
|
1290 | 1297 | In [1]: run -t uniq_stable |
|
1291 | 1298 | |
|
1292 | 1299 | IPython CPU timings (estimated):\\ |
|
1293 | 1300 | User : 0.19597 s.\\ |
|
1294 | 1301 | System: 0.0 s.\\ |
|
1295 | 1302 | |
|
1296 | 1303 | In [2]: run -t -N5 uniq_stable |
|
1297 | 1304 | |
|
1298 | 1305 | IPython CPU timings (estimated):\\ |
|
1299 | 1306 | Total runs performed: 5\\ |
|
1300 | 1307 | Times : Total Per run\\ |
|
1301 | 1308 | User : 0.910862 s, 0.1821724 s.\\ |
|
1302 | 1309 | System: 0.0 s, 0.0 s. |
|
1303 | 1310 | |
|
1304 | 1311 | -d: run your program under the control of pdb, the Python debugger. |
|
1305 | 1312 | This allows you to execute your program step by step, watch variables, |
|
1306 | 1313 | etc. Internally, what IPython does is similar to calling: |
|
1307 | 1314 | |
|
1308 | 1315 | pdb.run('execfile("YOURFILENAME")') |
|
1309 | 1316 | |
|
1310 | 1317 | with a breakpoint set on line 1 of your file. You can change the line |
|
1311 | 1318 | number for this automatic breakpoint to be <N> by using the -bN option |
|
1312 | 1319 | (where N must be an integer). For example: |
|
1313 | 1320 | |
|
1314 | 1321 | %run -d -b40 myscript |
|
1315 | 1322 | |
|
1316 | 1323 | will set the first breakpoint at line 40 in myscript.py. Note that |
|
1317 | 1324 | the first breakpoint must be set on a line which actually does |
|
1318 | 1325 | something (not a comment or docstring) for it to stop execution. |
|
1319 | 1326 | |
|
1320 | 1327 | When the pdb debugger starts, you will see a (Pdb) prompt. You must |
|
1321 | 1328 | first enter 'c' (without qoutes) to start execution up to the first |
|
1322 | 1329 | breakpoint. |
|
1323 | 1330 | |
|
1324 | 1331 | Entering 'help' gives information about the use of the debugger. You |
|
1325 | 1332 | can easily see pdb's full documentation with "import pdb;pdb.help()" |
|
1326 | 1333 | at a prompt. |
|
1327 | 1334 | |
|
1328 | 1335 | -p: run program under the control of the Python profiler module (which |
|
1329 | 1336 | prints a detailed report of execution times, function calls, etc). |
|
1330 | 1337 | |
|
1331 | 1338 | You can pass other options after -p which affect the behavior of the |
|
1332 | 1339 | profiler itself. See the docs for %prun for details. |
|
1333 | 1340 | |
|
1334 | 1341 | In this mode, the program's variables do NOT propagate back to the |
|
1335 | 1342 | IPython interactive namespace (because they remain in the namespace |
|
1336 | 1343 | where the profiler executes them). |
|
1337 | 1344 | |
|
1338 | 1345 | Internally this triggers a call to %prun, see its documentation for |
|
1339 | 1346 | details on the options available specifically for profiling.""" |
|
1340 | 1347 | |
|
1341 | 1348 | # get arguments and set sys.argv for program to be run. |
|
1342 | 1349 | opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e', |
|
1343 | 1350 | mode='list',list_all=1) |
|
1344 | 1351 | |
|
1345 | 1352 | try: |
|
1346 | 1353 | filename = get_py_filename(arg_lst[0]) |
|
1347 | 1354 | except IndexError: |
|
1348 | 1355 | warn('you must provide at least a filename.') |
|
1349 | 1356 | print '\n%run:\n',OInspect.getdoc(self.magic_run) |
|
1350 | 1357 | return |
|
1351 | 1358 | except IOError,msg: |
|
1352 | 1359 | error(msg) |
|
1353 | 1360 | return |
|
1354 | 1361 | |
|
1355 | 1362 | # Control the response to exit() calls made by the script being run |
|
1356 | 1363 | exit_ignore = opts.has_key('e') |
|
1357 | 1364 | |
|
1358 | 1365 | # Make sure that the running script gets a proper sys.argv as if it |
|
1359 | 1366 | # were run from a system shell. |
|
1360 | 1367 | save_argv = sys.argv # save it for later restoring |
|
1361 | 1368 | sys.argv = [filename]+ arg_lst[1:] # put in the proper filename |
|
1362 | 1369 | |
|
1363 | 1370 | if opts.has_key('i'): |
|
1364 | 1371 | prog_ns = self.shell.user_ns |
|
1365 | 1372 | __name__save = self.shell.user_ns['__name__'] |
|
1366 | 1373 | prog_ns['__name__'] = '__main__' |
|
1367 | 1374 | else: |
|
1368 | 1375 | if opts.has_key('n'): |
|
1369 | 1376 | name = os.path.splitext(os.path.basename(filename))[0] |
|
1370 | 1377 | else: |
|
1371 | 1378 | name = '__main__' |
|
1372 | 1379 | prog_ns = {'__name__':name} |
|
1373 | 1380 | |
|
1374 | 1381 | # pickle fix. See iplib for an explanation |
|
1375 | 1382 | sys.modules[prog_ns['__name__']] = FakeModule(prog_ns) |
|
1376 | 1383 | |
|
1377 | 1384 | stats = None |
|
1378 | 1385 | try: |
|
1379 | 1386 | if opts.has_key('p'): |
|
1380 | 1387 | stats = self.magic_prun('',0,opts,arg_lst,prog_ns) |
|
1381 | 1388 | else: |
|
1382 | 1389 | if opts.has_key('d'): |
|
1383 | 1390 | deb = Debugger.Pdb(self.shell.rc.colors) |
|
1384 | 1391 | # reset Breakpoint state, which is moronically kept |
|
1385 | 1392 | # in a class |
|
1386 | 1393 | bdb.Breakpoint.next = 1 |
|
1387 | 1394 | bdb.Breakpoint.bplist = {} |
|
1388 | 1395 | bdb.Breakpoint.bpbynumber = [None] |
|
1389 | 1396 | # Set an initial breakpoint to stop execution |
|
1390 | 1397 | maxtries = 10 |
|
1391 | 1398 | bp = int(opts.get('b',[1])[0]) |
|
1392 | 1399 | checkline = deb.checkline(filename,bp) |
|
1393 | 1400 | if not checkline: |
|
1394 | 1401 | for bp in range(bp+1,bp+maxtries+1): |
|
1395 | 1402 | if deb.checkline(filename,bp): |
|
1396 | 1403 | break |
|
1397 | 1404 | else: |
|
1398 | 1405 | msg = ("\nI failed to find a valid line to set " |
|
1399 | 1406 | "a breakpoint\n" |
|
1400 | 1407 | "after trying up to line: %s.\n" |
|
1401 | 1408 | "Please set a valid breakpoint manually " |
|
1402 | 1409 | "with the -b option." % bp) |
|
1403 | 1410 | error(msg) |
|
1404 | 1411 | return |
|
1405 | 1412 | # if we find a good linenumber, set the breakpoint |
|
1406 | 1413 | deb.do_break('%s:%s' % (filename,bp)) |
|
1407 | 1414 | # Start file run |
|
1408 | 1415 | print "NOTE: Enter 'c' at the", |
|
1409 | 1416 | print "ipdb> prompt to start your script." |
|
1410 | 1417 | try: |
|
1411 | 1418 | deb.run('execfile("%s")' % filename,prog_ns) |
|
1412 | 1419 | except: |
|
1413 | 1420 | etype, value, tb = sys.exc_info() |
|
1414 | 1421 | # Skip three frames in the traceback: the %run one, |
|
1415 | 1422 | # one inside bdb.py, and the command-line typed by the |
|
1416 | 1423 | # user (run by exec in pdb itself). |
|
1417 | 1424 | self.shell.InteractiveTB(etype,value,tb,tb_offset=3) |
|
1418 | 1425 | else: |
|
1419 | 1426 | if runner is None: |
|
1420 | 1427 | runner = self.shell.safe_execfile |
|
1421 | 1428 | if opts.has_key('t'): |
|
1422 | 1429 | try: |
|
1423 | 1430 | nruns = int(opts['N'][0]) |
|
1424 | 1431 | if nruns < 1: |
|
1425 | 1432 | error('Number of runs must be >=1') |
|
1426 | 1433 | return |
|
1427 | 1434 | except (KeyError): |
|
1428 | 1435 | nruns = 1 |
|
1429 | 1436 | if nruns == 1: |
|
1430 | 1437 | t0 = clock2() |
|
1431 | 1438 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1432 | 1439 | t1 = clock2() |
|
1433 | 1440 | t_usr = t1[0]-t0[0] |
|
1434 | 1441 | t_sys = t1[1]-t1[1] |
|
1435 | 1442 | print "\nIPython CPU timings (estimated):" |
|
1436 | 1443 | print " User : %10s s." % t_usr |
|
1437 | 1444 | print " System: %10s s." % t_sys |
|
1438 | 1445 | else: |
|
1439 | 1446 | runs = range(nruns) |
|
1440 | 1447 | t0 = clock2() |
|
1441 | 1448 | for nr in runs: |
|
1442 | 1449 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1443 | 1450 | t1 = clock2() |
|
1444 | 1451 | t_usr = t1[0]-t0[0] |
|
1445 | 1452 | t_sys = t1[1]-t1[1] |
|
1446 | 1453 | print "\nIPython CPU timings (estimated):" |
|
1447 | 1454 | print "Total runs performed:",nruns |
|
1448 | 1455 | print " Times : %10s %10s" % ('Total','Per run') |
|
1449 | 1456 | print " User : %10s s, %10s s." % (t_usr,t_usr/nruns) |
|
1450 | 1457 | print " System: %10s s, %10s s." % (t_sys,t_sys/nruns) |
|
1451 | 1458 | |
|
1452 | 1459 | else: |
|
1453 | 1460 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1454 | 1461 | if opts.has_key('i'): |
|
1455 | 1462 | self.shell.user_ns['__name__'] = __name__save |
|
1456 | 1463 | else: |
|
1457 | 1464 | # update IPython interactive namespace |
|
1458 | 1465 | del prog_ns['__name__'] |
|
1459 | 1466 | self.shell.user_ns.update(prog_ns) |
|
1460 | 1467 | finally: |
|
1461 | 1468 | sys.argv = save_argv |
|
1462 | 1469 | return stats |
|
1463 | 1470 | |
|
1464 | 1471 | def magic_runlog(self, parameter_s =''): |
|
1465 | 1472 | """Run files as logs. |
|
1466 | 1473 | |
|
1467 | 1474 | Usage:\\ |
|
1468 | 1475 | %runlog file1 file2 ... |
|
1469 | 1476 | |
|
1470 | 1477 | Run the named files (treating them as log files) in sequence inside |
|
1471 | 1478 | the interpreter, and return to the prompt. This is much slower than |
|
1472 | 1479 | %run because each line is executed in a try/except block, but it |
|
1473 | 1480 | allows running files with syntax errors in them. |
|
1474 | 1481 | |
|
1475 | 1482 | Normally IPython will guess when a file is one of its own logfiles, so |
|
1476 | 1483 | you can typically use %run even for logs. This shorthand allows you to |
|
1477 | 1484 | force any file to be treated as a log file.""" |
|
1478 | 1485 | |
|
1479 | 1486 | for f in parameter_s.split(): |
|
1480 | 1487 | self.shell.safe_execfile(f,self.shell.user_ns, |
|
1481 | 1488 | self.shell.user_ns,islog=1) |
|
1482 | 1489 | |
|
1483 | 1490 | def magic_time(self,parameter_s = ''): |
|
1484 | 1491 | """Time execution of a Python statement or expression. |
|
1485 | 1492 | |
|
1486 | 1493 | The CPU and wall clock times are printed, and the value of the |
|
1487 | 1494 | expression (if any) is returned. Note that under Win32, system time |
|
1488 | 1495 | is always reported as 0, since it can not be measured. |
|
1489 | 1496 | |
|
1490 | 1497 | This function provides very basic timing functionality. In Python |
|
1491 | 1498 | 2.3, the timeit module offers more control and sophistication, but for |
|
1492 | 1499 | now IPython supports Python 2.2, so we can not rely on timeit being |
|
1493 | 1500 | present. |
|
1494 | 1501 | |
|
1495 | 1502 | Some examples: |
|
1496 | 1503 | |
|
1497 | 1504 | In [1]: time 2**128 |
|
1498 | 1505 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
1499 | 1506 | Wall time: 0.00 |
|
1500 | 1507 | Out[1]: 340282366920938463463374607431768211456L |
|
1501 | 1508 | |
|
1502 | 1509 | In [2]: n = 1000000 |
|
1503 | 1510 | |
|
1504 | 1511 | In [3]: time sum(range(n)) |
|
1505 | 1512 | CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s |
|
1506 | 1513 | Wall time: 1.37 |
|
1507 | 1514 | Out[3]: 499999500000L |
|
1508 | 1515 | |
|
1509 | 1516 | In [4]: time print 'hello world' |
|
1510 | 1517 | hello world |
|
1511 | 1518 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
1512 | 1519 | Wall time: 0.00 |
|
1513 | 1520 | """ |
|
1514 | 1521 | |
|
1515 | 1522 | # fail immediately if the given expression can't be compiled |
|
1516 | 1523 | try: |
|
1517 | 1524 | mode = 'eval' |
|
1518 | 1525 | code = compile(parameter_s,'<timed eval>',mode) |
|
1519 | 1526 | except SyntaxError: |
|
1520 | 1527 | mode = 'exec' |
|
1521 | 1528 | code = compile(parameter_s,'<timed exec>',mode) |
|
1522 | 1529 | # skew measurement as little as possible |
|
1523 | 1530 | glob = self.shell.user_ns |
|
1524 | 1531 | clk = clock2 |
|
1525 | 1532 | wtime = time.time |
|
1526 | 1533 | # time execution |
|
1527 | 1534 | wall_st = wtime() |
|
1528 | 1535 | if mode=='eval': |
|
1529 | 1536 | st = clk() |
|
1530 | 1537 | out = eval(code,glob) |
|
1531 | 1538 | end = clk() |
|
1532 | 1539 | else: |
|
1533 | 1540 | st = clk() |
|
1534 | 1541 | exec code in glob |
|
1535 | 1542 | end = clk() |
|
1536 | 1543 | out = None |
|
1537 | 1544 | wall_end = wtime() |
|
1538 | 1545 | # Compute actual times and report |
|
1539 | 1546 | wall_time = wall_end-wall_st |
|
1540 | 1547 | cpu_user = end[0]-st[0] |
|
1541 | 1548 | cpu_sys = end[1]-st[1] |
|
1542 | 1549 | cpu_tot = cpu_user+cpu_sys |
|
1543 | 1550 | print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \ |
|
1544 | 1551 | (cpu_user,cpu_sys,cpu_tot) |
|
1545 | 1552 | print "Wall time: %.2f" % wall_time |
|
1546 | 1553 | return out |
|
1547 | 1554 | |
|
1548 | 1555 | def magic_macro(self,parameter_s = ''): |
|
1549 | 1556 | """Define a set of input lines as a macro for future re-execution. |
|
1550 | 1557 | |
|
1551 | 1558 | Usage:\\ |
|
1552 | 1559 | %macro name n1:n2 n3:n4 ... n5 .. n6 ... |
|
1553 | 1560 | |
|
1554 | 1561 | This will define a global variable called `name` which is a string |
|
1555 | 1562 | made of joining the slices and lines you specify (n1,n2,... numbers |
|
1556 | 1563 | above) from your input history into a single string. This variable |
|
1557 | 1564 | acts like an automatic function which re-executes those lines as if |
|
1558 | 1565 | you had typed them. You just type 'name' at the prompt and the code |
|
1559 | 1566 | executes. |
|
1560 | 1567 | |
|
1561 | 1568 | Note that the slices use the standard Python slicing notation (5:8 |
|
1562 | 1569 | means include lines numbered 5,6,7). |
|
1563 | 1570 | |
|
1564 | 1571 | For example, if your history contains (%hist prints it): |
|
1565 | 1572 | |
|
1566 | 1573 | 44: x=1\\ |
|
1567 | 1574 | 45: y=3\\ |
|
1568 | 1575 | 46: z=x+y\\ |
|
1569 | 1576 | 47: print x\\ |
|
1570 | 1577 | 48: a=5\\ |
|
1571 | 1578 | 49: print 'x',x,'y',y\\ |
|
1572 | 1579 | |
|
1573 | 1580 | you can create a macro with lines 44 through 47 (included) and line 49 |
|
1574 | 1581 | called my_macro with: |
|
1575 | 1582 | |
|
1576 | 1583 | In [51]: %macro my_macro 44:48 49 |
|
1577 | 1584 | |
|
1578 | 1585 | Now, typing `my_macro` (without quotes) will re-execute all this code |
|
1579 | 1586 | in one pass. |
|
1580 | 1587 | |
|
1581 | 1588 | You don't need to give the line-numbers in order, and any given line |
|
1582 | 1589 | number can appear multiple times. You can assemble macros with any |
|
1583 | 1590 | lines from your input history in any order. |
|
1584 | 1591 | |
|
1585 | 1592 | The macro is a simple object which holds its value in an attribute, |
|
1586 | 1593 | but IPython's display system checks for macros and executes them as |
|
1587 | 1594 | code instead of printing them when you type their name. |
|
1588 | 1595 | |
|
1589 | 1596 | You can view a macro's contents by explicitly printing it with: |
|
1590 | 1597 | |
|
1591 | 1598 | 'print macro_name'. |
|
1592 | 1599 | |
|
1593 | 1600 | For one-off cases which DON'T contain magic function calls in them you |
|
1594 | 1601 | can obtain similar results by explicitly executing slices from your |
|
1595 | 1602 | input history with: |
|
1596 | 1603 | |
|
1597 | 1604 | In [60]: exec In[44:48]+In[49]""" |
|
1598 | 1605 | |
|
1599 | 1606 | args = parameter_s.split() |
|
1600 | 1607 | name,ranges = args[0], args[1:] |
|
1601 | 1608 | #print 'rng',ranges # dbg |
|
1602 | 1609 | cmds = self.extract_input_slices(ranges) |
|
1603 | 1610 | macro = Macro(cmds) |
|
1604 | 1611 | self.shell.user_ns.update({name:macro}) |
|
1605 | 1612 | print 'Macro `%s` created. To execute, type its name (without quotes).' % name |
|
1606 | 1613 | print 'Macro contents:' |
|
1607 | 1614 | print str(macro).rstrip(), |
|
1608 | 1615 | |
|
1609 | 1616 | def magic_save(self,parameter_s = ''): |
|
1610 | 1617 | """Save a set of lines to a given filename. |
|
1611 | 1618 | |
|
1612 | 1619 | Usage:\\ |
|
1613 | 1620 | %save filename n1:n2 n3:n4 ... n5 .. n6 ... |
|
1614 | 1621 | |
|
1615 | 1622 | This function uses the same syntax as %macro for line extraction, but |
|
1616 | 1623 | instead of creating a macro it saves the resulting string to the |
|
1617 | 1624 | filename you specify. |
|
1618 | 1625 | |
|
1619 | 1626 | It adds a '.py' extension to the file if you don't do so yourself, and |
|
1620 | 1627 | it asks for confirmation before overwriting existing files.""" |
|
1621 | 1628 | |
|
1622 | 1629 | args = parameter_s.split() |
|
1623 | 1630 | fname,ranges = args[0], args[1:] |
|
1624 | 1631 | if not fname.endswith('.py'): |
|
1625 | 1632 | fname += '.py' |
|
1626 | 1633 | if os.path.isfile(fname): |
|
1627 | 1634 | ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname) |
|
1628 | 1635 | if ans.lower() not in ['y','yes']: |
|
1629 | 1636 | print 'Operation cancelled.' |
|
1630 | 1637 | return |
|
1631 | 1638 | cmds = ''.join(self.extract_input_slices(ranges)) |
|
1632 | 1639 | f = file(fname,'w') |
|
1633 | 1640 | f.write(cmds) |
|
1634 | 1641 | f.close() |
|
1635 | 1642 | print 'The following commands were written to file `%s`:' % fname |
|
1636 | 1643 | print cmds |
|
1637 | 1644 | |
|
1638 | 1645 | def magic_ed(self,parameter_s = ''): |
|
1639 | 1646 | """Alias to %edit.""" |
|
1640 | 1647 | return self.magic_edit(parameter_s) |
|
1641 | 1648 | |
|
1642 | 1649 | def magic_edit(self,parameter_s = '',last_call=['','']): |
|
1643 | 1650 | """Bring up an editor and execute the resulting code. |
|
1644 | 1651 | |
|
1645 | 1652 | Usage: |
|
1646 | 1653 | %edit [options] [args] |
|
1647 | 1654 | |
|
1648 | 1655 | %edit runs IPython's editor hook. The default version of this hook is |
|
1649 | 1656 | set to call the __IPYTHON__.rc.editor command. This is read from your |
|
1650 | 1657 | environment variable $EDITOR. If this isn't found, it will default to |
|
1651 | 1658 | vi under Linux/Unix and to notepad under Windows. See the end of this |
|
1652 | 1659 | docstring for how to change the editor hook. |
|
1653 | 1660 | |
|
1654 | 1661 | You can also set the value of this editor via the command line option |
|
1655 | 1662 | '-editor' or in your ipythonrc file. This is useful if you wish to use |
|
1656 | 1663 | specifically for IPython an editor different from your typical default |
|
1657 | 1664 | (and for Windows users who typically don't set environment variables). |
|
1658 | 1665 | |
|
1659 | 1666 | This command allows you to conveniently edit multi-line code right in |
|
1660 | 1667 | your IPython session. |
|
1661 | 1668 | |
|
1662 | 1669 | If called without arguments, %edit opens up an empty editor with a |
|
1663 | 1670 | temporary file and will execute the contents of this file when you |
|
1664 | 1671 | close it (don't forget to save it!). |
|
1665 | 1672 | |
|
1666 | 1673 | Options: |
|
1667 | 1674 | |
|
1668 | 1675 | -p: this will call the editor with the same data as the previous time |
|
1669 | 1676 | it was used, regardless of how long ago (in your current session) it |
|
1670 | 1677 | was. |
|
1671 | 1678 | |
|
1672 | 1679 | -x: do not execute the edited code immediately upon exit. This is |
|
1673 | 1680 | mainly useful if you are editing programs which need to be called with |
|
1674 | 1681 | command line arguments, which you can then do using %run. |
|
1675 | 1682 | |
|
1676 | 1683 | Arguments: |
|
1677 | 1684 | |
|
1678 | 1685 | If arguments are given, the following possibilites exist: |
|
1679 | 1686 | |
|
1680 | 1687 | - The arguments are numbers or pairs of colon-separated numbers (like |
|
1681 | 1688 | 1 4:8 9). These are interpreted as lines of previous input to be |
|
1682 | 1689 | loaded into the editor. The syntax is the same of the %macro command. |
|
1683 | 1690 | |
|
1684 | 1691 | - If the argument doesn't start with a number, it is evaluated as a |
|
1685 | 1692 | variable and its contents loaded into the editor. You can thus edit |
|
1686 | 1693 | any string which contains python code (including the result of |
|
1687 | 1694 | previous edits). |
|
1688 | 1695 | |
|
1689 | 1696 | - If the argument is the name of an object (other than a string), |
|
1690 | 1697 | IPython will try to locate the file where it was defined and open the |
|
1691 | 1698 | editor at the point where it is defined. You can use `%edit function` |
|
1692 | 1699 | to load an editor exactly at the point where 'function' is defined, |
|
1693 | 1700 | edit it and have the file be executed automatically. |
|
1694 | 1701 | |
|
1695 | 1702 | Note: opening at an exact line is only supported under Unix, and some |
|
1696 | 1703 | editors (like kedit and gedit up to Gnome 2.8) do not understand the |
|
1697 | 1704 | '+NUMBER' parameter necessary for this feature. Good editors like |
|
1698 | 1705 | (X)Emacs, vi, jed, pico and joe all do. |
|
1699 | 1706 | |
|
1700 | 1707 | - If the argument is not found as a variable, IPython will look for a |
|
1701 | 1708 | file with that name (adding .py if necessary) and load it into the |
|
1702 | 1709 | editor. It will execute its contents with execfile() when you exit, |
|
1703 | 1710 | loading any code in the file into your interactive namespace. |
|
1704 | 1711 | |
|
1705 | 1712 | After executing your code, %edit will return as output the code you |
|
1706 | 1713 | typed in the editor (except when it was an existing file). This way |
|
1707 | 1714 | you can reload the code in further invocations of %edit as a variable, |
|
1708 | 1715 | via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of |
|
1709 | 1716 | the output. |
|
1710 | 1717 | |
|
1711 | 1718 | Note that %edit is also available through the alias %ed. |
|
1712 | 1719 | |
|
1713 | 1720 | This is an example of creating a simple function inside the editor and |
|
1714 | 1721 | then modifying it. First, start up the editor: |
|
1715 | 1722 | |
|
1716 | 1723 | In [1]: ed\\ |
|
1717 | 1724 | Editing... done. Executing edited code...\\ |
|
1718 | 1725 | Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n' |
|
1719 | 1726 | |
|
1720 | 1727 | We can then call the function foo(): |
|
1721 | 1728 | |
|
1722 | 1729 | In [2]: foo()\\ |
|
1723 | 1730 | foo() was defined in an editing session |
|
1724 | 1731 | |
|
1725 | 1732 | Now we edit foo. IPython automatically loads the editor with the |
|
1726 | 1733 | (temporary) file where foo() was previously defined: |
|
1727 | 1734 | |
|
1728 | 1735 | In [3]: ed foo\\ |
|
1729 | 1736 | Editing... done. Executing edited code... |
|
1730 | 1737 | |
|
1731 | 1738 | And if we call foo() again we get the modified version: |
|
1732 | 1739 | |
|
1733 | 1740 | In [4]: foo()\\ |
|
1734 | 1741 | foo() has now been changed! |
|
1735 | 1742 | |
|
1736 | 1743 | Here is an example of how to edit a code snippet successive |
|
1737 | 1744 | times. First we call the editor: |
|
1738 | 1745 | |
|
1739 | 1746 | In [8]: ed\\ |
|
1740 | 1747 | Editing... done. Executing edited code...\\ |
|
1741 | 1748 | hello\\ |
|
1742 | 1749 | Out[8]: "print 'hello'\\n" |
|
1743 | 1750 | |
|
1744 | 1751 | Now we call it again with the previous output (stored in _): |
|
1745 | 1752 | |
|
1746 | 1753 | In [9]: ed _\\ |
|
1747 | 1754 | Editing... done. Executing edited code...\\ |
|
1748 | 1755 | hello world\\ |
|
1749 | 1756 | Out[9]: "print 'hello world'\\n" |
|
1750 | 1757 | |
|
1751 | 1758 | Now we call it with the output #8 (stored in _8, also as Out[8]): |
|
1752 | 1759 | |
|
1753 | 1760 | In [10]: ed _8\\ |
|
1754 | 1761 | Editing... done. Executing edited code...\\ |
|
1755 | 1762 | hello again\\ |
|
1756 | 1763 | Out[10]: "print 'hello again'\\n" |
|
1757 | 1764 | |
|
1758 | 1765 | |
|
1759 | 1766 | Changing the default editor hook: |
|
1760 | 1767 | |
|
1761 | 1768 | If you wish to write your own editor hook, you can put it in a |
|
1762 | 1769 | configuration file which you load at startup time. The default hook |
|
1763 | 1770 | is defined in the IPython.hooks module, and you can use that as a |
|
1764 | 1771 | starting example for further modifications. That file also has |
|
1765 | 1772 | general instructions on how to set a new hook for use once you've |
|
1766 | 1773 | defined it.""" |
|
1767 | 1774 | |
|
1768 | 1775 | # FIXME: This function has become a convoluted mess. It needs a |
|
1769 | 1776 | # ground-up rewrite with clean, simple logic. |
|
1770 | 1777 | |
|
1771 | 1778 | def make_filename(arg): |
|
1772 | 1779 | "Make a filename from the given args" |
|
1773 | 1780 | try: |
|
1774 | 1781 | filename = get_py_filename(arg) |
|
1775 | 1782 | except IOError: |
|
1776 | 1783 | if args.endswith('.py'): |
|
1777 | 1784 | filename = arg |
|
1778 | 1785 | else: |
|
1779 | 1786 | filename = None |
|
1780 | 1787 | return filename |
|
1781 | 1788 | |
|
1782 | 1789 | # custom exceptions |
|
1783 | 1790 | class DataIsObject(Exception): pass |
|
1784 | 1791 | |
|
1785 | 1792 | opts,args = self.parse_options(parameter_s,'px') |
|
1786 | 1793 | |
|
1787 | 1794 | # Default line number value |
|
1788 | 1795 | lineno = None |
|
1789 | 1796 | if opts.has_key('p'): |
|
1790 | 1797 | args = '_%s' % last_call[0] |
|
1791 | 1798 | if not self.shell.user_ns.has_key(args): |
|
1792 | 1799 | args = last_call[1] |
|
1793 | 1800 | |
|
1794 | 1801 | # use last_call to remember the state of the previous call, but don't |
|
1795 | 1802 | # let it be clobbered by successive '-p' calls. |
|
1796 | 1803 | try: |
|
1797 | 1804 | last_call[0] = self.shell.outputcache.prompt_count |
|
1798 | 1805 | if not opts.has_key('p'): |
|
1799 | 1806 | last_call[1] = parameter_s |
|
1800 | 1807 | except: |
|
1801 | 1808 | pass |
|
1802 | 1809 | |
|
1803 | 1810 | # by default this is done with temp files, except when the given |
|
1804 | 1811 | # arg is a filename |
|
1805 | 1812 | use_temp = 1 |
|
1806 | 1813 | |
|
1807 | 1814 | if re.match(r'\d',args): |
|
1808 | 1815 | # Mode where user specifies ranges of lines, like in %macro. |
|
1809 | 1816 | # This means that you can't edit files whose names begin with |
|
1810 | 1817 | # numbers this way. Tough. |
|
1811 | 1818 | ranges = args.split() |
|
1812 | 1819 | data = ''.join(self.extract_input_slices(ranges)) |
|
1813 | 1820 | elif args.endswith('.py'): |
|
1814 | 1821 | filename = make_filename(args) |
|
1815 | 1822 | data = '' |
|
1816 | 1823 | use_temp = 0 |
|
1817 | 1824 | elif args: |
|
1818 | 1825 | try: |
|
1819 | 1826 | # Load the parameter given as a variable. If not a string, |
|
1820 | 1827 | # process it as an object instead (below) |
|
1821 | 1828 | |
|
1822 | 1829 | #print '*** args',args,'type',type(args) # dbg |
|
1823 | 1830 | data = eval(args,self.shell.user_ns) |
|
1824 | 1831 | if not type(data) in StringTypes: |
|
1825 | 1832 | raise DataIsObject |
|
1826 | 1833 | except (NameError,SyntaxError): |
|
1827 | 1834 | # given argument is not a variable, try as a filename |
|
1828 | 1835 | filename = make_filename(args) |
|
1829 | 1836 | if filename is None: |
|
1830 | 1837 | warn("Argument given (%s) can't be found as a variable " |
|
1831 | 1838 | "or as a filename." % args) |
|
1832 | 1839 | return |
|
1833 | 1840 | data = '' |
|
1834 | 1841 | use_temp = 0 |
|
1835 | 1842 | except DataIsObject: |
|
1836 | 1843 | # For objects, try to edit the file where they are defined |
|
1837 | 1844 | try: |
|
1838 | 1845 | filename = inspect.getabsfile(data) |
|
1839 | 1846 | datafile = 1 |
|
1840 | 1847 | except TypeError: |
|
1841 | 1848 | filename = make_filename(args) |
|
1842 | 1849 | datafile = 1 |
|
1843 | 1850 | warn('Could not find file where `%s` is defined.\n' |
|
1844 | 1851 | 'Opening a file named `%s`' % (args,filename)) |
|
1845 | 1852 | # Now, make sure we can actually read the source (if it was in |
|
1846 | 1853 | # a temp file it's gone by now). |
|
1847 | 1854 | if datafile: |
|
1848 | 1855 | try: |
|
1849 | 1856 | lineno = inspect.getsourcelines(data)[1] |
|
1850 | 1857 | except IOError: |
|
1851 | 1858 | filename = make_filename(args) |
|
1852 | 1859 | if filename is None: |
|
1853 | 1860 | warn('The file `%s` where `%s` was defined cannot ' |
|
1854 | 1861 | 'be read.' % (filename,data)) |
|
1855 | 1862 | return |
|
1856 | 1863 | use_temp = 0 |
|
1857 | 1864 | else: |
|
1858 | 1865 | data = '' |
|
1859 | 1866 | |
|
1860 | 1867 | if use_temp: |
|
1861 | 1868 | filename = tempfile.mktemp('.py') |
|
1862 | 1869 | self.shell.tempfiles.append(filename) |
|
1863 | 1870 | |
|
1864 | 1871 | if data and use_temp: |
|
1865 | 1872 | tmp_file = open(filename,'w') |
|
1866 | 1873 | tmp_file.write(data) |
|
1867 | 1874 | tmp_file.close() |
|
1868 | 1875 | |
|
1869 | 1876 | # do actual editing here |
|
1870 | 1877 | print 'Editing...', |
|
1871 | 1878 | sys.stdout.flush() |
|
1872 | 1879 | self.shell.hooks.editor(filename,lineno) |
|
1873 | 1880 | if opts.has_key('x'): # -x prevents actual execution |
|
1874 | 1881 | |
|
1875 | 1882 | else: |
|
1876 | 1883 | print 'done. Executing edited code...' |
|
1877 | 1884 | try: |
|
1878 | 1885 | self.shell.safe_execfile(filename,self.shell.user_ns) |
|
1879 | 1886 | except IOError,msg: |
|
1880 | 1887 | if msg.filename == filename: |
|
1881 | 1888 | warn('File not found. Did you forget to save?') |
|
1882 | 1889 | return |
|
1883 | 1890 | else: |
|
1884 | 1891 | self.shell.showtraceback() |
|
1885 | 1892 | except: |
|
1886 | 1893 | self.shell.showtraceback() |
|
1887 | 1894 | if use_temp: |
|
1888 | 1895 | contents = open(filename).read() |
|
1889 | 1896 | return contents |
|
1890 | 1897 | |
|
1891 | 1898 | def magic_xmode(self,parameter_s = ''): |
|
1892 | 1899 | """Switch modes for the exception handlers. |
|
1893 | 1900 | |
|
1894 | 1901 | Valid modes: Plain, Context and Verbose. |
|
1895 | 1902 | |
|
1896 | 1903 | If called without arguments, acts as a toggle.""" |
|
1897 | 1904 | |
|
1905 | def xmode_switch_err(name): | |
|
1906 | warn('Error changing %s exception modes.\n%s' % | |
|
1907 | (name,sys.exc_info()[1])) | |
|
1908 | ||
|
1898 | 1909 | new_mode = parameter_s.strip().capitalize() |
|
1899 | 1910 | try: |
|
1900 |
self.InteractiveTB.set_mode(mode |
|
|
1911 | self.InteractiveTB.set_mode(mode=new_mode) | |
|
1901 | 1912 | print 'Exception reporting mode:',self.InteractiveTB.mode |
|
1902 | 1913 | except: |
|
1903 | warn('Error changing exception modes.\n' + str(sys.exc_info()[1])) | |
|
1914 | xmode_switch_err('user') | |
|
1915 | ||
|
1916 | # threaded shells use a special handler in sys.excepthook | |
|
1917 | if self.isthreaded: | |
|
1918 | try: | |
|
1919 | self.shell.sys_excepthook.set_mode(mode=new_mode) | |
|
1920 | except: | |
|
1921 | xmode_switch_err('threaded') | |
|
1904 | 1922 | |
|
1905 | 1923 | def magic_colors(self,parameter_s = ''): |
|
1906 | 1924 | """Switch color scheme for prompts, info system and exception handlers. |
|
1907 | 1925 | |
|
1908 | 1926 | Currently implemented schemes: NoColor, Linux, LightBG. |
|
1909 | 1927 | |
|
1910 | 1928 | Color scheme names are not case-sensitive.""" |
|
1929 | ||
|
1930 | def color_switch_err(name): | |
|
1931 | warn('Error changing %s color schemes.\n%s' % | |
|
1932 | (name,sys.exc_info()[1])) | |
|
1933 | ||
|
1911 | 1934 | |
|
1912 | 1935 | new_scheme = parameter_s.strip() |
|
1913 | 1936 | if not new_scheme: |
|
1914 | 1937 | print 'You must specify a color scheme.' |
|
1915 | 1938 | return |
|
1916 | 1939 | # Under Windows, check for Gary Bishop's readline, which is necessary |
|
1917 | 1940 | # for ANSI coloring |
|
1918 | 1941 | if os.name in ['nt','dos']: |
|
1919 | 1942 | try: |
|
1920 | 1943 | import readline |
|
1921 | 1944 | except ImportError: |
|
1922 | 1945 | has_readline = 0 |
|
1923 | 1946 | else: |
|
1924 | 1947 | try: |
|
1925 | 1948 | readline.GetOutputFile() |
|
1926 | 1949 | except AttributeError: |
|
1927 | 1950 | has_readline = 0 |
|
1928 | 1951 | else: |
|
1929 | 1952 | has_readline = 1 |
|
1930 | 1953 | if not has_readline: |
|
1931 | 1954 | msg = """\ |
|
1932 | 1955 | Proper color support under MS Windows requires Gary Bishop's readline library. |
|
1933 | 1956 | You can find it at: |
|
1934 | 1957 | http://sourceforge.net/projects/uncpythontools |
|
1935 | 1958 | Gary's readline needs the ctypes module, from: |
|
1936 | 1959 | http://starship.python.net/crew/theller/ctypes |
|
1937 | 1960 | |
|
1938 | 1961 | Defaulting color scheme to 'NoColor'""" |
|
1939 | 1962 | new_scheme = 'NoColor' |
|
1940 | 1963 | warn(msg) |
|
1941 | 1964 | |
|
1942 | 1965 | # Set prompt colors |
|
1943 | 1966 | try: |
|
1944 | 1967 | self.shell.outputcache.set_colors(new_scheme) |
|
1945 | 1968 | except: |
|
1946 | warn('Error changing prompt color schemes.\n' | |
|
1947 | + str(sys.exc_info()[1])) | |
|
1969 | color_switch_err('prompt') | |
|
1948 | 1970 | else: |
|
1949 | 1971 | self.shell.rc.colors = \ |
|
1950 | 1972 | self.shell.outputcache.color_table.active_scheme_name |
|
1951 | 1973 | # Set exception colors |
|
1952 | 1974 | try: |
|
1953 | 1975 | self.shell.InteractiveTB.set_colors(scheme = new_scheme) |
|
1954 | 1976 | self.shell.SyntaxTB.set_colors(scheme = new_scheme) |
|
1955 | 1977 | except: |
|
1956 | warn('Error changing exception color schemes.\n' | |
|
1957 | + str(sys.exc_info()[1])) | |
|
1978 | color_switch_err('exception') | |
|
1979 | ||
|
1980 | # threaded shells use a verbose traceback in sys.excepthook | |
|
1981 | if self.isthreaded: | |
|
1982 | try: | |
|
1983 | self.shell.sys_excepthook.set_colors(scheme=new_scheme) | |
|
1984 | except: | |
|
1985 | color_switch_err('system exception handler') | |
|
1986 | ||
|
1958 | 1987 | # Set info (for 'object?') colors |
|
1959 | 1988 | if self.shell.rc.color_info: |
|
1960 | 1989 | try: |
|
1961 | 1990 | self.shell.inspector.set_active_scheme(new_scheme) |
|
1962 | 1991 | except: |
|
1963 |
|
|
|
1964 | + str(sys.exc_info()[1])) | |
|
1992 | color_switch_err('object inspector') | |
|
1965 | 1993 | else: |
|
1966 | 1994 | self.shell.inspector.set_active_scheme('NoColor') |
|
1967 | 1995 | |
|
1968 | 1996 | def magic_color_info(self,parameter_s = ''): |
|
1969 | 1997 | """Toggle color_info. |
|
1970 | 1998 | |
|
1971 | 1999 | The color_info configuration parameter controls whether colors are |
|
1972 | 2000 | used for displaying object details (by things like %psource, %pfile or |
|
1973 | 2001 | the '?' system). This function toggles this value with each call. |
|
1974 | 2002 | |
|
1975 | 2003 | Note that unless you have a fairly recent pager (less works better |
|
1976 | 2004 | than more) in your system, using colored object information displays |
|
1977 | 2005 | will not work properly. Test it and see.""" |
|
1978 | 2006 | |
|
1979 | 2007 | self.shell.rc.color_info = 1 - self.shell.rc.color_info |
|
1980 | 2008 | self.magic_colors(self.shell.rc.colors) |
|
1981 | 2009 | print 'Object introspection functions have now coloring:', |
|
1982 | 2010 | print ['OFF','ON'][self.shell.rc.color_info] |
|
1983 | 2011 | |
|
1984 | 2012 | def magic_Pprint(self, parameter_s=''): |
|
1985 | 2013 | """Toggle pretty printing on/off.""" |
|
1986 | 2014 | |
|
1987 | 2015 | self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint |
|
1988 | 2016 | print 'Pretty printing has been turned', \ |
|
1989 | 2017 | ['OFF','ON'][self.shell.outputcache.Pprint] |
|
1990 | 2018 | |
|
1991 | 2019 | def magic_exit(self, parameter_s=''): |
|
1992 | 2020 | """Exit IPython, confirming if configured to do so. |
|
1993 | 2021 | |
|
1994 | 2022 | You can configure whether IPython asks for confirmation upon exit by |
|
1995 | 2023 | setting the confirm_exit flag in the ipythonrc file.""" |
|
1996 | 2024 | |
|
1997 | 2025 | self.shell.exit() |
|
1998 | 2026 | |
|
1999 | 2027 | def magic_quit(self, parameter_s=''): |
|
2000 | 2028 | """Exit IPython, confirming if configured to do so (like %exit)""" |
|
2001 | 2029 | |
|
2002 | 2030 | self.shell.exit() |
|
2003 | 2031 | |
|
2004 | 2032 | def magic_Exit(self, parameter_s=''): |
|
2005 | 2033 | """Exit IPython without confirmation.""" |
|
2006 | 2034 | |
|
2007 | 2035 | self.shell.exit_now = True |
|
2008 | 2036 | |
|
2009 | 2037 | def magic_Quit(self, parameter_s=''): |
|
2010 | 2038 | """Exit IPython without confirmation (like %Exit).""" |
|
2011 | 2039 | |
|
2012 | 2040 | self.shell.exit_now = True |
|
2013 | 2041 | |
|
2014 | 2042 | #...................................................................... |
|
2015 | 2043 | # Functions to implement unix shell-type things |
|
2016 | 2044 | |
|
2017 | 2045 | def magic_alias(self, parameter_s = ''): |
|
2018 | 2046 | """Define an alias for a system command. |
|
2019 | 2047 | |
|
2020 | 2048 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
|
2021 | 2049 | |
|
2022 | 2050 | Then, typing 'alias_name params' will execute the system command 'cmd |
|
2023 | 2051 | params' (from your underlying operating system). |
|
2024 | 2052 | |
|
2025 | 2053 | Aliases have lower precedence than magic functions and Python normal |
|
2026 | 2054 | variables, so if 'foo' is both a Python variable and an alias, the |
|
2027 | 2055 | alias can not be executed until 'del foo' removes the Python variable. |
|
2028 | 2056 | |
|
2029 | 2057 | You can use the %l specifier in an alias definition to represent the |
|
2030 | 2058 | whole line when the alias is called. For example: |
|
2031 | 2059 | |
|
2032 | 2060 | In [2]: alias all echo "Input in brackets: <%l>"\\ |
|
2033 | 2061 | In [3]: all hello world\\ |
|
2034 | 2062 | Input in brackets: <hello world> |
|
2035 | 2063 | |
|
2036 | 2064 | You can also define aliases with parameters using %s specifiers (one |
|
2037 | 2065 | per parameter): |
|
2038 | 2066 | |
|
2039 | 2067 | In [1]: alias parts echo first %s second %s\\ |
|
2040 | 2068 | In [2]: %parts A B\\ |
|
2041 | 2069 | first A second B\\ |
|
2042 | 2070 | In [3]: %parts A\\ |
|
2043 | 2071 | Incorrect number of arguments: 2 expected.\\ |
|
2044 | 2072 | parts is an alias to: 'echo first %s second %s' |
|
2045 | 2073 | |
|
2046 | 2074 | Note that %l and %s are mutually exclusive. You can only use one or |
|
2047 | 2075 | the other in your aliases. |
|
2048 | 2076 | |
|
2049 | 2077 | Aliases expand Python variables just like system calls using ! or !! |
|
2050 | 2078 | do: all expressions prefixed with '$' get expanded. For details of |
|
2051 | 2079 | the semantic rules, see PEP-215: |
|
2052 | 2080 | http://www.python.org/peps/pep-0215.html. This is the library used by |
|
2053 | 2081 | IPython for variable expansion. If you want to access a true shell |
|
2054 | 2082 | variable, an extra $ is necessary to prevent its expansion by IPython: |
|
2055 | 2083 | |
|
2056 | 2084 | In [6]: alias show echo\\ |
|
2057 | 2085 | In [7]: PATH='A Python string'\\ |
|
2058 | 2086 | In [8]: show $PATH\\ |
|
2059 | 2087 | A Python string\\ |
|
2060 | 2088 | In [9]: show $$PATH\\ |
|
2061 | 2089 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
2062 | 2090 | |
|
2063 | 2091 | You can use the alias facility to acess all of $PATH. See the %rehash |
|
2064 | 2092 | and %rehashx functions, which automatically create aliases for the |
|
2065 | 2093 | contents of your $PATH. |
|
2066 | 2094 | |
|
2067 | 2095 | If called with no parameters, %alias prints the current alias table.""" |
|
2068 | 2096 | |
|
2069 | 2097 | par = parameter_s.strip() |
|
2070 | 2098 | if not par: |
|
2071 | 2099 | if self.shell.rc.automagic: |
|
2072 | 2100 | prechar = '' |
|
2073 | 2101 | else: |
|
2074 | 2102 | prechar = self.shell.ESC_MAGIC |
|
2075 | 2103 | print 'Alias\t\tSystem Command\n'+'-'*30 |
|
2076 | 2104 | atab = self.shell.alias_table |
|
2077 | 2105 | aliases = atab.keys() |
|
2078 | 2106 | aliases.sort() |
|
2079 | 2107 | for alias in aliases: |
|
2080 | 2108 | print prechar+alias+'\t\t'+atab[alias][1] |
|
2081 | 2109 | print '-'*30+'\nTotal number of aliases:',len(aliases) |
|
2082 | 2110 | return |
|
2083 | 2111 | try: |
|
2084 | 2112 | alias,cmd = par.split(None,1) |
|
2085 | 2113 | except: |
|
2086 | 2114 | print OInspect.getdoc(self.magic_alias) |
|
2087 | 2115 | else: |
|
2088 | 2116 | nargs = cmd.count('%s') |
|
2089 | 2117 | if nargs>0 and cmd.find('%l')>=0: |
|
2090 | 2118 | error('The %s and %l specifiers are mutually exclusive ' |
|
2091 | 2119 | 'in alias definitions.') |
|
2092 | 2120 | else: # all looks OK |
|
2093 | 2121 | self.shell.alias_table[alias] = (nargs,cmd) |
|
2094 | 2122 | self.shell.alias_table_validate(verbose=1) |
|
2095 | 2123 | # end magic_alias |
|
2096 | 2124 | |
|
2097 | 2125 | def magic_unalias(self, parameter_s = ''): |
|
2098 | 2126 | """Remove an alias""" |
|
2099 | 2127 | |
|
2100 | 2128 | aname = parameter_s.strip() |
|
2101 | 2129 | if aname in self.shell.alias_table: |
|
2102 | 2130 | del self.shell.alias_table[aname] |
|
2103 | 2131 | |
|
2104 | 2132 | def magic_rehash(self, parameter_s = ''): |
|
2105 | 2133 | """Update the alias table with all entries in $PATH. |
|
2106 | 2134 | |
|
2107 | 2135 | This version does no checks on execute permissions or whether the |
|
2108 | 2136 | contents of $PATH are truly files (instead of directories or something |
|
2109 | 2137 | else). For such a safer (but slower) version, use %rehashx.""" |
|
2110 | 2138 | |
|
2111 | 2139 | # This function (and rehashx) manipulate the alias_table directly |
|
2112 | 2140 | # rather than calling magic_alias, for speed reasons. A rehash on a |
|
2113 | 2141 | # typical Linux box involves several thousand entries, so efficiency |
|
2114 | 2142 | # here is a top concern. |
|
2115 | 2143 | |
|
2116 | 2144 | path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep)) |
|
2117 | 2145 | alias_table = self.shell.alias_table |
|
2118 | 2146 | for pdir in path: |
|
2119 | 2147 | for ff in os.listdir(pdir): |
|
2120 | 2148 | # each entry in the alias table must be (N,name), where |
|
2121 | 2149 | # N is the number of positional arguments of the alias. |
|
2122 | 2150 | alias_table[ff] = (0,ff) |
|
2123 | 2151 | # Make sure the alias table doesn't contain keywords or builtins |
|
2124 | 2152 | self.shell.alias_table_validate() |
|
2125 | 2153 | # Call again init_auto_alias() so we get 'rm -i' and other modified |
|
2126 | 2154 | # aliases since %rehash will probably clobber them |
|
2127 | 2155 | self.shell.init_auto_alias() |
|
2128 | 2156 | |
|
2129 | 2157 | def magic_rehashx(self, parameter_s = ''): |
|
2130 | 2158 | """Update the alias table with all executable files in $PATH. |
|
2131 | 2159 | |
|
2132 | 2160 | This version explicitly checks that every entry in $PATH is a file |
|
2133 | 2161 | with execute access (os.X_OK), so it is much slower than %rehash. |
|
2134 | 2162 | |
|
2135 | 2163 | Under Windows, it checks executability as a match agains a |
|
2136 | 2164 | '|'-separated string of extensions, stored in the IPython config |
|
2137 | 2165 | variable win_exec_ext. This defaults to 'exe|com|bat'. """ |
|
2138 | 2166 | |
|
2139 | 2167 | path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep)) |
|
2140 | 2168 | alias_table = self.shell.alias_table |
|
2141 | 2169 | |
|
2142 | 2170 | if os.name == 'posix': |
|
2143 | 2171 | isexec = lambda fname:os.path.isfile(fname) and \ |
|
2144 | 2172 | os.access(fname,os.X_OK) |
|
2145 | 2173 | else: |
|
2146 | 2174 | |
|
2147 | 2175 | try: |
|
2148 | 2176 | winext = os.environ['pathext'].replace(';','|').replace('.','') |
|
2149 | 2177 | except KeyError: |
|
2150 | 2178 | winext = 'exe|com|bat' |
|
2151 | 2179 | |
|
2152 | 2180 | execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE) |
|
2153 | 2181 | isexec = lambda fname:os.path.isfile(fname) and execre.match(fname) |
|
2154 | 2182 | savedir = os.getcwd() |
|
2155 | 2183 | try: |
|
2156 | 2184 | # write the whole loop for posix/Windows so we don't have an if in |
|
2157 | 2185 | # the innermost part |
|
2158 | 2186 | if os.name == 'posix': |
|
2159 | 2187 | for pdir in path: |
|
2160 | 2188 | os.chdir(pdir) |
|
2161 | 2189 | for ff in os.listdir(pdir): |
|
2162 | 2190 | if isexec(ff): |
|
2163 | 2191 | # each entry in the alias table must be (N,name), |
|
2164 | 2192 | # where N is the number of positional arguments of the |
|
2165 | 2193 | # alias. |
|
2166 | 2194 | alias_table[ff] = (0,ff) |
|
2167 | 2195 | else: |
|
2168 | 2196 | for pdir in path: |
|
2169 | 2197 | os.chdir(pdir) |
|
2170 | 2198 | for ff in os.listdir(pdir): |
|
2171 | 2199 | if isexec(ff): |
|
2172 | 2200 | alias_table[execre.sub(r'\1',ff)] = (0,ff) |
|
2173 | 2201 | # Make sure the alias table doesn't contain keywords or builtins |
|
2174 | 2202 | self.shell.alias_table_validate() |
|
2175 | 2203 | # Call again init_auto_alias() so we get 'rm -i' and other |
|
2176 | 2204 | # modified aliases since %rehashx will probably clobber them |
|
2177 | 2205 | self.shell.init_auto_alias() |
|
2178 | 2206 | finally: |
|
2179 | 2207 | os.chdir(savedir) |
|
2180 | 2208 | |
|
2181 | 2209 | def magic_pwd(self, parameter_s = ''): |
|
2182 | 2210 | """Return the current working directory path.""" |
|
2183 | 2211 | return os.getcwd() |
|
2184 | 2212 | |
|
2185 | 2213 | def magic_cd(self, parameter_s=''): |
|
2186 | 2214 | """Change the current working directory. |
|
2187 | 2215 | |
|
2188 | 2216 | This command automatically maintains an internal list of directories |
|
2189 | 2217 | you visit during your IPython session, in the variable _dh. The |
|
2190 | 2218 | command %dhist shows this history nicely formatted. |
|
2191 | 2219 | |
|
2192 | 2220 | Usage: |
|
2193 | 2221 | |
|
2194 | 2222 | cd 'dir': changes to directory 'dir'. |
|
2195 | 2223 | |
|
2196 | 2224 | cd -: changes to the last visited directory. |
|
2197 | 2225 | |
|
2198 | 2226 | cd -<n>: changes to the n-th directory in the directory history. |
|
2199 | 2227 | |
|
2200 | 2228 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark |
|
2201 | 2229 | (note: cd <bookmark_name> is enough if there is no |
|
2202 | 2230 | directory <bookmark_name>, but a bookmark with the name exists.) |
|
2203 | 2231 | |
|
2204 | 2232 | Options: |
|
2205 | 2233 | |
|
2206 | 2234 | -q: quiet. Do not print the working directory after the cd command is |
|
2207 | 2235 | executed. By default IPython's cd command does print this directory, |
|
2208 | 2236 | since the default prompts do not display path information. |
|
2209 | 2237 | |
|
2210 | 2238 | Note that !cd doesn't work for this purpose because the shell where |
|
2211 | 2239 | !command runs is immediately discarded after executing 'command'.""" |
|
2212 | 2240 | |
|
2213 | 2241 | parameter_s = parameter_s.strip() |
|
2214 | 2242 | bkms = self.shell.persist.get("bookmarks",{}) |
|
2215 | 2243 | |
|
2216 | 2244 | numcd = re.match(r'(-)(\d+)$',parameter_s) |
|
2217 | 2245 | # jump in directory history by number |
|
2218 | 2246 | if numcd: |
|
2219 | 2247 | nn = int(numcd.group(2)) |
|
2220 | 2248 | try: |
|
2221 | 2249 | ps = self.shell.user_ns['_dh'][nn] |
|
2222 | 2250 | except IndexError: |
|
2223 | 2251 | print 'The requested directory does not exist in history.' |
|
2224 | 2252 | return |
|
2225 | 2253 | else: |
|
2226 | 2254 | opts = {} |
|
2227 | 2255 | else: |
|
2228 | 2256 | opts,ps = self.parse_options(parameter_s,'qb',mode='string') |
|
2229 | 2257 | # jump to previous |
|
2230 | 2258 | if ps == '-': |
|
2231 | 2259 | try: |
|
2232 | 2260 | ps = self.shell.user_ns['_dh'][-2] |
|
2233 | 2261 | except IndexError: |
|
2234 | 2262 | print 'No previous directory to change to.' |
|
2235 | 2263 | return |
|
2236 | 2264 | # jump to bookmark |
|
2237 | 2265 | elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)): |
|
2238 | 2266 | if bkms.has_key(ps): |
|
2239 | 2267 | target = bkms[ps] |
|
2240 | 2268 | print '(bookmark:%s) -> %s' % (ps,target) |
|
2241 | 2269 | ps = target |
|
2242 | 2270 | else: |
|
2243 | 2271 | if bkms: |
|
2244 | 2272 | error("Bookmark '%s' not found. " |
|
2245 | 2273 | "Use '%bookmark -l' to see your bookmarks." % ps) |
|
2246 | 2274 | else: |
|
2247 | 2275 | print "Bookmarks not set - use %bookmark <bookmarkname>" |
|
2248 | 2276 | return |
|
2249 | 2277 | |
|
2250 | 2278 | # at this point ps should point to the target dir |
|
2251 | 2279 | if ps: |
|
2252 | 2280 | try: |
|
2253 | 2281 | os.chdir(os.path.expanduser(ps)) |
|
2254 | 2282 | except OSError: |
|
2255 | 2283 | print sys.exc_info()[1] |
|
2256 | 2284 | else: |
|
2257 | 2285 | self.shell.user_ns['_dh'].append(os.getcwd()) |
|
2258 | 2286 | else: |
|
2259 | 2287 | os.chdir(self.home_dir) |
|
2260 | 2288 | self.shell.user_ns['_dh'].append(os.getcwd()) |
|
2261 | 2289 | if not 'q' in opts: |
|
2262 | 2290 | print self.shell.user_ns['_dh'][-1] |
|
2263 | 2291 | |
|
2264 | 2292 | def magic_dhist(self, parameter_s=''): |
|
2265 | 2293 | """Print your history of visited directories. |
|
2266 | 2294 | |
|
2267 | 2295 | %dhist -> print full history\\ |
|
2268 | 2296 | %dhist n -> print last n entries only\\ |
|
2269 | 2297 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\ |
|
2270 | 2298 | |
|
2271 | 2299 | This history is automatically maintained by the %cd command, and |
|
2272 | 2300 | always available as the global list variable _dh. You can use %cd -<n> |
|
2273 | 2301 | to go to directory number <n>.""" |
|
2274 | 2302 | |
|
2275 | 2303 | dh = self.shell.user_ns['_dh'] |
|
2276 | 2304 | if parameter_s: |
|
2277 | 2305 | try: |
|
2278 | 2306 | args = map(int,parameter_s.split()) |
|
2279 | 2307 | except: |
|
2280 | 2308 | self.arg_err(Magic.magic_dhist) |
|
2281 | 2309 | return |
|
2282 | 2310 | if len(args) == 1: |
|
2283 | 2311 | ini,fin = max(len(dh)-(args[0]),0),len(dh) |
|
2284 | 2312 | elif len(args) == 2: |
|
2285 | 2313 | ini,fin = args |
|
2286 | 2314 | else: |
|
2287 | 2315 | self.arg_err(Magic.magic_dhist) |
|
2288 | 2316 | return |
|
2289 | 2317 | else: |
|
2290 | 2318 | ini,fin = 0,len(dh) |
|
2291 | 2319 | nlprint(dh, |
|
2292 | 2320 | header = 'Directory history (kept in _dh)', |
|
2293 | 2321 | start=ini,stop=fin) |
|
2294 | 2322 | |
|
2295 | 2323 | def magic_env(self, parameter_s=''): |
|
2296 | 2324 | """List environment variables.""" |
|
2297 | 2325 | |
|
2298 | 2326 | # environ is an instance of UserDict |
|
2299 | 2327 | return os.environ.data |
|
2300 | 2328 | |
|
2301 | 2329 | def magic_pushd(self, parameter_s=''): |
|
2302 | 2330 | """Place the current dir on stack and change directory. |
|
2303 | 2331 | |
|
2304 | 2332 | Usage:\\ |
|
2305 | 2333 | %pushd ['dirname'] |
|
2306 | 2334 | |
|
2307 | 2335 | %pushd with no arguments does a %pushd to your home directory. |
|
2308 | 2336 | """ |
|
2309 | 2337 | if parameter_s == '': parameter_s = '~' |
|
2310 | 2338 | if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \ |
|
2311 | 2339 | os.path.expanduser(self.dir_stack[0]): |
|
2312 | 2340 | try: |
|
2313 | 2341 | self.magic_cd(parameter_s) |
|
2314 | 2342 | self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~')) |
|
2315 | 2343 | self.magic_dirs() |
|
2316 | 2344 | except: |
|
2317 | 2345 | print 'Invalid directory' |
|
2318 | 2346 | else: |
|
2319 | 2347 | print 'You are already there!' |
|
2320 | 2348 | |
|
2321 | 2349 | def magic_popd(self, parameter_s=''): |
|
2322 | 2350 | """Change to directory popped off the top of the stack. |
|
2323 | 2351 | """ |
|
2324 | 2352 | if len (self.dir_stack) > 1: |
|
2325 | 2353 | self.dir_stack.pop(0) |
|
2326 | 2354 | self.magic_cd(self.dir_stack[0]) |
|
2327 | 2355 | print self.dir_stack[0] |
|
2328 | 2356 | else: |
|
2329 | 2357 | print "You can't remove the starting directory from the stack:",\ |
|
2330 | 2358 | self.dir_stack |
|
2331 | 2359 | |
|
2332 | 2360 | def magic_dirs(self, parameter_s=''): |
|
2333 | 2361 | """Return the current directory stack.""" |
|
2334 | 2362 | |
|
2335 | 2363 | return self.dir_stack[:] |
|
2336 | 2364 | |
|
2337 | 2365 | def magic_sc(self, parameter_s=''): |
|
2338 | 2366 | """Shell capture - execute a shell command and capture its output. |
|
2339 | 2367 | |
|
2340 | 2368 | %sc [options] varname=command |
|
2341 | 2369 | |
|
2342 | 2370 | IPython will run the given command using commands.getoutput(), and |
|
2343 | 2371 | will then update the user's interactive namespace with a variable |
|
2344 | 2372 | called varname, containing the value of the call. Your command can |
|
2345 | 2373 | contain shell wildcards, pipes, etc. |
|
2346 | 2374 | |
|
2347 | 2375 | The '=' sign in the syntax is mandatory, and the variable name you |
|
2348 | 2376 | supply must follow Python's standard conventions for valid names. |
|
2349 | 2377 | |
|
2350 | 2378 | Options: |
|
2351 | 2379 | |
|
2352 | 2380 | -l: list output. Split the output on newlines into a list before |
|
2353 | 2381 | assigning it to the given variable. By default the output is stored |
|
2354 | 2382 | as a single string. |
|
2355 | 2383 | |
|
2356 | 2384 | -v: verbose. Print the contents of the variable. |
|
2357 | 2385 | |
|
2358 | 2386 | In most cases you should not need to split as a list, because the |
|
2359 | 2387 | returned value is a special type of string which can automatically |
|
2360 | 2388 | provide its contents either as a list (split on newlines) or as a |
|
2361 | 2389 | space-separated string. These are convenient, respectively, either |
|
2362 | 2390 | for sequential processing or to be passed to a shell command. |
|
2363 | 2391 | |
|
2364 | 2392 | For example: |
|
2365 | 2393 | |
|
2366 | 2394 | # Capture into variable a |
|
2367 | 2395 | In [9]: sc a=ls *py |
|
2368 | 2396 | |
|
2369 | 2397 | # a is a string with embedded newlines |
|
2370 | 2398 | In [10]: a |
|
2371 | 2399 | Out[10]: 'setup.py\nwin32_manual_post_install.py' |
|
2372 | 2400 | |
|
2373 | 2401 | # which can be seen as a list: |
|
2374 | 2402 | In [11]: a.l |
|
2375 | 2403 | Out[11]: ['setup.py', 'win32_manual_post_install.py'] |
|
2376 | 2404 | |
|
2377 | 2405 | # or as a whitespace-separated string: |
|
2378 | 2406 | In [12]: a.s |
|
2379 | 2407 | Out[12]: 'setup.py win32_manual_post_install.py' |
|
2380 | 2408 | |
|
2381 | 2409 | # a.s is useful to pass as a single command line: |
|
2382 | 2410 | In [13]: !wc -l $a.s |
|
2383 | 2411 | 146 setup.py |
|
2384 | 2412 | 130 win32_manual_post_install.py |
|
2385 | 2413 | 276 total |
|
2386 | 2414 | |
|
2387 | 2415 | # while the list form is useful to loop over: |
|
2388 | 2416 | In [14]: for f in a.l: |
|
2389 | 2417 | ....: !wc -l $f |
|
2390 | 2418 | ....: |
|
2391 | 2419 | 146 setup.py |
|
2392 | 2420 | 130 win32_manual_post_install.py |
|
2393 | 2421 | |
|
2394 | 2422 | Similiarly, the lists returned by the -l option are also special, in |
|
2395 | 2423 | the sense that you can equally invoke the .s attribute on them to |
|
2396 | 2424 | automatically get a whitespace-separated string from their contents: |
|
2397 | 2425 | |
|
2398 | 2426 | In [1]: sc -l b=ls *py |
|
2399 | 2427 | |
|
2400 | 2428 | In [2]: b |
|
2401 | 2429 | Out[2]: ['setup.py', 'win32_manual_post_install.py'] |
|
2402 | 2430 | |
|
2403 | 2431 | In [3]: b.s |
|
2404 | 2432 | Out[3]: 'setup.py win32_manual_post_install.py' |
|
2405 | 2433 | |
|
2406 | 2434 | In summary, both the lists and strings used for ouptut capture have |
|
2407 | 2435 | the following special attributes: |
|
2408 | 2436 | |
|
2409 | 2437 | .l (or .list) : value as list. |
|
2410 | 2438 | .n (or .nlstr): value as newline-separated string. |
|
2411 | 2439 | .s (or .spstr): value as space-separated string. |
|
2412 | 2440 | """ |
|
2413 | 2441 | |
|
2414 | 2442 | opts,args = self.parse_options(parameter_s,'lv') |
|
2415 | 2443 | # Try to get a variable name and command to run |
|
2416 | 2444 | try: |
|
2417 | 2445 | # the variable name must be obtained from the parse_options |
|
2418 | 2446 | # output, which uses shlex.split to strip options out. |
|
2419 | 2447 | var,_ = args.split('=',1) |
|
2420 | 2448 | var = var.strip() |
|
2421 | 2449 | # But the the command has to be extracted from the original input |
|
2422 | 2450 | # parameter_s, not on what parse_options returns, to avoid the |
|
2423 | 2451 | # quote stripping which shlex.split performs on it. |
|
2424 | 2452 | _,cmd = parameter_s.split('=',1) |
|
2425 | 2453 | except ValueError: |
|
2426 | 2454 | var,cmd = '','' |
|
2427 | 2455 | if not var: |
|
2428 | 2456 | error('you must specify a variable to assign the command to.') |
|
2429 | 2457 | return |
|
2430 | 2458 | # If all looks ok, proceed |
|
2431 | 2459 | out,err = self.shell.getoutputerror(cmd) |
|
2432 | 2460 | if err: |
|
2433 | 2461 | print >> Term.cerr,err |
|
2434 | 2462 | if opts.has_key('l'): |
|
2435 | 2463 | out = SList(out.split('\n')) |
|
2436 | 2464 | else: |
|
2437 | 2465 | out = LSString(out) |
|
2438 | 2466 | if opts.has_key('v'): |
|
2439 | 2467 | print '%s ==\n%s' % (var,pformat(out)) |
|
2440 | 2468 | self.shell.user_ns.update({var:out}) |
|
2441 | 2469 | |
|
2442 | 2470 | def magic_sx(self, parameter_s=''): |
|
2443 | 2471 | """Shell execute - run a shell command and capture its output. |
|
2444 | 2472 | |
|
2445 | 2473 | %sx command |
|
2446 | 2474 | |
|
2447 | 2475 | IPython will run the given command using commands.getoutput(), and |
|
2448 | 2476 | return the result formatted as a list (split on '\\n'). Since the |
|
2449 | 2477 | output is _returned_, it will be stored in ipython's regular output |
|
2450 | 2478 | cache Out[N] and in the '_N' automatic variables. |
|
2451 | 2479 | |
|
2452 | 2480 | Notes: |
|
2453 | 2481 | |
|
2454 | 2482 | 1) If an input line begins with '!!', then %sx is automatically |
|
2455 | 2483 | invoked. That is, while: |
|
2456 | 2484 | !ls |
|
2457 | 2485 | causes ipython to simply issue system('ls'), typing |
|
2458 | 2486 | !!ls |
|
2459 | 2487 | is a shorthand equivalent to: |
|
2460 | 2488 | %sx ls |
|
2461 | 2489 | |
|
2462 | 2490 | 2) %sx differs from %sc in that %sx automatically splits into a list, |
|
2463 | 2491 | like '%sc -l'. The reason for this is to make it as easy as possible |
|
2464 | 2492 | to process line-oriented shell output via further python commands. |
|
2465 | 2493 | %sc is meant to provide much finer control, but requires more |
|
2466 | 2494 | typing. |
|
2467 | 2495 | |
|
2468 | 2496 | 3) Just like %sc -l, this is a list with special attributes: |
|
2469 | 2497 | |
|
2470 | 2498 | .l (or .list) : value as list. |
|
2471 | 2499 | .n (or .nlstr): value as newline-separated string. |
|
2472 | 2500 | .s (or .spstr): value as whitespace-separated string. |
|
2473 | 2501 | |
|
2474 | 2502 | This is very useful when trying to use such lists as arguments to |
|
2475 | 2503 | system commands.""" |
|
2476 | 2504 | |
|
2477 | 2505 | if parameter_s: |
|
2478 | 2506 | out,err = self.shell.getoutputerror(parameter_s) |
|
2479 | 2507 | if err: |
|
2480 | 2508 | print >> Term.cerr,err |
|
2481 | 2509 | return SList(out.split('\n')) |
|
2482 | 2510 | |
|
2483 | 2511 | def magic_bg(self, parameter_s=''): |
|
2484 | 2512 | """Run a job in the background, in a separate thread. |
|
2485 | 2513 | |
|
2486 | 2514 | For example, |
|
2487 | 2515 | |
|
2488 | 2516 | %bg myfunc(x,y,z=1) |
|
2489 | 2517 | |
|
2490 | 2518 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the |
|
2491 | 2519 | execution starts, a message will be printed indicating the job |
|
2492 | 2520 | number. If your job number is 5, you can use |
|
2493 | 2521 | |
|
2494 | 2522 | myvar = jobs.result(5) or myvar = jobs[5].result |
|
2495 | 2523 | |
|
2496 | 2524 | to assign this result to variable 'myvar'. |
|
2497 | 2525 | |
|
2498 | 2526 | IPython has a job manager, accessible via the 'jobs' object. You can |
|
2499 | 2527 | type jobs? to get more information about it, and use jobs.<TAB> to see |
|
2500 | 2528 | its attributes. All attributes not starting with an underscore are |
|
2501 | 2529 | meant for public use. |
|
2502 | 2530 | |
|
2503 | 2531 | In particular, look at the jobs.new() method, which is used to create |
|
2504 | 2532 | new jobs. This magic %bg function is just a convenience wrapper |
|
2505 | 2533 | around jobs.new(), for expression-based jobs. If you want to create a |
|
2506 | 2534 | new job with an explicit function object and arguments, you must call |
|
2507 | 2535 | jobs.new() directly. |
|
2508 | 2536 | |
|
2509 | 2537 | The jobs.new docstring also describes in detail several important |
|
2510 | 2538 | caveats associated with a thread-based model for background job |
|
2511 | 2539 | execution. Type jobs.new? for details. |
|
2512 | 2540 | |
|
2513 | 2541 | You can check the status of all jobs with jobs.status(). |
|
2514 | 2542 | |
|
2515 | 2543 | The jobs variable is set by IPython into the Python builtin namespace. |
|
2516 | 2544 | If you ever declare a variable named 'jobs', you will shadow this |
|
2517 | 2545 | name. You can either delete your global jobs variable to regain |
|
2518 | 2546 | access to the job manager, or make a new name and assign it manually |
|
2519 | 2547 | to the manager (stored in IPython's namespace). For example, to |
|
2520 | 2548 | assign the job manager to the Jobs name, use: |
|
2521 | 2549 | |
|
2522 | 2550 | Jobs = __builtins__.jobs""" |
|
2523 | 2551 | |
|
2524 | 2552 | self.shell.jobs.new(parameter_s,self.shell.user_ns) |
|
2525 | 2553 | |
|
2526 | 2554 | def magic_bookmark(self, parameter_s=''): |
|
2527 | 2555 | """Manage IPython's bookmark system. |
|
2528 | 2556 | |
|
2529 | 2557 | %bookmark <name> - set bookmark to current dir |
|
2530 | 2558 | %bookmark <name> <dir> - set bookmark to <dir> |
|
2531 | 2559 | %bookmark -l - list all bookmarks |
|
2532 | 2560 | %bookmark -d <name> - remove bookmark |
|
2533 | 2561 | %bookmark -r - remove all bookmarks |
|
2534 | 2562 | |
|
2535 | 2563 | You can later on access a bookmarked folder with: |
|
2536 | 2564 | %cd -b <name> |
|
2537 | 2565 | or simply '%cd <name>' if there is no directory called <name> AND |
|
2538 | 2566 | there is such a bookmark defined. |
|
2539 | 2567 | |
|
2540 | 2568 | Your bookmarks persist through IPython sessions, but they are |
|
2541 | 2569 | associated with each profile.""" |
|
2542 | 2570 | |
|
2543 | 2571 | opts,args = self.parse_options(parameter_s,'drl',mode='list') |
|
2544 | 2572 | if len(args) > 2: |
|
2545 | 2573 | error('You can only give at most two arguments') |
|
2546 | 2574 | return |
|
2547 | 2575 | |
|
2548 | 2576 | bkms = self.shell.persist.get('bookmarks',{}) |
|
2549 | 2577 | |
|
2550 | 2578 | if opts.has_key('d'): |
|
2551 | 2579 | try: |
|
2552 | 2580 | todel = args[0] |
|
2553 | 2581 | except IndexError: |
|
2554 | 2582 | error('You must provide a bookmark to delete') |
|
2555 | 2583 | else: |
|
2556 | 2584 | try: |
|
2557 | 2585 | del bkms[todel] |
|
2558 | 2586 | except: |
|
2559 | 2587 | error("Can't delete bookmark '%s'" % todel) |
|
2560 | 2588 | elif opts.has_key('r'): |
|
2561 | 2589 | bkms = {} |
|
2562 | 2590 | elif opts.has_key('l'): |
|
2563 | 2591 | bks = bkms.keys() |
|
2564 | 2592 | bks.sort() |
|
2565 | 2593 | if bks: |
|
2566 | 2594 | size = max(map(len,bks)) |
|
2567 | 2595 | else: |
|
2568 | 2596 | size = 0 |
|
2569 | 2597 | fmt = '%-'+str(size)+'s -> %s' |
|
2570 | 2598 | print 'Current bookmarks:' |
|
2571 | 2599 | for bk in bks: |
|
2572 | 2600 | print fmt % (bk,bkms[bk]) |
|
2573 | 2601 | else: |
|
2574 | 2602 | if not args: |
|
2575 | 2603 | error("You must specify the bookmark name") |
|
2576 | 2604 | elif len(args)==1: |
|
2577 | 2605 | bkms[args[0]] = os.getcwd() |
|
2578 | 2606 | elif len(args)==2: |
|
2579 | 2607 | bkms[args[0]] = args[1] |
|
2580 | 2608 | self.persist['bookmarks'] = bkms |
|
2581 | 2609 | |
|
2582 | 2610 | def magic_pycat(self, parameter_s=''): |
|
2583 | 2611 | """Show a syntax-highlighted file through a pager. |
|
2584 | 2612 | |
|
2585 | 2613 | This magic is similar to the cat utility, but it will assume the file |
|
2586 | 2614 | to be Python source and will show it with syntax highlighting. """ |
|
2587 | 2615 | |
|
2588 | 2616 | filename = get_py_filename(parameter_s) |
|
2589 | 2617 | page(self.shell.colorize(file_read(filename)), |
|
2590 | 2618 | screen_lines=self.shell.rc.screen_length) |
|
2591 | 2619 | |
|
2592 | 2620 | # end Magic |
@@ -1,913 +1,917 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 96 |
|
|
7 | $Id: Shell.py 965 2005-12-28 23:23:09Z 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 os |
|
24 | 24 | import sys |
|
25 | 25 | import signal |
|
26 | 26 | import threading |
|
27 | 27 | |
|
28 | 28 | import IPython |
|
29 | 29 | from IPython import ultraTB |
|
30 | 30 | from IPython.genutils import Term,warn,error,flag_calls |
|
31 | 31 | from IPython.iplib import InteractiveShell |
|
32 | 32 | from IPython.ipmaker import make_IPython |
|
33 | 33 | from IPython.Magic import Magic |
|
34 | 34 | from IPython.Struct import Struct |
|
35 | 35 | |
|
36 | 36 | # global flag to pass around information about Ctrl-C without exceptions |
|
37 | 37 | KBINT = False |
|
38 | 38 | |
|
39 | 39 | # global flag to turn on/off Tk support. |
|
40 | 40 | USE_TK = False |
|
41 | 41 | |
|
42 | 42 | #----------------------------------------------------------------------------- |
|
43 | 43 | # This class is trivial now, but I want to have it in to publish a clean |
|
44 | 44 | # interface. Later when the internals are reorganized, code that uses this |
|
45 | 45 | # shouldn't have to change. |
|
46 | 46 | |
|
47 | 47 | class IPShell: |
|
48 | 48 | """Create an IPython instance.""" |
|
49 | 49 | |
|
50 | 50 | def __init__(self,argv=None,user_ns=None,user_global_ns=None, |
|
51 | 51 | debug=1,shell_class=InteractiveShell): |
|
52 | 52 | self.IP = make_IPython(argv,user_ns=user_ns,user_global_ns=user_global_ns, |
|
53 | 53 | debug=debug,shell_class=shell_class) |
|
54 | 54 | |
|
55 | 55 | def mainloop(self,sys_exit=0,banner=None): |
|
56 | 56 | self.IP.mainloop(banner) |
|
57 | 57 | if sys_exit: |
|
58 | 58 | sys.exit() |
|
59 | 59 | |
|
60 | 60 | #----------------------------------------------------------------------------- |
|
61 | 61 | class IPShellEmbed: |
|
62 | 62 | """Allow embedding an IPython shell into a running program. |
|
63 | 63 | |
|
64 | 64 | Instances of this class are callable, with the __call__ method being an |
|
65 | 65 | alias to the embed() method of an InteractiveShell instance. |
|
66 | 66 | |
|
67 | 67 | Usage (see also the example-embed.py file for a running example): |
|
68 | 68 | |
|
69 | 69 | ipshell = IPShellEmbed([argv,banner,exit_msg,rc_override]) |
|
70 | 70 | |
|
71 | 71 | - argv: list containing valid command-line options for IPython, as they |
|
72 | 72 | would appear in sys.argv[1:]. |
|
73 | 73 | |
|
74 | 74 | For example, the following command-line options: |
|
75 | 75 | |
|
76 | 76 | $ ipython -prompt_in1 'Input <\\#>' -colors LightBG |
|
77 | 77 | |
|
78 | 78 | would be passed in the argv list as: |
|
79 | 79 | |
|
80 | 80 | ['-prompt_in1','Input <\\#>','-colors','LightBG'] |
|
81 | 81 | |
|
82 | 82 | - banner: string which gets printed every time the interpreter starts. |
|
83 | 83 | |
|
84 | 84 | - exit_msg: string which gets printed every time the interpreter exits. |
|
85 | 85 | |
|
86 | 86 | - rc_override: a dict or Struct of configuration options such as those |
|
87 | 87 | used by IPython. These options are read from your ~/.ipython/ipythonrc |
|
88 | 88 | file when the Shell object is created. Passing an explicit rc_override |
|
89 | 89 | dict with any options you want allows you to override those values at |
|
90 | 90 | creation time without having to modify the file. This way you can create |
|
91 | 91 | embeddable instances configured in any way you want without editing any |
|
92 | 92 | global files (thus keeping your interactive IPython configuration |
|
93 | 93 | unchanged). |
|
94 | 94 | |
|
95 | 95 | Then the ipshell instance can be called anywhere inside your code: |
|
96 | 96 | |
|
97 | 97 | ipshell(header='') -> Opens up an IPython shell. |
|
98 | 98 | |
|
99 | 99 | - header: string printed by the IPython shell upon startup. This can let |
|
100 | 100 | you know where in your code you are when dropping into the shell. Note |
|
101 | 101 | that 'banner' gets prepended to all calls, so header is used for |
|
102 | 102 | location-specific information. |
|
103 | 103 | |
|
104 | 104 | For more details, see the __call__ method below. |
|
105 | 105 | |
|
106 | 106 | When the IPython shell is exited with Ctrl-D, normal program execution |
|
107 | 107 | resumes. |
|
108 | 108 | |
|
109 | 109 | This functionality was inspired by a posting on comp.lang.python by cmkl |
|
110 | 110 | <cmkleffner@gmx.de> on Dec. 06/01 concerning similar uses of pyrepl, and |
|
111 | 111 | by the IDL stop/continue commands.""" |
|
112 | 112 | |
|
113 | 113 | def __init__(self,argv=None,banner='',exit_msg=None,rc_override=None): |
|
114 | 114 | """Note that argv here is a string, NOT a list.""" |
|
115 | 115 | self.set_banner(banner) |
|
116 | 116 | self.set_exit_msg(exit_msg) |
|
117 | 117 | self.set_dummy_mode(0) |
|
118 | 118 | |
|
119 | 119 | # sys.displayhook is a global, we need to save the user's original |
|
120 | 120 | # Don't rely on __displayhook__, as the user may have changed that. |
|
121 | 121 | self.sys_displayhook_ori = sys.displayhook |
|
122 | 122 | |
|
123 | 123 | # save readline completer status |
|
124 | 124 | try: |
|
125 | 125 | #print 'Save completer',sys.ipcompleter # dbg |
|
126 | 126 | self.sys_ipcompleter_ori = sys.ipcompleter |
|
127 | 127 | except: |
|
128 | 128 | pass # not nested with IPython |
|
129 | 129 | |
|
130 | 130 | # FIXME. Passing user_ns breaks namespace handling. |
|
131 | 131 | #self.IP = make_IPython(argv,user_ns=__main__.__dict__) |
|
132 | 132 | self.IP = make_IPython(argv,rc_override=rc_override,embedded=True) |
|
133 | 133 | |
|
134 | 134 | # copy our own displayhook also |
|
135 | 135 | self.sys_displayhook_embed = sys.displayhook |
|
136 | 136 | # and leave the system's display hook clean |
|
137 | 137 | sys.displayhook = self.sys_displayhook_ori |
|
138 | 138 | # don't use the ipython crash handler so that user exceptions aren't |
|
139 | 139 | # trapped |
|
140 | 140 | sys.excepthook = ultraTB.FormattedTB(color_scheme = self.IP.rc.colors, |
|
141 | 141 | mode = self.IP.rc.xmode, |
|
142 | 142 | call_pdb = self.IP.rc.pdb) |
|
143 | 143 | self.restore_system_completer() |
|
144 | 144 | |
|
145 | 145 | def restore_system_completer(self): |
|
146 | 146 | """Restores the readline completer which was in place. |
|
147 | 147 | |
|
148 | 148 | This allows embedded IPython within IPython not to disrupt the |
|
149 | 149 | parent's completion. |
|
150 | 150 | """ |
|
151 | 151 | |
|
152 | 152 | try: |
|
153 | 153 | self.IP.readline.set_completer(self.sys_ipcompleter_ori) |
|
154 | 154 | sys.ipcompleter = self.sys_ipcompleter_ori |
|
155 | 155 | except: |
|
156 | 156 | pass |
|
157 | 157 | |
|
158 | 158 | def __call__(self,header='',local_ns=None,global_ns=None,dummy=None): |
|
159 | 159 | """Activate the interactive interpreter. |
|
160 | 160 | |
|
161 | 161 | __call__(self,header='',local_ns=None,global_ns,dummy=None) -> Start |
|
162 | 162 | the interpreter shell with the given local and global namespaces, and |
|
163 | 163 | optionally print a header string at startup. |
|
164 | 164 | |
|
165 | 165 | The shell can be globally activated/deactivated using the |
|
166 | 166 | set/get_dummy_mode methods. This allows you to turn off a shell used |
|
167 | 167 | for debugging globally. |
|
168 | 168 | |
|
169 | 169 | However, *each* time you call the shell you can override the current |
|
170 | 170 | state of dummy_mode with the optional keyword parameter 'dummy'. For |
|
171 | 171 | example, if you set dummy mode on with IPShell.set_dummy_mode(1), you |
|
172 | 172 | can still have a specific call work by making it as IPShell(dummy=0). |
|
173 | 173 | |
|
174 | 174 | The optional keyword parameter dummy controls whether the call |
|
175 | 175 | actually does anything. """ |
|
176 | 176 | |
|
177 | 177 | # Allow the dummy parameter to override the global __dummy_mode |
|
178 | 178 | if dummy or (dummy != 0 and self.__dummy_mode): |
|
179 | 179 | return |
|
180 | 180 | |
|
181 | 181 | # Set global subsystems (display,completions) to our values |
|
182 | 182 | sys.displayhook = self.sys_displayhook_embed |
|
183 | 183 | if self.IP.has_readline: |
|
184 | 184 | self.IP.readline.set_completer(self.IP.Completer.complete) |
|
185 | 185 | |
|
186 | 186 | if self.banner and header: |
|
187 | 187 | format = '%s\n%s\n' |
|
188 | 188 | else: |
|
189 | 189 | format = '%s%s\n' |
|
190 | 190 | banner = format % (self.banner,header) |
|
191 | 191 | |
|
192 | 192 | # Call the embedding code with a stack depth of 1 so it can skip over |
|
193 | 193 | # our call and get the original caller's namespaces. |
|
194 | 194 | self.IP.embed_mainloop(banner,local_ns,global_ns,stack_depth=1) |
|
195 | 195 | |
|
196 | 196 | if self.exit_msg: |
|
197 | 197 | print self.exit_msg |
|
198 | 198 | |
|
199 | 199 | # Restore global systems (display, completion) |
|
200 | 200 | sys.displayhook = self.sys_displayhook_ori |
|
201 | 201 | self.restore_system_completer() |
|
202 | 202 | |
|
203 | 203 | def set_dummy_mode(self,dummy): |
|
204 | 204 | """Sets the embeddable shell's dummy mode parameter. |
|
205 | 205 | |
|
206 | 206 | set_dummy_mode(dummy): dummy = 0 or 1. |
|
207 | 207 | |
|
208 | 208 | This parameter is persistent and makes calls to the embeddable shell |
|
209 | 209 | silently return without performing any action. This allows you to |
|
210 | 210 | globally activate or deactivate a shell you're using with a single call. |
|
211 | 211 | |
|
212 | 212 | If you need to manually""" |
|
213 | 213 | |
|
214 | 214 | if dummy not in [0,1,False,True]: |
|
215 | 215 | raise ValueError,'dummy parameter must be boolean' |
|
216 | 216 | self.__dummy_mode = dummy |
|
217 | 217 | |
|
218 | 218 | def get_dummy_mode(self): |
|
219 | 219 | """Return the current value of the dummy mode parameter. |
|
220 | 220 | """ |
|
221 | 221 | return self.__dummy_mode |
|
222 | 222 | |
|
223 | 223 | def set_banner(self,banner): |
|
224 | 224 | """Sets the global banner. |
|
225 | 225 | |
|
226 | 226 | This banner gets prepended to every header printed when the shell |
|
227 | 227 | instance is called.""" |
|
228 | 228 | |
|
229 | 229 | self.banner = banner |
|
230 | 230 | |
|
231 | 231 | def set_exit_msg(self,exit_msg): |
|
232 | 232 | """Sets the global exit_msg. |
|
233 | 233 | |
|
234 | 234 | This exit message gets printed upon exiting every time the embedded |
|
235 | 235 | shell is called. It is None by default. """ |
|
236 | 236 | |
|
237 | 237 | self.exit_msg = exit_msg |
|
238 | 238 | |
|
239 | 239 | #----------------------------------------------------------------------------- |
|
240 | 240 | def sigint_handler (signum,stack_frame): |
|
241 | 241 | """Sigint handler for threaded apps. |
|
242 | 242 | |
|
243 | 243 | This is a horrible hack to pass information about SIGINT _without_ using |
|
244 | 244 | exceptions, since I haven't been able to properly manage cross-thread |
|
245 | 245 | exceptions in GTK/WX. In fact, I don't think it can be done (or at least |
|
246 | 246 | that's my understanding from a c.l.py thread where this was discussed).""" |
|
247 | 247 | |
|
248 | 248 | global KBINT |
|
249 | 249 | |
|
250 | 250 | print '\nKeyboardInterrupt - Press <Enter> to continue.', |
|
251 | 251 | Term.cout.flush() |
|
252 | 252 | # Set global flag so that runsource can know that Ctrl-C was hit |
|
253 | 253 | KBINT = True |
|
254 | 254 | |
|
255 | 255 | class MTInteractiveShell(InteractiveShell): |
|
256 | 256 | """Simple multi-threaded shell.""" |
|
257 | 257 | |
|
258 | 258 | # Threading strategy taken from: |
|
259 | 259 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by Brian |
|
260 | 260 | # McErlean and John Finlay. Modified with corrections by Antoon Pardon, |
|
261 | 261 | # from the pygtk mailing list, to avoid lockups with system calls. |
|
262 | 262 | |
|
263 | # class attribute to indicate whether the class supports threads or not. | |
|
264 | # Subclasses with thread support should override this as needed. | |
|
265 | isthreaded = True | |
|
266 | ||
|
263 | 267 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
264 | 268 | user_ns=None,user_global_ns=None,banner2='',**kw): |
|
265 | 269 | """Similar to the normal InteractiveShell, but with threading control""" |
|
266 | 270 | |
|
267 | 271 | InteractiveShell.__init__(self,name,usage,rc,user_ns, |
|
268 | 272 | user_global_ns,banner2) |
|
269 | 273 | |
|
270 | 274 | # Locking control variable |
|
271 | 275 | self.thread_ready = threading.Condition() |
|
272 | 276 | |
|
273 | 277 | # Stuff to do at closing time |
|
274 | 278 | self._kill = False |
|
275 | 279 | on_kill = kw.get('on_kill') |
|
276 | 280 | if on_kill is None: |
|
277 | 281 | on_kill = [] |
|
278 | 282 | # Check that all things to kill are callable: |
|
279 | 283 | for t in on_kill: |
|
280 | 284 | if not callable(t): |
|
281 | 285 | raise TypeError,'on_kill must be a list of callables' |
|
282 | 286 | self.on_kill = on_kill |
|
283 | 287 | |
|
284 | 288 | def runsource(self, source, filename="<input>", symbol="single"): |
|
285 | 289 | """Compile and run some source in the interpreter. |
|
286 | 290 | |
|
287 | 291 | Modified version of code.py's runsource(), to handle threading issues. |
|
288 | 292 | See the original for full docstring details.""" |
|
289 | 293 | |
|
290 | 294 | global KBINT |
|
291 | 295 | |
|
292 | 296 | # If Ctrl-C was typed, we reset the flag and return right away |
|
293 | 297 | if KBINT: |
|
294 | 298 | KBINT = False |
|
295 | 299 | return False |
|
296 | 300 | |
|
297 | 301 | try: |
|
298 | 302 | code = self.compile(source, filename, symbol) |
|
299 | 303 | except (OverflowError, SyntaxError, ValueError): |
|
300 | 304 | # Case 1 |
|
301 | 305 | self.showsyntaxerror(filename) |
|
302 | 306 | return False |
|
303 | 307 | |
|
304 | 308 | if code is None: |
|
305 | 309 | # Case 2 |
|
306 | 310 | return True |
|
307 | 311 | |
|
308 | 312 | # Case 3 |
|
309 | 313 | # Store code in self, so the execution thread can handle it |
|
310 | 314 | self.thread_ready.acquire() |
|
311 | 315 | self.code_to_run = code |
|
312 | 316 | self.thread_ready.wait() # Wait until processed in timeout interval |
|
313 | 317 | self.thread_ready.release() |
|
314 | 318 | |
|
315 | 319 | return False |
|
316 | 320 | |
|
317 | 321 | def runcode(self): |
|
318 | 322 | """Execute a code object. |
|
319 | 323 | |
|
320 | 324 | Multithreaded wrapper around IPython's runcode().""" |
|
321 | 325 | |
|
322 | 326 | # lock thread-protected stuff |
|
323 | 327 | self.thread_ready.acquire() |
|
324 | 328 | |
|
325 | 329 | # Install sigint handler |
|
326 | 330 | try: |
|
327 | 331 | signal.signal(signal.SIGINT, sigint_handler) |
|
328 | 332 | except SystemError: |
|
329 | 333 | # This happens under Windows, which seems to have all sorts |
|
330 | 334 | # of problems with signal handling. Oh well... |
|
331 | 335 | pass |
|
332 | 336 | |
|
333 | 337 | if self._kill: |
|
334 | 338 | print >>Term.cout, 'Closing threads...', |
|
335 | 339 | Term.cout.flush() |
|
336 | 340 | for tokill in self.on_kill: |
|
337 | 341 | tokill() |
|
338 | 342 | print >>Term.cout, 'Done.' |
|
339 | 343 | |
|
340 | 344 | # Run pending code by calling parent class |
|
341 | 345 | if self.code_to_run is not None: |
|
342 | 346 | self.thread_ready.notify() |
|
343 | 347 | InteractiveShell.runcode(self,self.code_to_run) |
|
344 | 348 | |
|
345 | 349 | # We're done with thread-protected variables |
|
346 | 350 | self.thread_ready.release() |
|
347 | 351 | # This MUST return true for gtk threading to work |
|
348 | 352 | return True |
|
349 | 353 | |
|
350 | 354 | def kill (self): |
|
351 | 355 | """Kill the thread, returning when it has been shut down.""" |
|
352 | 356 | self.thread_ready.acquire() |
|
353 | 357 | self._kill = True |
|
354 | 358 | self.thread_ready.release() |
|
355 | 359 | |
|
356 | 360 | class MatplotlibShellBase: |
|
357 | 361 | """Mixin class to provide the necessary modifications to regular IPython |
|
358 | 362 | shell classes for matplotlib support. |
|
359 | 363 | |
|
360 | 364 | Given Python's MRO, this should be used as the FIRST class in the |
|
361 | 365 | inheritance hierarchy, so that it overrides the relevant methods.""" |
|
362 | 366 | |
|
363 | 367 | def _matplotlib_config(self,name): |
|
364 | 368 | """Return various items needed to setup the user's shell with matplotlib""" |
|
365 | 369 | |
|
366 | 370 | # Initialize matplotlib to interactive mode always |
|
367 | 371 | import matplotlib |
|
368 | 372 | from matplotlib import backends |
|
369 | 373 | matplotlib.interactive(True) |
|
370 | 374 | |
|
371 | 375 | def use(arg): |
|
372 | 376 | """IPython wrapper for matplotlib's backend switcher. |
|
373 | 377 | |
|
374 | 378 | In interactive use, we can not allow switching to a different |
|
375 | 379 | interactive backend, since thread conflicts will most likely crash |
|
376 | 380 | the python interpreter. This routine does a safety check first, |
|
377 | 381 | and refuses to perform a dangerous switch. It still allows |
|
378 | 382 | switching to non-interactive backends.""" |
|
379 | 383 | |
|
380 | 384 | if arg in backends.interactive_bk and arg != self.mpl_backend: |
|
381 | 385 | m=('invalid matplotlib backend switch.\n' |
|
382 | 386 | 'This script attempted to switch to the interactive ' |
|
383 | 387 | 'backend: `%s`\n' |
|
384 | 388 | 'Your current choice of interactive backend is: `%s`\n\n' |
|
385 | 389 | 'Switching interactive matplotlib backends at runtime\n' |
|
386 | 390 | 'would crash the python interpreter, ' |
|
387 | 391 | 'and IPython has blocked it.\n\n' |
|
388 | 392 | 'You need to either change your choice of matplotlib backend\n' |
|
389 | 393 | 'by editing your .matplotlibrc file, or run this script as a \n' |
|
390 | 394 | 'standalone file from the command line, not using IPython.\n' % |
|
391 | 395 | (arg,self.mpl_backend) ) |
|
392 | 396 | raise RuntimeError, m |
|
393 | 397 | else: |
|
394 | 398 | self.mpl_use(arg) |
|
395 | 399 | self.mpl_use._called = True |
|
396 | 400 | |
|
397 | 401 | self.matplotlib = matplotlib |
|
398 | 402 | self.mpl_backend = matplotlib.rcParams['backend'] |
|
399 | 403 | |
|
400 | 404 | # we also need to block switching of interactive backends by use() |
|
401 | 405 | self.mpl_use = matplotlib.use |
|
402 | 406 | self.mpl_use._called = False |
|
403 | 407 | # overwrite the original matplotlib.use with our wrapper |
|
404 | 408 | matplotlib.use = use |
|
405 | 409 | |
|
406 | 410 | |
|
407 | 411 | # This must be imported last in the matplotlib series, after |
|
408 | 412 | # backend/interactivity choices have been made |
|
409 | 413 | try: |
|
410 | 414 | import matplotlib.pylab as pylab |
|
411 | 415 | self.pylab = pylab |
|
412 | 416 | self.pylab_name = 'pylab' |
|
413 | 417 | except ImportError: |
|
414 | 418 | import matplotlib.matlab as matlab |
|
415 | 419 | self.pylab = matlab |
|
416 | 420 | self.pylab_name = 'matlab' |
|
417 | 421 | |
|
418 | 422 | self.pylab.show._needmain = False |
|
419 | 423 | # We need to detect at runtime whether show() is called by the user. |
|
420 | 424 | # For this, we wrap it into a decorator which adds a 'called' flag. |
|
421 | 425 | self.pylab.draw_if_interactive = flag_calls(self.pylab.draw_if_interactive) |
|
422 | 426 | |
|
423 | 427 | # Build a user namespace initialized with matplotlib/matlab features. |
|
424 | 428 | user_ns = {'__name__':'__main__', |
|
425 | 429 | '__builtins__' : __builtin__ } |
|
426 | 430 | |
|
427 | 431 | # Be careful not to remove the final \n in the code string below, or |
|
428 | 432 | # things will break badly with py22 (I think it's a python bug, 2.3 is |
|
429 | 433 | # OK). |
|
430 | 434 | pname = self.pylab_name # Python can't interpolate dotted var names |
|
431 | 435 | exec ("import matplotlib\n" |
|
432 | 436 | "import matplotlib.%(pname)s as %(pname)s\n" |
|
433 | 437 | "from matplotlib.%(pname)s import *\n" % locals()) in user_ns |
|
434 | 438 | |
|
435 | 439 | # Build matplotlib info banner |
|
436 | 440 | b=""" |
|
437 | 441 | Welcome to pylab, a matplotlib-based Python environment. |
|
438 | 442 | For more information, type 'help(pylab)'. |
|
439 | 443 | """ |
|
440 | 444 | return user_ns,b |
|
441 | 445 | |
|
442 | 446 | def mplot_exec(self,fname,*where,**kw): |
|
443 | 447 | """Execute a matplotlib script. |
|
444 | 448 | |
|
445 | 449 | This is a call to execfile(), but wrapped in safeties to properly |
|
446 | 450 | handle interactive rendering and backend switching.""" |
|
447 | 451 | |
|
448 | 452 | #print '*** Matplotlib runner ***' # dbg |
|
449 | 453 | # turn off rendering until end of script |
|
450 | 454 | isInteractive = self.matplotlib.rcParams['interactive'] |
|
451 | 455 | self.matplotlib.interactive(False) |
|
452 | 456 | self.safe_execfile(fname,*where,**kw) |
|
453 | 457 | self.matplotlib.interactive(isInteractive) |
|
454 | 458 | # make rendering call now, if the user tried to do it |
|
455 | 459 | if self.pylab.draw_if_interactive.called: |
|
456 | 460 | self.pylab.draw() |
|
457 | 461 | self.pylab.draw_if_interactive.called = False |
|
458 | 462 | |
|
459 | 463 | # if a backend switch was performed, reverse it now |
|
460 | 464 | if self.mpl_use._called: |
|
461 | 465 | self.matplotlib.rcParams['backend'] = self.mpl_backend |
|
462 | 466 | |
|
463 | 467 | def magic_run(self,parameter_s=''): |
|
464 | 468 | Magic.magic_run(self,parameter_s,runner=self.mplot_exec) |
|
465 | 469 | |
|
466 | 470 | # Fix the docstring so users see the original as well |
|
467 | 471 | magic_run.__doc__ = "%s\n%s" % (Magic.magic_run.__doc__, |
|
468 | 472 | "\n *** Modified %run for Matplotlib," |
|
469 | 473 | " with proper interactive handling ***") |
|
470 | 474 | |
|
471 | 475 | # Now we provide 2 versions of a matplotlib-aware IPython base shells, single |
|
472 | 476 | # and multithreaded. Note that these are meant for internal use, the IPShell* |
|
473 | 477 | # classes below are the ones meant for public consumption. |
|
474 | 478 | |
|
475 | 479 | class MatplotlibShell(MatplotlibShellBase,InteractiveShell): |
|
476 | 480 | """Single-threaded shell with matplotlib support.""" |
|
477 | 481 | |
|
478 | 482 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
479 | 483 | user_ns=None,user_global_ns=None,**kw): |
|
480 | 484 | user_ns,b2 = self._matplotlib_config(name) |
|
481 | 485 | InteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns, |
|
482 | 486 | banner2=b2,**kw) |
|
483 | 487 | |
|
484 | 488 | class MatplotlibMTShell(MatplotlibShellBase,MTInteractiveShell): |
|
485 | 489 | """Multi-threaded shell with matplotlib support.""" |
|
486 | 490 | |
|
487 | 491 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
488 | 492 | user_ns=None,user_global_ns=None, **kw): |
|
489 | 493 | user_ns,b2 = self._matplotlib_config(name) |
|
490 | 494 | MTInteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns, |
|
491 | 495 | banner2=b2,**kw) |
|
492 | 496 | |
|
493 | 497 | #----------------------------------------------------------------------------- |
|
494 | 498 | # Utility functions for the different GUI enabled IPShell* classes. |
|
495 | 499 | |
|
496 | 500 | def get_tk(): |
|
497 | 501 | """Tries to import Tkinter and returns a withdrawn Tkinter root |
|
498 | 502 | window. If Tkinter is already imported or not available, this |
|
499 | 503 | returns None. This function calls `hijack_tk` underneath. |
|
500 | 504 | """ |
|
501 | 505 | if not USE_TK or sys.modules.has_key('Tkinter'): |
|
502 | 506 | return None |
|
503 | 507 | else: |
|
504 | 508 | try: |
|
505 | 509 | import Tkinter |
|
506 | 510 | except ImportError: |
|
507 | 511 | return None |
|
508 | 512 | else: |
|
509 | 513 | hijack_tk() |
|
510 | 514 | r = Tkinter.Tk() |
|
511 | 515 | r.withdraw() |
|
512 | 516 | return r |
|
513 | 517 | |
|
514 | 518 | def hijack_tk(): |
|
515 | 519 | """Modifies Tkinter's mainloop with a dummy so when a module calls |
|
516 | 520 | mainloop, it does not block. |
|
517 | 521 | |
|
518 | 522 | """ |
|
519 | 523 | def misc_mainloop(self, n=0): |
|
520 | 524 | pass |
|
521 | 525 | def tkinter_mainloop(n=0): |
|
522 | 526 | pass |
|
523 | 527 | |
|
524 | 528 | import Tkinter |
|
525 | 529 | Tkinter.Misc.mainloop = misc_mainloop |
|
526 | 530 | Tkinter.mainloop = tkinter_mainloop |
|
527 | 531 | |
|
528 | 532 | def update_tk(tk): |
|
529 | 533 | """Updates the Tkinter event loop. This is typically called from |
|
530 | 534 | the respective WX or GTK mainloops. |
|
531 | 535 | """ |
|
532 | 536 | if tk: |
|
533 | 537 | tk.update() |
|
534 | 538 | |
|
535 | 539 | def hijack_wx(): |
|
536 | 540 | """Modifies wxPython's MainLoop with a dummy so user code does not |
|
537 | 541 | block IPython. The hijacked mainloop function is returned. |
|
538 | 542 | """ |
|
539 | 543 | def dummy_mainloop(*args, **kw): |
|
540 | 544 | pass |
|
541 | 545 | import wxPython |
|
542 | 546 | ver = wxPython.__version__ |
|
543 | 547 | orig_mainloop = None |
|
544 | 548 | if ver[:3] >= '2.5': |
|
545 | 549 | import wx |
|
546 | 550 | if hasattr(wx, '_core_'): core = getattr(wx, '_core_') |
|
547 | 551 | elif hasattr(wx, '_core'): core = getattr(wx, '_core') |
|
548 | 552 | else: raise AttributeError('Could not find wx core module') |
|
549 | 553 | orig_mainloop = core.PyApp_MainLoop |
|
550 | 554 | core.PyApp_MainLoop = dummy_mainloop |
|
551 | 555 | elif ver[:3] == '2.4': |
|
552 | 556 | orig_mainloop = wxPython.wxc.wxPyApp_MainLoop |
|
553 | 557 | wxPython.wxc.wxPyApp_MainLoop = dummy_mainloop |
|
554 | 558 | else: |
|
555 | 559 | warn("Unable to find either wxPython version 2.4 or >= 2.5.") |
|
556 | 560 | return orig_mainloop |
|
557 | 561 | |
|
558 | 562 | def hijack_gtk(): |
|
559 | 563 | """Modifies pyGTK's mainloop with a dummy so user code does not |
|
560 | 564 | block IPython. This function returns the original `gtk.mainloop` |
|
561 | 565 | function that has been hijacked. |
|
562 | 566 | """ |
|
563 | 567 | def dummy_mainloop(*args, **kw): |
|
564 | 568 | pass |
|
565 | 569 | import gtk |
|
566 | 570 | if gtk.pygtk_version >= (2,4,0): orig_mainloop = gtk.main |
|
567 | 571 | else: orig_mainloop = gtk.mainloop |
|
568 | 572 | gtk.mainloop = dummy_mainloop |
|
569 | 573 | gtk.main = dummy_mainloop |
|
570 | 574 | return orig_mainloop |
|
571 | 575 | |
|
572 | 576 | #----------------------------------------------------------------------------- |
|
573 | 577 | # The IPShell* classes below are the ones meant to be run by external code as |
|
574 | 578 | # IPython instances. Note that unless a specific threading strategy is |
|
575 | 579 | # desired, the factory function start() below should be used instead (it |
|
576 | 580 | # selects the proper threaded class). |
|
577 | 581 | |
|
578 | 582 | class IPShellGTK(threading.Thread): |
|
579 | 583 | """Run a gtk mainloop() in a separate thread. |
|
580 | 584 | |
|
581 | 585 | Python commands can be passed to the thread where they will be executed. |
|
582 | 586 | This is implemented by periodically checking for passed code using a |
|
583 | 587 | GTK timeout callback.""" |
|
584 | 588 | |
|
585 | 589 | TIMEOUT = 100 # Millisecond interval between timeouts. |
|
586 | 590 | |
|
587 | 591 | def __init__(self,argv=None,user_ns=None,user_global_ns=None, |
|
588 | 592 | debug=1,shell_class=MTInteractiveShell): |
|
589 | 593 | |
|
590 | 594 | import gtk |
|
591 | 595 | |
|
592 | 596 | self.gtk = gtk |
|
593 | 597 | self.gtk_mainloop = hijack_gtk() |
|
594 | 598 | |
|
595 | 599 | # Allows us to use both Tk and GTK. |
|
596 | 600 | self.tk = get_tk() |
|
597 | 601 | |
|
598 | 602 | if gtk.pygtk_version >= (2,4,0): mainquit = self.gtk.main_quit |
|
599 | 603 | else: mainquit = self.gtk.mainquit |
|
600 | 604 | |
|
601 | 605 | self.IP = make_IPython(argv,user_ns=user_ns, |
|
602 | 606 | user_global_ns=user_global_ns, |
|
603 | 607 | debug=debug, |
|
604 | 608 | shell_class=shell_class, |
|
605 | 609 | on_kill=[mainquit]) |
|
606 | 610 | |
|
607 | 611 | # HACK: slot for banner in self; it will be passed to the mainloop |
|
608 | 612 | # method only and .run() needs it. The actual value will be set by |
|
609 | 613 | # .mainloop(). |
|
610 | 614 | self._banner = None |
|
611 | 615 | |
|
612 | 616 | threading.Thread.__init__(self) |
|
613 | 617 | |
|
614 | 618 | def run(self): |
|
615 | 619 | self.IP.mainloop(self._banner) |
|
616 | 620 | self.IP.kill() |
|
617 | 621 | |
|
618 | 622 | def mainloop(self,sys_exit=0,banner=None): |
|
619 | 623 | |
|
620 | 624 | self._banner = banner |
|
621 | 625 | |
|
622 | 626 | if self.gtk.pygtk_version >= (2,4,0): |
|
623 | 627 | import gobject |
|
624 | 628 | gobject.idle_add(self.on_timer) |
|
625 | 629 | else: |
|
626 | 630 | self.gtk.idle_add(self.on_timer) |
|
627 | 631 | |
|
628 | 632 | if sys.platform != 'win32': |
|
629 | 633 | try: |
|
630 | 634 | if self.gtk.gtk_version[0] >= 2: |
|
631 | 635 | self.gtk.threads_init() |
|
632 | 636 | except AttributeError: |
|
633 | 637 | pass |
|
634 | 638 | except RuntimeError: |
|
635 | 639 | error('Your pyGTK likely has not been compiled with ' |
|
636 | 640 | 'threading support.\n' |
|
637 | 641 | 'The exception printout is below.\n' |
|
638 | 642 | 'You can either rebuild pyGTK with threads, or ' |
|
639 | 643 | 'try using \n' |
|
640 | 644 | 'matplotlib with a different backend (like Tk or WX).\n' |
|
641 | 645 | 'Note that matplotlib will most likely not work in its ' |
|
642 | 646 | 'current state!') |
|
643 | 647 | self.IP.InteractiveTB() |
|
644 | 648 | self.start() |
|
645 | 649 | self.gtk.threads_enter() |
|
646 | 650 | self.gtk_mainloop() |
|
647 | 651 | self.gtk.threads_leave() |
|
648 | 652 | self.join() |
|
649 | 653 | |
|
650 | 654 | def on_timer(self): |
|
651 | 655 | update_tk(self.tk) |
|
652 | 656 | return self.IP.runcode() |
|
653 | 657 | |
|
654 | 658 | |
|
655 | 659 | class IPShellWX(threading.Thread): |
|
656 | 660 | """Run a wx mainloop() in a separate thread. |
|
657 | 661 | |
|
658 | 662 | Python commands can be passed to the thread where they will be executed. |
|
659 | 663 | This is implemented by periodically checking for passed code using a |
|
660 | 664 | GTK timeout callback.""" |
|
661 | 665 | |
|
662 | 666 | TIMEOUT = 100 # Millisecond interval between timeouts. |
|
663 | 667 | |
|
664 | 668 | def __init__(self,argv=None,user_ns=None,user_global_ns=None, |
|
665 | 669 | debug=1,shell_class=MTInteractiveShell): |
|
666 | 670 | |
|
667 | 671 | import wxPython.wx as wx |
|
668 | 672 | |
|
669 | 673 | threading.Thread.__init__(self) |
|
670 | 674 | self.wx = wx |
|
671 | 675 | self.wx_mainloop = hijack_wx() |
|
672 | 676 | |
|
673 | 677 | # Allows us to use both Tk and GTK. |
|
674 | 678 | self.tk = get_tk() |
|
675 | 679 | |
|
676 | 680 | self.IP = make_IPython(argv,user_ns=user_ns, |
|
677 | 681 | user_global_ns=user_global_ns, |
|
678 | 682 | debug=debug, |
|
679 | 683 | shell_class=shell_class, |
|
680 | 684 | on_kill=[self.wxexit]) |
|
681 | 685 | # HACK: slot for banner in self; it will be passed to the mainloop |
|
682 | 686 | # method only and .run() needs it. The actual value will be set by |
|
683 | 687 | # .mainloop(). |
|
684 | 688 | self._banner = None |
|
685 | 689 | |
|
686 | 690 | self.app = None |
|
687 | 691 | |
|
688 | 692 | def wxexit(self, *args): |
|
689 | 693 | if self.app is not None: |
|
690 | 694 | self.app.agent.timer.Stop() |
|
691 | 695 | self.app.ExitMainLoop() |
|
692 | 696 | |
|
693 | 697 | def run(self): |
|
694 | 698 | self.IP.mainloop(self._banner) |
|
695 | 699 | self.IP.kill() |
|
696 | 700 | |
|
697 | 701 | def mainloop(self,sys_exit=0,banner=None): |
|
698 | 702 | |
|
699 | 703 | self._banner = banner |
|
700 | 704 | |
|
701 | 705 | self.start() |
|
702 | 706 | |
|
703 | 707 | class TimerAgent(self.wx.wxMiniFrame): |
|
704 | 708 | wx = self.wx |
|
705 | 709 | IP = self.IP |
|
706 | 710 | tk = self.tk |
|
707 | 711 | def __init__(self, parent, interval): |
|
708 | 712 | style = self.wx.wxDEFAULT_FRAME_STYLE | self.wx.wxTINY_CAPTION_HORIZ |
|
709 | 713 | self.wx.wxMiniFrame.__init__(self, parent, -1, ' ', pos=(200, 200), |
|
710 | 714 | size=(100, 100),style=style) |
|
711 | 715 | self.Show(False) |
|
712 | 716 | self.interval = interval |
|
713 | 717 | self.timerId = self.wx.wxNewId() |
|
714 | 718 | |
|
715 | 719 | def StartWork(self): |
|
716 | 720 | self.timer = self.wx.wxTimer(self, self.timerId) |
|
717 | 721 | self.wx.EVT_TIMER(self, self.timerId, self.OnTimer) |
|
718 | 722 | self.timer.Start(self.interval) |
|
719 | 723 | |
|
720 | 724 | def OnTimer(self, event): |
|
721 | 725 | update_tk(self.tk) |
|
722 | 726 | self.IP.runcode() |
|
723 | 727 | |
|
724 | 728 | class App(self.wx.wxApp): |
|
725 | 729 | wx = self.wx |
|
726 | 730 | TIMEOUT = self.TIMEOUT |
|
727 | 731 | def OnInit(self): |
|
728 | 732 | 'Create the main window and insert the custom frame' |
|
729 | 733 | self.agent = TimerAgent(None, self.TIMEOUT) |
|
730 | 734 | self.agent.Show(self.wx.false) |
|
731 | 735 | self.agent.StartWork() |
|
732 | 736 | return self.wx.true |
|
733 | 737 | |
|
734 | 738 | self.app = App(redirect=False) |
|
735 | 739 | self.wx_mainloop(self.app) |
|
736 | 740 | self.join() |
|
737 | 741 | |
|
738 | 742 | |
|
739 | 743 | class IPShellQt(threading.Thread): |
|
740 | 744 | """Run a Qt event loop in a separate thread. |
|
741 | 745 | |
|
742 | 746 | Python commands can be passed to the thread where they will be executed. |
|
743 | 747 | This is implemented by periodically checking for passed code using a |
|
744 | 748 | Qt timer / slot.""" |
|
745 | 749 | |
|
746 | 750 | TIMEOUT = 100 # Millisecond interval between timeouts. |
|
747 | 751 | |
|
748 | 752 | def __init__(self,argv=None,user_ns=None,user_global_ns=None, |
|
749 | 753 | debug=0,shell_class=MTInteractiveShell): |
|
750 | 754 | |
|
751 | 755 | import qt |
|
752 | 756 | |
|
753 | 757 | class newQApplication: |
|
754 | 758 | def __init__( self ): |
|
755 | 759 | self.QApplication = qt.QApplication |
|
756 | 760 | |
|
757 | 761 | def __call__( *args, **kwargs ): |
|
758 | 762 | return qt.qApp |
|
759 | 763 | |
|
760 | 764 | def exec_loop( *args, **kwargs ): |
|
761 | 765 | pass |
|
762 | 766 | |
|
763 | 767 | def __getattr__( self, name ): |
|
764 | 768 | return getattr( self.QApplication, name ) |
|
765 | 769 | |
|
766 | 770 | qt.QApplication = newQApplication() |
|
767 | 771 | |
|
768 | 772 | # Allows us to use both Tk and QT. |
|
769 | 773 | self.tk = get_tk() |
|
770 | 774 | |
|
771 | 775 | self.IP = make_IPython(argv,user_ns=user_ns, |
|
772 | 776 | user_global_ns=user_global_ns, |
|
773 | 777 | debug=debug, |
|
774 | 778 | shell_class=shell_class, |
|
775 | 779 | on_kill=[qt.qApp.exit]) |
|
776 | 780 | |
|
777 | 781 | # HACK: slot for banner in self; it will be passed to the mainloop |
|
778 | 782 | # method only and .run() needs it. The actual value will be set by |
|
779 | 783 | # .mainloop(). |
|
780 | 784 | self._banner = None |
|
781 | 785 | |
|
782 | 786 | threading.Thread.__init__(self) |
|
783 | 787 | |
|
784 | 788 | def run(self): |
|
785 | 789 | self.IP.mainloop(self._banner) |
|
786 | 790 | self.IP.kill() |
|
787 | 791 | |
|
788 | 792 | def mainloop(self,sys_exit=0,banner=None): |
|
789 | 793 | |
|
790 | 794 | import qt |
|
791 | 795 | |
|
792 | 796 | self._banner = banner |
|
793 | 797 | |
|
794 | 798 | if qt.QApplication.startingUp(): |
|
795 | 799 | a = qt.QApplication.QApplication(sys.argv) |
|
796 | 800 | self.timer = qt.QTimer() |
|
797 | 801 | qt.QObject.connect( self.timer, qt.SIGNAL( 'timeout()' ), self.on_timer ) |
|
798 | 802 | |
|
799 | 803 | self.start() |
|
800 | 804 | self.timer.start( self.TIMEOUT, True ) |
|
801 | 805 | while True: |
|
802 | 806 | if self.IP._kill: break |
|
803 | 807 | qt.qApp.exec_loop() |
|
804 | 808 | self.join() |
|
805 | 809 | |
|
806 | 810 | def on_timer(self): |
|
807 | 811 | update_tk(self.tk) |
|
808 | 812 | result = self.IP.runcode() |
|
809 | 813 | self.timer.start( self.TIMEOUT, True ) |
|
810 | 814 | return result |
|
811 | 815 | |
|
812 | 816 | # A set of matplotlib public IPython shell classes, for single-threaded |
|
813 | 817 | # (Tk* and FLTK* backends) and multithreaded (GTK* and WX* backends) use. |
|
814 | 818 | class IPShellMatplotlib(IPShell): |
|
815 | 819 | """Subclass IPShell with MatplotlibShell as the internal shell. |
|
816 | 820 | |
|
817 | 821 | Single-threaded class, meant for the Tk* and FLTK* backends. |
|
818 | 822 | |
|
819 | 823 | Having this on a separate class simplifies the external driver code.""" |
|
820 | 824 | |
|
821 | 825 | def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): |
|
822 | 826 | IPShell.__init__(self,argv,user_ns,user_global_ns,debug, |
|
823 | 827 | shell_class=MatplotlibShell) |
|
824 | 828 | |
|
825 | 829 | class IPShellMatplotlibGTK(IPShellGTK): |
|
826 | 830 | """Subclass IPShellGTK with MatplotlibMTShell as the internal shell. |
|
827 | 831 | |
|
828 | 832 | Multi-threaded class, meant for the GTK* backends.""" |
|
829 | 833 | |
|
830 | 834 | def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): |
|
831 | 835 | IPShellGTK.__init__(self,argv,user_ns,user_global_ns,debug, |
|
832 | 836 | shell_class=MatplotlibMTShell) |
|
833 | 837 | |
|
834 | 838 | class IPShellMatplotlibWX(IPShellWX): |
|
835 | 839 | """Subclass IPShellWX with MatplotlibMTShell as the internal shell. |
|
836 | 840 | |
|
837 | 841 | Multi-threaded class, meant for the WX* backends.""" |
|
838 | 842 | |
|
839 | 843 | def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): |
|
840 | 844 | IPShellWX.__init__(self,argv,user_ns,user_global_ns,debug, |
|
841 | 845 | shell_class=MatplotlibMTShell) |
|
842 | 846 | |
|
843 | 847 | class IPShellMatplotlibQt(IPShellQt): |
|
844 | 848 | """Subclass IPShellQt with MatplotlibMTShell as the internal shell. |
|
845 | 849 | |
|
846 | 850 | Multi-threaded class, meant for the Qt* backends.""" |
|
847 | 851 | |
|
848 | 852 | def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1): |
|
849 | 853 | IPShellQt.__init__(self,argv,user_ns,user_global_ns,debug, |
|
850 | 854 | shell_class=MatplotlibMTShell) |
|
851 | 855 | |
|
852 | 856 | #----------------------------------------------------------------------------- |
|
853 | 857 | # Factory functions to actually start the proper thread-aware shell |
|
854 | 858 | |
|
855 | 859 | def _matplotlib_shell_class(): |
|
856 | 860 | """Factory function to handle shell class selection for matplotlib. |
|
857 | 861 | |
|
858 | 862 | The proper shell class to use depends on the matplotlib backend, since |
|
859 | 863 | each backend requires a different threading strategy.""" |
|
860 | 864 | |
|
861 | 865 | try: |
|
862 | 866 | import matplotlib |
|
863 | 867 | except ImportError: |
|
864 | 868 | error('matplotlib could NOT be imported! Starting normal IPython.') |
|
865 | 869 | sh_class = IPShell |
|
866 | 870 | else: |
|
867 | 871 | backend = matplotlib.rcParams['backend'] |
|
868 | 872 | if backend.startswith('GTK'): |
|
869 | 873 | sh_class = IPShellMatplotlibGTK |
|
870 | 874 | elif backend.startswith('WX'): |
|
871 | 875 | sh_class = IPShellMatplotlibWX |
|
872 | 876 | elif backend.startswith('Qt'): |
|
873 | 877 | sh_class = IPShellMatplotlibQt |
|
874 | 878 | else: |
|
875 | 879 | sh_class = IPShellMatplotlib |
|
876 | 880 | #print 'Using %s with the %s backend.' % (sh_class,backend) # dbg |
|
877 | 881 | return sh_class |
|
878 | 882 | |
|
879 | 883 | # This is the one which should be called by external code. |
|
880 | 884 | def start(): |
|
881 | 885 | """Return a running shell instance, dealing with threading options. |
|
882 | 886 | |
|
883 | 887 | This is a factory function which will instantiate the proper IPython shell |
|
884 | 888 | based on the user's threading choice. Such a selector is needed because |
|
885 | 889 | different GUI toolkits require different thread handling details.""" |
|
886 | 890 | |
|
887 | 891 | global USE_TK |
|
888 | 892 | # Crude sys.argv hack to extract the threading options. |
|
889 | 893 | argv = sys.argv |
|
890 | 894 | if len(argv) > 1: |
|
891 | 895 | if len(argv) > 2: |
|
892 | 896 | arg2 = argv[2] |
|
893 | 897 | if arg2.endswith('-tk'): |
|
894 | 898 | USE_TK = True |
|
895 | 899 | arg1 = argv[1] |
|
896 | 900 | if arg1.endswith('-gthread'): |
|
897 | 901 | shell = IPShellGTK |
|
898 | 902 | elif arg1.endswith( '-qthread' ): |
|
899 | 903 | shell = IPShellQt |
|
900 | 904 | elif arg1.endswith('-wthread'): |
|
901 | 905 | shell = IPShellWX |
|
902 | 906 | elif arg1.endswith('-pylab'): |
|
903 | 907 | shell = _matplotlib_shell_class() |
|
904 | 908 | else: |
|
905 | 909 | shell = IPShell |
|
906 | 910 | else: |
|
907 | 911 | shell = IPShell |
|
908 | 912 | return shell() |
|
909 | 913 | |
|
910 | 914 | # Some aliases for backwards compatibility |
|
911 | 915 | IPythonShell = IPShell |
|
912 | 916 | IPythonShellEmbed = IPShellEmbed |
|
913 | 917 | #************************ End of file <Shell.py> *************************** |
@@ -1,1968 +1,1997 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 96 |
|
|
9 | $Id: iplib.py 965 2005-12-28 23:23:09Z fperez $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
|
13 | 13 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
14 | 14 | # Copyright (C) 2001-2005 Fernando Perez. <fperez@colorado.edu> |
|
15 | 15 | # |
|
16 | 16 | # Distributed under the terms of the BSD License. The full license is in |
|
17 | 17 | # the file COPYING, distributed as part of this software. |
|
18 | 18 | # |
|
19 | 19 | # Note: this code originally subclassed code.InteractiveConsole from the |
|
20 | 20 | # Python standard library. Over time, all of that class has been copied |
|
21 | 21 | # verbatim here for modifications which could not be accomplished by |
|
22 | 22 | # subclassing. At this point, there are no dependencies at all on the code |
|
23 | 23 | # module anymore (it is not even imported). The Python License (sec. 2) |
|
24 | 24 | # allows for this, but it's always nice to acknowledge credit where credit is |
|
25 | 25 | # due. |
|
26 | 26 | #***************************************************************************** |
|
27 | 27 | |
|
28 | 28 | #**************************************************************************** |
|
29 | 29 | # Modules and globals |
|
30 | 30 | |
|
31 | 31 | from __future__ import generators # for 2.2 backwards-compatibility |
|
32 | 32 | |
|
33 | 33 | from IPython import Release |
|
34 | 34 | __author__ = '%s <%s>\n%s <%s>' % \ |
|
35 | 35 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) |
|
36 | 36 | __license__ = Release.license |
|
37 | 37 | __version__ = Release.version |
|
38 | 38 | |
|
39 | 39 | # Python standard modules |
|
40 | 40 | import __main__ |
|
41 | 41 | import __builtin__ |
|
42 | 42 | import StringIO |
|
43 | 43 | import bdb |
|
44 | 44 | import cPickle as pickle |
|
45 | 45 | import codeop |
|
46 | 46 | import exceptions |
|
47 | 47 | import glob |
|
48 | 48 | import inspect |
|
49 | 49 | import keyword |
|
50 | 50 | import new |
|
51 | 51 | import os |
|
52 | 52 | import pdb |
|
53 | 53 | import pydoc |
|
54 | 54 | import re |
|
55 | 55 | import shutil |
|
56 | 56 | import string |
|
57 | 57 | import sys |
|
58 | 58 | import traceback |
|
59 | 59 | import types |
|
60 | 60 | |
|
61 | 61 | from pprint import pprint, pformat |
|
62 | 62 | |
|
63 | 63 | # IPython's own modules |
|
64 | 64 | import IPython |
|
65 | 65 | from IPython import OInspect,PyColorize,ultraTB |
|
66 | 66 | from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names |
|
67 | 67 | from IPython.FakeModule import FakeModule |
|
68 | 68 | from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns |
|
69 | 69 | from IPython.Logger import Logger |
|
70 | 70 | from IPython.Magic import Magic,magic2python |
|
71 | 71 | from IPython.Struct import Struct |
|
72 | 72 | from IPython.background_jobs import BackgroundJobManager |
|
73 | 73 | from IPython.usage import cmd_line_usage,interactive_usage |
|
74 | 74 | from IPython.genutils import * |
|
75 | 75 | |
|
76 | 76 | # store the builtin raw_input globally, and use this always, in case user code |
|
77 | 77 | # overwrites it (like wx.py.PyShell does) |
|
78 | 78 | raw_input_original = raw_input |
|
79 | 79 | |
|
80 | 80 | #**************************************************************************** |
|
81 | 81 | # Some utility function definitions |
|
82 | 82 | |
|
83 | 83 | # This can be replaced with an isspace() call once we drop 2.2 compatibility |
|
84 | 84 | _isspace_match = re.compile(r'^\s+$').match |
|
85 | 85 | def isspace(s): |
|
86 | 86 | return bool(_isspace_match(s)) |
|
87 | 87 | |
|
88 | 88 | def esc_quotes(strng): |
|
89 | 89 | """Return the input string with single and double quotes escaped out""" |
|
90 | 90 | |
|
91 | 91 | return strng.replace('"','\\"').replace("'","\\'") |
|
92 | 92 | |
|
93 | 93 | def import_fail_info(mod_name,fns=None): |
|
94 | 94 | """Inform load failure for a module.""" |
|
95 | 95 | |
|
96 | 96 | if fns == None: |
|
97 | 97 | warn("Loading of %s failed.\n" % (mod_name,)) |
|
98 | 98 | else: |
|
99 | 99 | warn("Loading of %s from %s failed.\n" % (fns,mod_name)) |
|
100 | 100 | |
|
101 | 101 | def qw_lol(indata): |
|
102 | 102 | """qw_lol('a b') -> [['a','b']], |
|
103 | 103 | otherwise it's just a call to qw(). |
|
104 | 104 | |
|
105 | 105 | We need this to make sure the modules_some keys *always* end up as a |
|
106 | 106 | list of lists.""" |
|
107 | 107 | |
|
108 | 108 | if type(indata) in StringTypes: |
|
109 | 109 | return [qw(indata)] |
|
110 | 110 | else: |
|
111 | 111 | return qw(indata) |
|
112 | 112 | |
|
113 | 113 | def ipmagic(arg_s): |
|
114 | 114 | """Call a magic function by name. |
|
115 | 115 | |
|
116 | 116 | Input: a string containing the name of the magic function to call and any |
|
117 | 117 | additional arguments to be passed to the magic. |
|
118 | 118 | |
|
119 | 119 | ipmagic('name -opt foo bar') is equivalent to typing at the ipython |
|
120 | 120 | prompt: |
|
121 | 121 | |
|
122 | 122 | In[1]: %name -opt foo bar |
|
123 | 123 | |
|
124 | 124 | To call a magic without arguments, simply use ipmagic('name'). |
|
125 | 125 | |
|
126 | 126 | This provides a proper Python function to call IPython's magics in any |
|
127 | 127 | valid Python code you can type at the interpreter, including loops and |
|
128 | 128 | compound statements. It is added by IPython to the Python builtin |
|
129 | 129 | namespace upon initialization.""" |
|
130 | 130 | |
|
131 | 131 | args = arg_s.split(' ',1) |
|
132 | 132 | magic_name = args[0] |
|
133 | 133 | if magic_name.startswith(__IPYTHON__.ESC_MAGIC): |
|
134 | 134 | magic_name = magic_name[1:] |
|
135 | 135 | try: |
|
136 | 136 | magic_args = args[1] |
|
137 | 137 | except IndexError: |
|
138 | 138 | magic_args = '' |
|
139 | 139 | fn = getattr(__IPYTHON__,'magic_'+magic_name,None) |
|
140 | 140 | if fn is None: |
|
141 | 141 | error("Magic function `%s` not found." % magic_name) |
|
142 | 142 | else: |
|
143 | 143 | magic_args = __IPYTHON__.var_expand(magic_args) |
|
144 | 144 | return fn(magic_args) |
|
145 | 145 | |
|
146 | 146 | def ipalias(arg_s): |
|
147 | 147 | """Call an alias by name. |
|
148 | 148 | |
|
149 | 149 | Input: a string containing the name of the alias to call and any |
|
150 | 150 | additional arguments to be passed to the magic. |
|
151 | 151 | |
|
152 | 152 | ipalias('name -opt foo bar') is equivalent to typing at the ipython |
|
153 | 153 | prompt: |
|
154 | 154 | |
|
155 | 155 | In[1]: name -opt foo bar |
|
156 | 156 | |
|
157 | 157 | To call an alias without arguments, simply use ipalias('name'). |
|
158 | 158 | |
|
159 | 159 | This provides a proper Python function to call IPython's aliases in any |
|
160 | 160 | valid Python code you can type at the interpreter, including loops and |
|
161 | 161 | compound statements. It is added by IPython to the Python builtin |
|
162 | 162 | namespace upon initialization.""" |
|
163 | 163 | |
|
164 | 164 | args = arg_s.split(' ',1) |
|
165 | 165 | alias_name = args[0] |
|
166 | 166 | try: |
|
167 | 167 | alias_args = args[1] |
|
168 | 168 | except IndexError: |
|
169 | 169 | alias_args = '' |
|
170 | 170 | if alias_name in __IPYTHON__.alias_table: |
|
171 | 171 | __IPYTHON__.call_alias(alias_name,alias_args) |
|
172 | 172 | else: |
|
173 | 173 | error("Alias `%s` not found." % alias_name) |
|
174 | 174 | |
|
175 | 175 | def softspace(file, newvalue): |
|
176 | 176 | """Copied from code.py, to remove the dependency""" |
|
177 | 177 | oldvalue = 0 |
|
178 | 178 | try: |
|
179 | 179 | oldvalue = file.softspace |
|
180 | 180 | except AttributeError: |
|
181 | 181 | pass |
|
182 | 182 | try: |
|
183 | 183 | file.softspace = newvalue |
|
184 | 184 | except (AttributeError, TypeError): |
|
185 | 185 | # "attribute-less object" or "read-only attributes" |
|
186 | 186 | pass |
|
187 | 187 | return oldvalue |
|
188 | 188 | |
|
189 | 189 | |
|
190 | 190 | #**************************************************************************** |
|
191 | 191 | # Local use exceptions |
|
192 | 192 | class SpaceInInput(exceptions.Exception): pass |
|
193 | 193 | |
|
194 | 194 | #**************************************************************************** |
|
195 | 195 | # Local use classes |
|
196 | 196 | class Bunch: pass |
|
197 | 197 | |
|
198 | 198 | class InputList(list): |
|
199 | 199 | """Class to store user input. |
|
200 | 200 | |
|
201 | 201 | It's basically a list, but slices return a string instead of a list, thus |
|
202 | 202 | allowing things like (assuming 'In' is an instance): |
|
203 | 203 | |
|
204 | 204 | exec In[4:7] |
|
205 | 205 | |
|
206 | 206 | or |
|
207 | 207 | |
|
208 | 208 | exec In[5:9] + In[14] + In[21:25]""" |
|
209 | 209 | |
|
210 | 210 | def __getslice__(self,i,j): |
|
211 | 211 | return ''.join(list.__getslice__(self,i,j)) |
|
212 | 212 | |
|
213 | 213 | class SyntaxTB(ultraTB.ListTB): |
|
214 | 214 | """Extension which holds some state: the last exception value""" |
|
215 | 215 | |
|
216 | 216 | def __init__(self,color_scheme = 'NoColor'): |
|
217 | 217 | ultraTB.ListTB.__init__(self,color_scheme) |
|
218 | 218 | self.last_syntax_error = None |
|
219 | 219 | |
|
220 | 220 | def __call__(self, etype, value, elist): |
|
221 | 221 | self.last_syntax_error = value |
|
222 | 222 | ultraTB.ListTB.__call__(self,etype,value,elist) |
|
223 | 223 | |
|
224 | 224 | def clear_err_state(self): |
|
225 | 225 | """Return the current error state and clear it""" |
|
226 | 226 | e = self.last_syntax_error |
|
227 | 227 | self.last_syntax_error = None |
|
228 | 228 | return e |
|
229 | 229 | |
|
230 | 230 | #**************************************************************************** |
|
231 | 231 | # Main IPython class |
|
232 | 232 | class InteractiveShell(Logger, Magic): |
|
233 | 233 | """An enhanced console for Python.""" |
|
234 | 234 | |
|
235 | # class attribute to indicate whether the class supports threads or not. | |
|
236 | # Subclasses with thread support should override this as needed. | |
|
237 | isthreaded = False | |
|
238 | ||
|
235 | 239 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
236 | 240 | user_ns = None,user_global_ns=None,banner2='', |
|
237 | 241 | custom_exceptions=((),None),embedded=False): |
|
238 | 242 | |
|
239 | 243 | # some minimal strict typechecks. For some core data structures, I |
|
240 | 244 | # want actual basic python types, not just anything that looks like |
|
241 | 245 | # one. This is especially true for namespaces. |
|
242 | 246 | for ns in (user_ns,user_global_ns): |
|
243 | 247 | if ns is not None and type(ns) != types.DictType: |
|
244 | 248 | raise TypeError,'namespace must be a dictionary' |
|
245 | 249 | |
|
246 | 250 | # Put a reference to self in builtins so that any form of embedded or |
|
247 | 251 | # imported code can test for being inside IPython. |
|
248 | 252 | __builtin__.__IPYTHON__ = self |
|
249 | 253 | |
|
250 | 254 | # And load into builtins ipmagic/ipalias as well |
|
251 | 255 | __builtin__.ipmagic = ipmagic |
|
252 | 256 | __builtin__.ipalias = ipalias |
|
253 | 257 | |
|
254 | 258 | # Add to __builtin__ other parts of IPython's public API |
|
255 | 259 | __builtin__.ip_set_hook = self.set_hook |
|
256 | 260 | |
|
257 | 261 | # Keep in the builtins a flag for when IPython is active. We set it |
|
258 | 262 | # with setdefault so that multiple nested IPythons don't clobber one |
|
259 | 263 | # another. Each will increase its value by one upon being activated, |
|
260 | 264 | # which also gives us a way to determine the nesting level. |
|
261 | 265 | __builtin__.__dict__.setdefault('__IPYTHON__active',0) |
|
262 | 266 | |
|
263 | 267 | # Do the intuitively correct thing for quit/exit: we remove the |
|
264 | 268 | # builtins if they exist, and our own prefilter routine will handle |
|
265 | 269 | # these special cases |
|
266 | 270 | try: |
|
267 | 271 | del __builtin__.exit, __builtin__.quit |
|
268 | 272 | except AttributeError: |
|
269 | 273 | pass |
|
270 | 274 | |
|
275 | # Store the actual shell's name | |
|
276 | self.name = name | |
|
277 | ||
|
271 | 278 | # We need to know whether the instance is meant for embedding, since |
|
272 | 279 | # global/local namespaces need to be handled differently in that case |
|
273 | 280 | self.embedded = embedded |
|
274 | 281 | |
|
275 | 282 | # command compiler |
|
276 | 283 | self.compile = codeop.CommandCompiler() |
|
277 | 284 | |
|
278 | 285 | # User input buffer |
|
279 | 286 | self.buffer = [] |
|
280 | 287 | |
|
281 | 288 | # Default name given in compilation of code |
|
282 | 289 | self.filename = '<ipython console>' |
|
283 | 290 | |
|
284 | 291 | # Create the namespace where the user will operate. user_ns is |
|
285 | 292 | # normally the only one used, and it is passed to the exec calls as |
|
286 | 293 | # the locals argument. But we do carry a user_global_ns namespace |
|
287 | 294 | # given as the exec 'globals' argument, This is useful in embedding |
|
288 | 295 | # situations where the ipython shell opens in a context where the |
|
289 | 296 | # distinction between locals and globals is meaningful. |
|
290 | 297 | |
|
291 | 298 | # FIXME. For some strange reason, __builtins__ is showing up at user |
|
292 | 299 | # level as a dict instead of a module. This is a manual fix, but I |
|
293 | 300 | # should really track down where the problem is coming from. Alex |
|
294 | 301 | # Schmolck reported this problem first. |
|
295 | 302 | |
|
296 | 303 | # A useful post by Alex Martelli on this topic: |
|
297 | 304 | # Re: inconsistent value from __builtins__ |
|
298 | 305 | # Von: Alex Martelli <aleaxit@yahoo.com> |
|
299 | 306 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends |
|
300 | 307 | # Gruppen: comp.lang.python |
|
301 | 308 | # Referenzen: 1 |
|
302 | 309 | |
|
303 | 310 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: |
|
304 | 311 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) |
|
305 | 312 | # > <type 'dict'> |
|
306 | 313 | # > >>> print type(__builtins__) |
|
307 | 314 | # > <type 'module'> |
|
308 | 315 | # > Is this difference in return value intentional? |
|
309 | 316 | |
|
310 | 317 | # Well, it's documented that '__builtins__' can be either a dictionary |
|
311 | 318 | # or a module, and it's been that way for a long time. Whether it's |
|
312 | 319 | # intentional (or sensible), I don't know. In any case, the idea is |
|
313 | 320 | # that if you need to access the built-in namespace directly, you |
|
314 | 321 | # should start with "import __builtin__" (note, no 's') which will |
|
315 | 322 | # definitely give you a module. Yeah, it's somewhatΒ confusing:-(. |
|
316 | 323 | |
|
317 | 324 | if user_ns is None: |
|
318 | 325 | # Set __name__ to __main__ to better match the behavior of the |
|
319 | 326 | # normal interpreter. |
|
320 | 327 | user_ns = {'__name__' :'__main__', |
|
321 | 328 | '__builtins__' : __builtin__, |
|
322 | 329 | } |
|
323 | 330 | |
|
324 | 331 | if user_global_ns is None: |
|
325 | 332 | user_global_ns = {} |
|
326 | 333 | |
|
327 | 334 | # Assign namespaces |
|
328 | 335 | # This is the namespace where all normal user variables live |
|
329 | 336 | self.user_ns = user_ns |
|
330 | 337 | # Embedded instances require a separate namespace for globals. |
|
331 | 338 | # Normally this one is unused by non-embedded instances. |
|
332 | 339 | self.user_global_ns = user_global_ns |
|
333 | 340 | # A namespace to keep track of internal data structures to prevent |
|
334 | 341 | # them from cluttering user-visible stuff. Will be updated later |
|
335 | 342 | self.internal_ns = {} |
|
336 | 343 | |
|
337 | 344 | # Namespace of system aliases. Each entry in the alias |
|
338 | 345 | # table must be a 2-tuple of the form (N,name), where N is the number |
|
339 | 346 | # of positional arguments of the alias. |
|
340 | 347 | self.alias_table = {} |
|
341 | 348 | |
|
342 | 349 | # A table holding all the namespaces IPython deals with, so that |
|
343 | 350 | # introspection facilities can search easily. |
|
344 | 351 | self.ns_table = {'user':user_ns, |
|
345 | 352 | 'user_global':user_global_ns, |
|
346 | 353 | 'alias':self.alias_table, |
|
347 | 354 | 'internal':self.internal_ns, |
|
348 | 355 | 'builtin':__builtin__.__dict__ |
|
349 | 356 | } |
|
350 | 357 | |
|
351 | 358 | # The user namespace MUST have a pointer to the shell itself. |
|
352 | 359 | self.user_ns[name] = self |
|
353 | 360 | |
|
354 | 361 | # We need to insert into sys.modules something that looks like a |
|
355 | 362 | # module but which accesses the IPython namespace, for shelve and |
|
356 | 363 | # pickle to work interactively. Normally they rely on getting |
|
357 | 364 | # everything out of __main__, but for embedding purposes each IPython |
|
358 | 365 | # instance has its own private namespace, so we can't go shoving |
|
359 | 366 | # everything into __main__. |
|
360 | 367 | |
|
361 | 368 | # note, however, that we should only do this for non-embedded |
|
362 | 369 | # ipythons, which really mimic the __main__.__dict__ with their own |
|
363 | 370 | # namespace. Embedded instances, on the other hand, should not do |
|
364 | 371 | # this because they need to manage the user local/global namespaces |
|
365 | 372 | # only, but they live within a 'normal' __main__ (meaning, they |
|
366 | 373 | # shouldn't overtake the execution environment of the script they're |
|
367 | 374 | # embedded in). |
|
368 | 375 | |
|
369 | 376 | if not embedded: |
|
370 | 377 | try: |
|
371 | 378 | main_name = self.user_ns['__name__'] |
|
372 | 379 | except KeyError: |
|
373 | 380 | raise KeyError,'user_ns dictionary MUST have a "__name__" key' |
|
374 | 381 | else: |
|
375 | 382 | #print "pickle hack in place" # dbg |
|
376 | 383 | sys.modules[main_name] = FakeModule(self.user_ns) |
|
377 | 384 | |
|
378 | 385 | # List of input with multi-line handling. |
|
379 | 386 | # Fill its zero entry, user counter starts at 1 |
|
380 | 387 | self.input_hist = InputList(['\n']) |
|
381 | 388 | |
|
382 | 389 | # list of visited directories |
|
383 | 390 | try: |
|
384 | 391 | self.dir_hist = [os.getcwd()] |
|
385 | 392 | except IOError, e: |
|
386 | 393 | self.dir_hist = [] |
|
387 | 394 | |
|
388 | 395 | # dict of output history |
|
389 | 396 | self.output_hist = {} |
|
390 | 397 | |
|
391 | 398 | # dict of things NOT to alias (keywords, builtins and some magics) |
|
392 | 399 | no_alias = {} |
|
393 | 400 | no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias'] |
|
394 | 401 | for key in keyword.kwlist + no_alias_magics: |
|
395 | 402 | no_alias[key] = 1 |
|
396 | 403 | no_alias.update(__builtin__.__dict__) |
|
397 | 404 | self.no_alias = no_alias |
|
398 | 405 | |
|
399 | 406 | # make global variables for user access to these |
|
400 | 407 | self.user_ns['_ih'] = self.input_hist |
|
401 | 408 | self.user_ns['_oh'] = self.output_hist |
|
402 | 409 | self.user_ns['_dh'] = self.dir_hist |
|
403 | 410 | |
|
404 | 411 | # user aliases to input and output histories |
|
405 | 412 | self.user_ns['In'] = self.input_hist |
|
406 | 413 | self.user_ns['Out'] = self.output_hist |
|
407 | 414 | |
|
408 | # Store the actual shell's name | |
|
409 | self.name = name | |
|
410 | ||
|
411 | 415 | # Object variable to store code object waiting execution. This is |
|
412 | 416 | # used mainly by the multithreaded shells, but it can come in handy in |
|
413 | 417 | # other situations. No need to use a Queue here, since it's a single |
|
414 | 418 | # item which gets cleared once run. |
|
415 | 419 | self.code_to_run = None |
|
416 | 420 | |
|
417 | 421 | # Job manager (for jobs run as background threads) |
|
418 | 422 | self.jobs = BackgroundJobManager() |
|
419 | 423 | # Put the job manager into builtins so it's always there. |
|
420 | 424 | __builtin__.jobs = self.jobs |
|
421 | 425 | |
|
422 | 426 | # escapes for automatic behavior on the command line |
|
423 | 427 | self.ESC_SHELL = '!' |
|
424 | 428 | self.ESC_HELP = '?' |
|
425 | 429 | self.ESC_MAGIC = '%' |
|
426 | 430 | self.ESC_QUOTE = ',' |
|
427 | 431 | self.ESC_QUOTE2 = ';' |
|
428 | 432 | self.ESC_PAREN = '/' |
|
429 | 433 | |
|
430 | 434 | # And their associated handlers |
|
431 | 435 | self.esc_handlers = {self.ESC_PAREN:self.handle_auto, |
|
432 | 436 | self.ESC_QUOTE:self.handle_auto, |
|
433 | 437 | self.ESC_QUOTE2:self.handle_auto, |
|
434 | 438 | self.ESC_MAGIC:self.handle_magic, |
|
435 | 439 | self.ESC_HELP:self.handle_help, |
|
436 | 440 | self.ESC_SHELL:self.handle_shell_escape, |
|
437 | 441 | } |
|
438 | 442 | |
|
439 | 443 | # class initializations |
|
440 | 444 | Logger.__init__(self,log_ns = self.user_ns) |
|
441 | 445 | Magic.__init__(self,self) |
|
442 | 446 | |
|
443 | 447 | # an ugly hack to get a pointer to the shell, so I can start writing |
|
444 | 448 | # magic code via this pointer instead of the current mixin salad. |
|
445 | 449 | Magic.set_shell(self,self) |
|
446 | 450 | |
|
447 | 451 | # Python source parser/formatter for syntax highlighting |
|
448 | 452 | pyformat = PyColorize.Parser().format |
|
449 | 453 | self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors']) |
|
450 | 454 | |
|
451 | 455 | # hooks holds pointers used for user-side customizations |
|
452 | 456 | self.hooks = Struct() |
|
453 | 457 | |
|
454 | 458 | # Set all default hooks, defined in the IPython.hooks module. |
|
455 | 459 | hooks = IPython.hooks |
|
456 | 460 | for hook_name in hooks.__all__: |
|
457 | 461 | self.set_hook(hook_name,getattr(hooks,hook_name)) |
|
458 | 462 | |
|
459 | 463 | # Flag to mark unconditional exit |
|
460 | 464 | self.exit_now = False |
|
461 | 465 | |
|
462 | 466 | self.usage_min = """\ |
|
463 | 467 | An enhanced console for Python. |
|
464 | 468 | Some of its features are: |
|
465 | 469 | - Readline support if the readline library is present. |
|
466 | 470 | - Tab completion in the local namespace. |
|
467 | 471 | - Logging of input, see command-line options. |
|
468 | 472 | - System shell escape via ! , eg !ls. |
|
469 | 473 | - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.) |
|
470 | 474 | - Keeps track of locally defined variables via %who, %whos. |
|
471 | 475 | - Show object information with a ? eg ?x or x? (use ?? for more info). |
|
472 | 476 | """ |
|
473 | 477 | if usage: self.usage = usage |
|
474 | 478 | else: self.usage = self.usage_min |
|
475 | 479 | |
|
476 | 480 | # Storage |
|
477 | 481 | self.rc = rc # This will hold all configuration information |
|
478 | 482 | self.inputcache = [] |
|
479 | 483 | self._boundcache = [] |
|
480 | 484 | self.pager = 'less' |
|
481 | 485 | # temporary files used for various purposes. Deleted at exit. |
|
482 | 486 | self.tempfiles = [] |
|
483 | 487 | |
|
484 | 488 | # Keep track of readline usage (later set by init_readline) |
|
485 | 489 | self.has_readline = False |
|
486 | 490 | |
|
487 | 491 | # for pushd/popd management |
|
488 | 492 | try: |
|
489 | 493 | self.home_dir = get_home_dir() |
|
490 | 494 | except HomeDirError,msg: |
|
491 | 495 | fatal(msg) |
|
492 | 496 | |
|
493 | 497 | self.dir_stack = [os.getcwd().replace(self.home_dir,'~')] |
|
494 | 498 | |
|
495 | 499 | # Functions to call the underlying shell. |
|
496 | 500 | |
|
497 | 501 | # utility to expand user variables via Itpl |
|
498 | 502 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), |
|
499 | 503 | self.user_ns)) |
|
500 | 504 | # The first is similar to os.system, but it doesn't return a value, |
|
501 | 505 | # and it allows interpolation of variables in the user's namespace. |
|
502 | 506 | self.system = lambda cmd: shell(self.var_expand(cmd), |
|
503 | 507 | header='IPython system call: ', |
|
504 | 508 | verbose=self.rc.system_verbose) |
|
505 | 509 | # These are for getoutput and getoutputerror: |
|
506 | 510 | self.getoutput = lambda cmd: \ |
|
507 | 511 | getoutput(self.var_expand(cmd), |
|
508 | 512 | header='IPython system call: ', |
|
509 | 513 | verbose=self.rc.system_verbose) |
|
510 | 514 | self.getoutputerror = lambda cmd: \ |
|
511 | 515 | getoutputerror(str(ItplNS(cmd.replace('#','\#'), |
|
512 | 516 | self.user_ns)), |
|
513 | 517 | header='IPython system call: ', |
|
514 | 518 | verbose=self.rc.system_verbose) |
|
515 | 519 | |
|
516 | 520 | # RegExp for splitting line contents into pre-char//first |
|
517 | 521 | # word-method//rest. For clarity, each group in on one line. |
|
518 | 522 | |
|
519 | 523 | # WARNING: update the regexp if the above escapes are changed, as they |
|
520 | 524 | # are hardwired in. |
|
521 | 525 | |
|
522 | 526 | # Don't get carried away with trying to make the autocalling catch too |
|
523 | 527 | # much: it's better to be conservative rather than to trigger hidden |
|
524 | 528 | # evals() somewhere and end up causing side effects. |
|
525 | 529 | |
|
526 | 530 | self.line_split = re.compile(r'^([\s*,;/])' |
|
527 | 531 | r'([\?\w\.]+\w*\s*)' |
|
528 | 532 | r'(\(?.*$)') |
|
529 | 533 | |
|
530 | 534 | # Original re, keep around for a while in case changes break something |
|
531 | 535 | #self.line_split = re.compile(r'(^[\s*!\?%,/]?)' |
|
532 | 536 | # r'(\s*[\?\w\.]+\w*\s*)' |
|
533 | 537 | # r'(\(?.*$)') |
|
534 | 538 | |
|
535 | 539 | # RegExp to identify potential function names |
|
536 | 540 | self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') |
|
537 | 541 | # RegExp to exclude strings with this start from autocalling |
|
538 | 542 | self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ') |
|
539 | 543 | |
|
540 | 544 | # try to catch also methods for stuff in lists/tuples/dicts: off |
|
541 | 545 | # (experimental). For this to work, the line_split regexp would need |
|
542 | 546 | # to be modified so it wouldn't break things at '['. That line is |
|
543 | 547 | # nasty enough that I shouldn't change it until I can test it _well_. |
|
544 | 548 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') |
|
545 | 549 | |
|
546 | 550 | # keep track of where we started running (mainly for crash post-mortem) |
|
547 | 551 | self.starting_dir = os.getcwd() |
|
548 | 552 | |
|
549 | 553 | # Attributes for Logger mixin class, make defaults here |
|
550 | 554 | self._dolog = False |
|
551 | 555 | self.LOG = '' |
|
552 | 556 | self.LOGDEF = '.InteractiveShell.log' |
|
553 | 557 | self.LOGMODE = 'over' |
|
554 | 558 | self.LOGHEAD = Itpl( |
|
555 | 559 | """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE *** |
|
556 | 560 | #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW |
|
557 | 561 | #log# opts = $self.rc.opts |
|
558 | 562 | #log# args = $self.rc.args |
|
559 | 563 | #log# It is safe to make manual edits below here. |
|
560 | 564 | #log#----------------------------------------------------------------------- |
|
561 | 565 | """) |
|
562 | 566 | # Various switches which can be set |
|
563 | 567 | self.CACHELENGTH = 5000 # this is cheap, it's just text |
|
564 | 568 | self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__ |
|
565 | 569 | self.banner2 = banner2 |
|
566 | 570 | |
|
567 | 571 | # TraceBack handlers: |
|
568 | # Need two, one for syntax errors and one for other exceptions. | |
|
572 | ||
|
573 | # Syntax error handler. | |
|
569 | 574 | self.SyntaxTB = SyntaxTB(color_scheme='NoColor') |
|
575 | ||
|
570 | 576 | # The interactive one is initialized with an offset, meaning we always |
|
571 | 577 | # want to remove the topmost item in the traceback, which is our own |
|
572 | 578 | # internal code. Valid modes: ['Plain','Context','Verbose'] |
|
573 | 579 | self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain', |
|
574 | 580 | color_scheme='NoColor', |
|
575 | 581 | tb_offset = 1) |
|
582 | ||
|
583 | # IPython itself shouldn't crash. This will produce a detailed | |
|
584 | # post-mortem if it does. But we only install the crash handler for | |
|
585 | # non-threaded shells, the threaded ones use a normal verbose reporter | |
|
586 | # and lose the crash handler. This is because exceptions in the main | |
|
587 | # thread (such as in GUI code) propagate directly to sys.excepthook, | |
|
588 | # and there's no point in printing crash dumps for every user exception. | |
|
589 | if self.isthreaded: | |
|
590 | sys.excepthook = ultraTB.FormattedTB() | |
|
591 | else: | |
|
592 | from IPython import CrashHandler | |
|
593 | sys.excepthook = CrashHandler.CrashHandler(self) | |
|
594 | ||
|
595 | # The instance will store a pointer to this, so that runtime code | |
|
596 | # (such as magics) can access it. This is because during the | |
|
597 | # read-eval loop, it gets temporarily overwritten (to deal with GUI | |
|
598 | # frameworks). | |
|
599 | self.sys_excepthook = sys.excepthook | |
|
600 | ||
|
576 | 601 | # and add any custom exception handlers the user may have specified |
|
577 | 602 | self.set_custom_exc(*custom_exceptions) |
|
578 | 603 | |
|
579 | 604 | # Object inspector |
|
580 | 605 | self.inspector = OInspect.Inspector(OInspect.InspectColors, |
|
581 | 606 | PyColorize.ANSICodeColors, |
|
582 | 607 | 'NoColor') |
|
583 | 608 | # indentation management |
|
584 | 609 | self.autoindent = False |
|
585 | 610 | self.indent_current_nsp = 0 |
|
586 | 611 | self.indent_current = '' # actual indent string |
|
587 | 612 | |
|
588 | 613 | # Make some aliases automatically |
|
589 | 614 | # Prepare list of shell aliases to auto-define |
|
590 | 615 | if os.name == 'posix': |
|
591 | 616 | auto_alias = ('mkdir mkdir', 'rmdir rmdir', |
|
592 | 617 | 'mv mv -i','rm rm -i','cp cp -i', |
|
593 | 618 | 'cat cat','less less','clear clear', |
|
594 | 619 | # a better ls |
|
595 | 620 | 'ls ls -F', |
|
596 | 621 | # long ls |
|
597 | 622 | 'll ls -lF', |
|
598 | 623 | # color ls |
|
599 | 624 | 'lc ls -F -o --color', |
|
600 | 625 | # ls normal files only |
|
601 | 626 | 'lf ls -F -o --color %l | grep ^-', |
|
602 | 627 | # ls symbolic links |
|
603 | 628 | 'lk ls -F -o --color %l | grep ^l', |
|
604 | 629 | # directories or links to directories, |
|
605 | 630 | 'ldir ls -F -o --color %l | grep /$', |
|
606 | 631 | # things which are executable |
|
607 | 632 | 'lx ls -F -o --color %l | grep ^-..x', |
|
608 | 633 | ) |
|
609 | 634 | elif os.name in ['nt','dos']: |
|
610 | 635 | auto_alias = ('dir dir /on', 'ls dir /on', |
|
611 | 636 | 'ddir dir /ad /on', 'ldir dir /ad /on', |
|
612 | 637 | 'mkdir mkdir','rmdir rmdir','echo echo', |
|
613 | 638 | 'ren ren','cls cls','copy copy') |
|
614 | 639 | else: |
|
615 | 640 | auto_alias = () |
|
616 | 641 | self.auto_alias = map(lambda s:s.split(None,1),auto_alias) |
|
617 | 642 | # Call the actual (public) initializer |
|
618 | 643 | self.init_auto_alias() |
|
619 | 644 | # end __init__ |
|
620 | 645 | |
|
646 | def post_config_initialization(self): | |
|
647 | """Post configuration init method | |
|
648 | ||
|
649 | This is called after the configuration files have been processed to | |
|
650 | 'finalize' the initialization.""" | |
|
651 | ||
|
652 | rc = self.rc | |
|
653 | ||
|
654 | # Load readline proper | |
|
655 | if rc.readline: | |
|
656 | self.init_readline() | |
|
657 | ||
|
658 | # Set user colors (don't do it in the constructor above so that it | |
|
659 | # doesn't crash if colors option is invalid) | |
|
660 | self.magic_colors(rc.colors) | |
|
661 | ||
|
662 | # Load user aliases | |
|
663 | for alias in rc.alias: | |
|
664 | self.magic_alias(alias) | |
|
665 | ||
|
666 | # dynamic data that survives through sessions | |
|
667 | # XXX make the filename a config option? | |
|
668 | persist_base = 'persist' | |
|
669 | if rc.profile: | |
|
670 | persist_base += '_%s' % rc.profile | |
|
671 | self.persist_fname = os.path.join(rc.ipythondir,persist_base) | |
|
672 | ||
|
673 | try: | |
|
674 | self.persist = pickle.load(file(self.persist_fname)) | |
|
675 | except: | |
|
676 | self.persist = {} | |
|
677 | ||
|
621 | 678 | def set_hook(self,name,hook): |
|
622 | 679 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
623 | 680 | |
|
624 | 681 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
625 | 682 | resetting one of these hooks, you can modify IPython's behavior to |
|
626 | 683 | call at runtime your own routines.""" |
|
627 | 684 | |
|
628 | 685 | # At some point in the future, this should validate the hook before it |
|
629 | 686 | # accepts it. Probably at least check that the hook takes the number |
|
630 | 687 | # of args it's supposed to. |
|
631 | 688 | setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__)) |
|
632 | 689 | |
|
633 | 690 | def set_custom_exc(self,exc_tuple,handler): |
|
634 | 691 | """set_custom_exc(exc_tuple,handler) |
|
635 | 692 | |
|
636 | 693 | Set a custom exception handler, which will be called if any of the |
|
637 | 694 | exceptions in exc_tuple occur in the mainloop (specifically, in the |
|
638 | 695 | runcode() method. |
|
639 | 696 | |
|
640 | 697 | Inputs: |
|
641 | 698 | |
|
642 | 699 | - exc_tuple: a *tuple* of valid exceptions to call the defined |
|
643 | 700 | handler for. It is very important that you use a tuple, and NOT A |
|
644 | 701 | LIST here, because of the way Python's except statement works. If |
|
645 | 702 | you only want to trap a single exception, use a singleton tuple: |
|
646 | 703 | |
|
647 | 704 | exc_tuple == (MyCustomException,) |
|
648 | 705 | |
|
649 | 706 | - handler: this must be defined as a function with the following |
|
650 | 707 | basic interface: def my_handler(self,etype,value,tb). |
|
651 | 708 | |
|
652 | 709 | This will be made into an instance method (via new.instancemethod) |
|
653 | 710 | of IPython itself, and it will be called if any of the exceptions |
|
654 | 711 | listed in the exc_tuple are caught. If the handler is None, an |
|
655 | 712 | internal basic one is used, which just prints basic info. |
|
656 | 713 | |
|
657 | 714 | WARNING: by putting in your own exception handler into IPython's main |
|
658 | 715 | execution loop, you run a very good chance of nasty crashes. This |
|
659 | 716 | facility should only be used if you really know what you are doing.""" |
|
660 | 717 | |
|
661 | 718 | assert type(exc_tuple)==type(()) , \ |
|
662 | 719 | "The custom exceptions must be given AS A TUPLE." |
|
663 | 720 | |
|
664 | 721 | def dummy_handler(self,etype,value,tb): |
|
665 | 722 | print '*** Simple custom exception handler ***' |
|
666 | 723 | print 'Exception type :',etype |
|
667 | 724 | print 'Exception value:',value |
|
668 | 725 | print 'Traceback :',tb |
|
669 | 726 | print 'Source code :','\n'.join(self.buffer) |
|
670 | 727 | |
|
671 | 728 | if handler is None: handler = dummy_handler |
|
672 | 729 | |
|
673 | 730 | self.CustomTB = new.instancemethod(handler,self,self.__class__) |
|
674 | 731 | self.custom_exceptions = exc_tuple |
|
675 | 732 | |
|
676 | 733 | def set_custom_completer(self,completer,pos=0): |
|
677 | 734 | """set_custom_completer(completer,pos=0) |
|
678 | 735 | |
|
679 | 736 | Adds a new custom completer function. |
|
680 | 737 | |
|
681 | 738 | The position argument (defaults to 0) is the index in the completers |
|
682 | 739 | list where you want the completer to be inserted.""" |
|
683 | 740 | |
|
684 | 741 | newcomp = new.instancemethod(completer,self.Completer, |
|
685 | 742 | self.Completer.__class__) |
|
686 | 743 | self.Completer.matchers.insert(pos,newcomp) |
|
687 | 744 | |
|
688 | 745 | def complete(self,text): |
|
689 | 746 | """Return a sorted list of all possible completions on text. |
|
690 | 747 | |
|
691 | 748 | Inputs: |
|
692 | 749 | |
|
693 | 750 | - text: a string of text to be completed on. |
|
694 | 751 | |
|
695 | 752 | This is a wrapper around the completion mechanism, similar to what |
|
696 | 753 | readline does at the command line when the TAB key is hit. By |
|
697 | 754 | exposing it as a method, it can be used by other non-readline |
|
698 | 755 | environments (such as GUIs) for text completion. |
|
699 | 756 | |
|
700 | 757 | Simple usage example: |
|
701 | 758 | |
|
702 | 759 | In [1]: x = 'hello' |
|
703 | 760 | |
|
704 | 761 | In [2]: __IP.complete('x.l') |
|
705 | 762 | Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']""" |
|
706 | 763 | |
|
707 | 764 | complete = self.Completer.complete |
|
708 | 765 | state = 0 |
|
709 | 766 | # use a dict so we get unique keys, since ipyhton's multiple |
|
710 | 767 | # completers can return duplicates. |
|
711 | 768 | comps = {} |
|
712 | 769 | while True: |
|
713 | 770 | newcomp = complete(text,state) |
|
714 | 771 | if newcomp is None: |
|
715 | 772 | break |
|
716 | 773 | comps[newcomp] = 1 |
|
717 | 774 | state += 1 |
|
718 | 775 | outcomps = comps.keys() |
|
719 | 776 | outcomps.sort() |
|
720 | 777 | return outcomps |
|
721 | 778 | |
|
722 | 779 | def set_completer_frame(self, frame): |
|
723 | 780 | if frame: |
|
724 | 781 | self.Completer.namespace = frame.f_locals |
|
725 | 782 | self.Completer.global_namespace = frame.f_globals |
|
726 | 783 | else: |
|
727 | 784 | self.Completer.namespace = self.user_ns |
|
728 | 785 | self.Completer.global_namespace = self.user_global_ns |
|
729 | 786 | |
|
730 | def post_config_initialization(self): | |
|
731 | """Post configuration init method | |
|
732 | ||
|
733 | This is called after the configuration files have been processed to | |
|
734 | 'finalize' the initialization.""" | |
|
735 | ||
|
736 | rc = self.rc | |
|
737 | ||
|
738 | # Load readline proper | |
|
739 | if rc.readline: | |
|
740 | self.init_readline() | |
|
741 | ||
|
742 | # Set user colors (don't do it in the constructor above so that it | |
|
743 | # doesn't crash if colors option is invalid) | |
|
744 | self.magic_colors(rc.colors) | |
|
745 | ||
|
746 | # Load user aliases | |
|
747 | for alias in rc.alias: | |
|
748 | self.magic_alias(alias) | |
|
749 | ||
|
750 | # dynamic data that survives through sessions | |
|
751 | # XXX make the filename a config option? | |
|
752 | persist_base = 'persist' | |
|
753 | if rc.profile: | |
|
754 | persist_base += '_%s' % rc.profile | |
|
755 | self.persist_fname = os.path.join(rc.ipythondir,persist_base) | |
|
756 | ||
|
757 | try: | |
|
758 | self.persist = pickle.load(file(self.persist_fname)) | |
|
759 | except: | |
|
760 | self.persist = {} | |
|
761 | ||
|
762 | 787 | def init_auto_alias(self): |
|
763 | 788 | """Define some aliases automatically. |
|
764 | 789 | |
|
765 | 790 | These are ALL parameter-less aliases""" |
|
766 | 791 | for alias,cmd in self.auto_alias: |
|
767 | 792 | self.alias_table[alias] = (0,cmd) |
|
768 | 793 | |
|
769 | 794 | def alias_table_validate(self,verbose=0): |
|
770 | 795 | """Update information about the alias table. |
|
771 | 796 | |
|
772 | 797 | In particular, make sure no Python keywords/builtins are in it.""" |
|
773 | 798 | |
|
774 | 799 | no_alias = self.no_alias |
|
775 | 800 | for k in self.alias_table.keys(): |
|
776 | 801 | if k in no_alias: |
|
777 | 802 | del self.alias_table[k] |
|
778 | 803 | if verbose: |
|
779 | 804 | print ("Deleting alias <%s>, it's a Python " |
|
780 | 805 | "keyword or builtin." % k) |
|
781 | 806 | |
|
782 | 807 | def set_autoindent(self,value=None): |
|
783 | 808 | """Set the autoindent flag, checking for readline support. |
|
784 | 809 | |
|
785 | 810 | If called with no arguments, it acts as a toggle.""" |
|
786 | 811 | |
|
787 | 812 | if not self.has_readline: |
|
788 | 813 | if os.name == 'posix': |
|
789 | 814 | warn("The auto-indent feature requires the readline library") |
|
790 | 815 | self.autoindent = 0 |
|
791 | 816 | return |
|
792 | 817 | if value is None: |
|
793 | 818 | self.autoindent = not self.autoindent |
|
794 | 819 | else: |
|
795 | 820 | self.autoindent = value |
|
796 | 821 | |
|
797 | 822 | def rc_set_toggle(self,rc_field,value=None): |
|
798 | 823 | """Set or toggle a field in IPython's rc config. structure. |
|
799 | 824 | |
|
800 | 825 | If called with no arguments, it acts as a toggle. |
|
801 | 826 | |
|
802 | 827 | If called with a non-existent field, the resulting AttributeError |
|
803 | 828 | exception will propagate out.""" |
|
804 | 829 | |
|
805 | 830 | rc_val = getattr(self.rc,rc_field) |
|
806 | 831 | if value is None: |
|
807 | 832 | value = not rc_val |
|
808 | 833 | setattr(self.rc,rc_field,value) |
|
809 | 834 | |
|
810 | 835 | def user_setup(self,ipythondir,rc_suffix,mode='install'): |
|
811 | 836 | """Install the user configuration directory. |
|
812 | 837 | |
|
813 | 838 | Can be called when running for the first time or to upgrade the user's |
|
814 | 839 | .ipython/ directory with the mode parameter. Valid modes are 'install' |
|
815 | 840 | and 'upgrade'.""" |
|
816 | 841 | |
|
817 | 842 | def wait(): |
|
818 | 843 | try: |
|
819 | 844 | raw_input("Please press <RETURN> to start IPython.") |
|
820 | 845 | except EOFError: |
|
821 | 846 | print >> Term.cout |
|
822 | 847 | print '*'*70 |
|
823 | 848 | |
|
824 | 849 | cwd = os.getcwd() # remember where we started |
|
825 | 850 | glb = glob.glob |
|
826 | 851 | print '*'*70 |
|
827 | 852 | if mode == 'install': |
|
828 | 853 | print \ |
|
829 | 854 | """Welcome to IPython. I will try to create a personal configuration directory |
|
830 | 855 | where you can customize many aspects of IPython's functionality in:\n""" |
|
831 | 856 | else: |
|
832 | 857 | print 'I am going to upgrade your configuration in:' |
|
833 | 858 | |
|
834 | 859 | print ipythondir |
|
835 | 860 | |
|
836 | 861 | rcdirend = os.path.join('IPython','UserConfig') |
|
837 | 862 | cfg = lambda d: os.path.join(d,rcdirend) |
|
838 | 863 | try: |
|
839 | 864 | rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] |
|
840 | 865 | except IOError: |
|
841 | 866 | warning = """ |
|
842 | 867 | Installation error. IPython's directory was not found. |
|
843 | 868 | |
|
844 | 869 | Check the following: |
|
845 | 870 | |
|
846 | 871 | The ipython/IPython directory should be in a directory belonging to your |
|
847 | 872 | PYTHONPATH environment variable (that is, it should be in a directory |
|
848 | 873 | belonging to sys.path). You can copy it explicitly there or just link to it. |
|
849 | 874 | |
|
850 | 875 | IPython will proceed with builtin defaults. |
|
851 | 876 | """ |
|
852 | 877 | warn(warning) |
|
853 | 878 | wait() |
|
854 | 879 | return |
|
855 | 880 | |
|
856 | 881 | if mode == 'install': |
|
857 | 882 | try: |
|
858 | 883 | shutil.copytree(rcdir,ipythondir) |
|
859 | 884 | os.chdir(ipythondir) |
|
860 | 885 | rc_files = glb("ipythonrc*") |
|
861 | 886 | for rc_file in rc_files: |
|
862 | 887 | os.rename(rc_file,rc_file+rc_suffix) |
|
863 | 888 | except: |
|
864 | 889 | warning = """ |
|
865 | 890 | |
|
866 | 891 | There was a problem with the installation: |
|
867 | 892 | %s |
|
868 | 893 | Try to correct it or contact the developers if you think it's a bug. |
|
869 | 894 | IPython will proceed with builtin defaults.""" % sys.exc_info()[1] |
|
870 | 895 | warn(warning) |
|
871 | 896 | wait() |
|
872 | 897 | return |
|
873 | 898 | |
|
874 | 899 | elif mode == 'upgrade': |
|
875 | 900 | try: |
|
876 | 901 | os.chdir(ipythondir) |
|
877 | 902 | except: |
|
878 | 903 | print """ |
|
879 | 904 | Can not upgrade: changing to directory %s failed. Details: |
|
880 | 905 | %s |
|
881 | 906 | """ % (ipythondir,sys.exc_info()[1]) |
|
882 | 907 | wait() |
|
883 | 908 | return |
|
884 | 909 | else: |
|
885 | 910 | sources = glb(os.path.join(rcdir,'[A-Za-z]*')) |
|
886 | 911 | for new_full_path in sources: |
|
887 | 912 | new_filename = os.path.basename(new_full_path) |
|
888 | 913 | if new_filename.startswith('ipythonrc'): |
|
889 | 914 | new_filename = new_filename + rc_suffix |
|
890 | 915 | # The config directory should only contain files, skip any |
|
891 | 916 | # directories which may be there (like CVS) |
|
892 | 917 | if os.path.isdir(new_full_path): |
|
893 | 918 | continue |
|
894 | 919 | if os.path.exists(new_filename): |
|
895 | 920 | old_file = new_filename+'.old' |
|
896 | 921 | if os.path.exists(old_file): |
|
897 | 922 | os.remove(old_file) |
|
898 | 923 | os.rename(new_filename,old_file) |
|
899 | 924 | shutil.copy(new_full_path,new_filename) |
|
900 | 925 | else: |
|
901 | 926 | raise ValueError,'unrecognized mode for install:',`mode` |
|
902 | 927 | |
|
903 | 928 | # Fix line-endings to those native to each platform in the config |
|
904 | 929 | # directory. |
|
905 | 930 | try: |
|
906 | 931 | os.chdir(ipythondir) |
|
907 | 932 | except: |
|
908 | 933 | print """ |
|
909 | 934 | Problem: changing to directory %s failed. |
|
910 | 935 | Details: |
|
911 | 936 | %s |
|
912 | 937 | |
|
913 | 938 | Some configuration files may have incorrect line endings. This should not |
|
914 | 939 | cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) |
|
915 | 940 | wait() |
|
916 | 941 | else: |
|
917 | 942 | for fname in glb('ipythonrc*'): |
|
918 | 943 | try: |
|
919 | 944 | native_line_ends(fname,backup=0) |
|
920 | 945 | except IOError: |
|
921 | 946 | pass |
|
922 | 947 | |
|
923 | 948 | if mode == 'install': |
|
924 | 949 | print """ |
|
925 | 950 | Successful installation! |
|
926 | 951 | |
|
927 | 952 | Please read the sections 'Initial Configuration' and 'Quick Tips' in the |
|
928 | 953 | IPython manual (there are both HTML and PDF versions supplied with the |
|
929 | 954 | distribution) to make sure that your system environment is properly configured |
|
930 | 955 | to take advantage of IPython's features.""" |
|
931 | 956 | else: |
|
932 | 957 | print """ |
|
933 | 958 | Successful upgrade! |
|
934 | 959 | |
|
935 | 960 | All files in your directory: |
|
936 | 961 | %(ipythondir)s |
|
937 | 962 | which would have been overwritten by the upgrade were backed up with a .old |
|
938 | 963 | extension. If you had made particular customizations in those files you may |
|
939 | 964 | want to merge them back into the new files.""" % locals() |
|
940 | 965 | wait() |
|
941 | 966 | os.chdir(cwd) |
|
942 | 967 | # end user_setup() |
|
943 | 968 | |
|
944 | 969 | def atexit_operations(self): |
|
945 | 970 | """This will be executed at the time of exit. |
|
946 | 971 | |
|
947 | 972 | Saving of persistent data should be performed here. """ |
|
948 | 973 | |
|
949 | 974 | # input history |
|
950 | 975 | self.savehist() |
|
951 | 976 | |
|
952 | 977 | # Cleanup all tempfiles left around |
|
953 | 978 | for tfile in self.tempfiles: |
|
954 | 979 | try: |
|
955 | 980 | os.unlink(tfile) |
|
956 | 981 | except OSError: |
|
957 | 982 | pass |
|
958 | 983 | |
|
959 | 984 | # save the "persistent data" catch-all dictionary |
|
960 | 985 | try: |
|
961 | 986 | pickle.dump(self.persist, open(self.persist_fname,"w")) |
|
962 | 987 | except: |
|
963 | 988 | print "*** ERROR *** persistent data saving failed." |
|
964 | 989 | |
|
965 | 990 | def savehist(self): |
|
966 | 991 | """Save input history to a file (via readline library).""" |
|
967 | 992 | try: |
|
968 | 993 | self.readline.write_history_file(self.histfile) |
|
969 | 994 | except: |
|
970 | 995 | print 'Unable to save IPython command history to file: ' + \ |
|
971 | 996 | `self.histfile` |
|
972 | 997 | |
|
973 | 998 | def pre_readline(self): |
|
974 | 999 | """readline hook to be used at the start of each line. |
|
975 | 1000 | |
|
976 | 1001 | Currently it handles auto-indent only.""" |
|
977 | 1002 | |
|
978 | 1003 | self.readline.insert_text(self.indent_current) |
|
979 | 1004 | |
|
980 | 1005 | def init_readline(self): |
|
981 | 1006 | """Command history completion/saving/reloading.""" |
|
982 | 1007 | try: |
|
983 | 1008 | import readline |
|
984 | 1009 | except ImportError: |
|
985 | 1010 | self.has_readline = 0 |
|
986 | 1011 | self.readline = None |
|
987 | 1012 | # no point in bugging windows users with this every time: |
|
988 | 1013 | if os.name == 'posix': |
|
989 | 1014 | warn('Readline services not available on this platform.') |
|
990 | 1015 | else: |
|
991 | 1016 | import atexit |
|
992 | 1017 | from IPython.completer import IPCompleter |
|
993 | 1018 | self.Completer = IPCompleter(self, |
|
994 | 1019 | self.user_ns, |
|
995 | 1020 | self.user_global_ns, |
|
996 | 1021 | self.rc.readline_omit__names, |
|
997 | 1022 | self.alias_table) |
|
998 | 1023 | |
|
999 | 1024 | # Platform-specific configuration |
|
1000 | 1025 | if os.name == 'nt': |
|
1001 | 1026 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1002 | 1027 | else: |
|
1003 | 1028 | self.readline_startup_hook = readline.set_startup_hook |
|
1004 | 1029 | |
|
1005 | 1030 | # Load user's initrc file (readline config) |
|
1006 | 1031 | inputrc_name = os.environ.get('INPUTRC') |
|
1007 | 1032 | if inputrc_name is None: |
|
1008 | 1033 | home_dir = get_home_dir() |
|
1009 | 1034 | if home_dir is not None: |
|
1010 | 1035 | inputrc_name = os.path.join(home_dir,'.inputrc') |
|
1011 | 1036 | if os.path.isfile(inputrc_name): |
|
1012 | 1037 | try: |
|
1013 | 1038 | readline.read_init_file(inputrc_name) |
|
1014 | 1039 | except: |
|
1015 | 1040 | warn('Problems reading readline initialization file <%s>' |
|
1016 | 1041 | % inputrc_name) |
|
1017 | 1042 | |
|
1018 | 1043 | self.has_readline = 1 |
|
1019 | 1044 | self.readline = readline |
|
1020 | 1045 | # save this in sys so embedded copies can restore it properly |
|
1021 | 1046 | sys.ipcompleter = self.Completer.complete |
|
1022 | 1047 | readline.set_completer(self.Completer.complete) |
|
1023 | 1048 | |
|
1024 | 1049 | # Configure readline according to user's prefs |
|
1025 | 1050 | for rlcommand in self.rc.readline_parse_and_bind: |
|
1026 | 1051 | readline.parse_and_bind(rlcommand) |
|
1027 | 1052 | |
|
1028 | 1053 | # remove some chars from the delimiters list |
|
1029 | 1054 | delims = readline.get_completer_delims() |
|
1030 | 1055 | delims = delims.translate(string._idmap, |
|
1031 | 1056 | self.rc.readline_remove_delims) |
|
1032 | 1057 | readline.set_completer_delims(delims) |
|
1033 | 1058 | # otherwise we end up with a monster history after a while: |
|
1034 | 1059 | readline.set_history_length(1000) |
|
1035 | 1060 | try: |
|
1036 | 1061 | #print '*** Reading readline history' # dbg |
|
1037 | 1062 | readline.read_history_file(self.histfile) |
|
1038 | 1063 | except IOError: |
|
1039 | 1064 | pass # It doesn't exist yet. |
|
1040 | 1065 | |
|
1041 | 1066 | atexit.register(self.atexit_operations) |
|
1042 | 1067 | del atexit |
|
1043 | 1068 | |
|
1044 | 1069 | # Configure auto-indent for all platforms |
|
1045 | 1070 | self.set_autoindent(self.rc.autoindent) |
|
1046 | 1071 | |
|
1047 | 1072 | def _should_recompile(self,e): |
|
1048 | 1073 | """Utility routine for edit_syntax_error""" |
|
1049 | 1074 | |
|
1050 | 1075 | if e.filename in ('<ipython console>','<input>','<string>', |
|
1051 | 1076 | '<console>'): |
|
1052 | 1077 | return False |
|
1053 | 1078 | try: |
|
1054 | 1079 | if not ask_yes_no('Return to editor to correct syntax error? ' |
|
1055 | 1080 | '[Y/n] ','y'): |
|
1056 | 1081 | return False |
|
1057 | 1082 | except EOFError: |
|
1058 | 1083 | return False |
|
1059 | 1084 | self.hooks.fix_error_editor(e.filename,e.lineno,e.offset,e.msg) |
|
1060 | 1085 | return True |
|
1061 | 1086 | |
|
1062 | 1087 | def edit_syntax_error(self): |
|
1063 | 1088 | """The bottom half of the syntax error handler called in the main loop. |
|
1064 | 1089 | |
|
1065 | 1090 | Loop until syntax error is fixed or user cancels. |
|
1066 | 1091 | """ |
|
1067 | 1092 | |
|
1068 | 1093 | while self.SyntaxTB.last_syntax_error: |
|
1069 | 1094 | # copy and clear last_syntax_error |
|
1070 | 1095 | err = self.SyntaxTB.clear_err_state() |
|
1071 | 1096 | if not self._should_recompile(err): |
|
1072 | 1097 | return |
|
1073 | 1098 | try: |
|
1074 | 1099 | # may set last_syntax_error again if a SyntaxError is raised |
|
1075 | 1100 | self.safe_execfile(err.filename,self.shell.user_ns) |
|
1076 | 1101 | except: |
|
1077 | 1102 | self.showtraceback() |
|
1078 | 1103 | else: |
|
1079 | 1104 | f = file(err.filename) |
|
1080 | 1105 | try: |
|
1081 | 1106 | sys.displayhook(f.read()) |
|
1082 | 1107 | finally: |
|
1083 | 1108 | f.close() |
|
1084 | 1109 | |
|
1085 | 1110 | def showsyntaxerror(self, filename=None): |
|
1086 | 1111 | """Display the syntax error that just occurred. |
|
1087 | 1112 | |
|
1088 | 1113 | This doesn't display a stack trace because there isn't one. |
|
1089 | 1114 | |
|
1090 | 1115 | If a filename is given, it is stuffed in the exception instead |
|
1091 | 1116 | of what was there before (because Python's parser always uses |
|
1092 | 1117 | "<string>" when reading from a string). |
|
1093 | 1118 | """ |
|
1094 | 1119 | type, value, sys.last_traceback = sys.exc_info() |
|
1095 | 1120 | sys.last_type = type |
|
1096 | 1121 | sys.last_value = value |
|
1097 | 1122 | if filename and type is SyntaxError: |
|
1098 | 1123 | # Work hard to stuff the correct filename in the exception |
|
1099 | 1124 | try: |
|
1100 | 1125 | msg, (dummy_filename, lineno, offset, line) = value |
|
1101 | 1126 | except: |
|
1102 | 1127 | # Not the format we expect; leave it alone |
|
1103 | 1128 | pass |
|
1104 | 1129 | else: |
|
1105 | 1130 | # Stuff in the right filename |
|
1106 | 1131 | try: |
|
1107 | 1132 | # Assume SyntaxError is a class exception |
|
1108 | 1133 | value = SyntaxError(msg, (filename, lineno, offset, line)) |
|
1109 | 1134 | except: |
|
1110 | 1135 | # If that failed, assume SyntaxError is a string |
|
1111 | 1136 | value = msg, (filename, lineno, offset, line) |
|
1112 | 1137 | self.SyntaxTB(type,value,[]) |
|
1113 | 1138 | |
|
1114 | 1139 | def debugger(self): |
|
1115 | 1140 | """Call the pdb debugger.""" |
|
1116 | 1141 | |
|
1117 | 1142 | if not self.rc.pdb: |
|
1118 | 1143 | return |
|
1119 | 1144 | pdb.pm() |
|
1120 | 1145 | |
|
1121 | 1146 | def showtraceback(self,exc_tuple = None,filename=None): |
|
1122 | 1147 | """Display the exception that just occurred.""" |
|
1123 | 1148 | |
|
1124 | 1149 | # Though this won't be called by syntax errors in the input line, |
|
1125 | 1150 | # there may be SyntaxError cases whith imported code. |
|
1126 | 1151 | if exc_tuple is None: |
|
1127 | 1152 | type, value, tb = sys.exc_info() |
|
1128 | 1153 | else: |
|
1129 | 1154 | type, value, tb = exc_tuple |
|
1130 | 1155 | if type is SyntaxError: |
|
1131 | 1156 | self.showsyntaxerror(filename) |
|
1132 | 1157 | else: |
|
1133 | 1158 | sys.last_type = type |
|
1134 | 1159 | sys.last_value = value |
|
1135 | 1160 | sys.last_traceback = tb |
|
1136 | 1161 | self.InteractiveTB() |
|
1137 | 1162 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1138 | 1163 | # pdb mucks up readline, fix it back |
|
1139 | 1164 | self.readline.set_completer(self.Completer.complete) |
|
1140 | 1165 | |
|
1141 | 1166 | def update_cache(self, line): |
|
1142 | 1167 | """puts line into cache""" |
|
1143 | 1168 | self.inputcache.insert(0, line) # This copies the cache every time ... :-( |
|
1144 | 1169 | if len(self.inputcache) >= self.CACHELENGTH: |
|
1145 | 1170 | self.inputcache.pop() # This doesn't :-) |
|
1146 | 1171 | |
|
1147 | 1172 | def mainloop(self,banner=None): |
|
1148 | 1173 | """Creates the local namespace and starts the mainloop. |
|
1149 | 1174 | |
|
1150 | 1175 | If an optional banner argument is given, it will override the |
|
1151 | 1176 | internally created default banner.""" |
|
1152 | 1177 | |
|
1153 | 1178 | if self.rc.c: # Emulate Python's -c option |
|
1154 | 1179 | self.exec_init_cmd() |
|
1155 | 1180 | if banner is None: |
|
1156 | 1181 | if self.rc.banner: |
|
1157 | 1182 | banner = self.BANNER+self.banner2 |
|
1158 | 1183 | else: |
|
1159 | 1184 | banner = '' |
|
1160 | 1185 | self.interact(banner) |
|
1161 | 1186 | |
|
1162 | 1187 | def exec_init_cmd(self): |
|
1163 | 1188 | """Execute a command given at the command line. |
|
1164 | 1189 | |
|
1165 | 1190 | This emulates Python's -c option.""" |
|
1166 | 1191 | |
|
1167 | 1192 | sys.argv = ['-c'] |
|
1168 | 1193 | self.push(self.rc.c) |
|
1169 | 1194 | |
|
1170 | 1195 | def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): |
|
1171 | 1196 | """Embeds IPython into a running python program. |
|
1172 | 1197 | |
|
1173 | 1198 | Input: |
|
1174 | 1199 | |
|
1175 | 1200 | - header: An optional header message can be specified. |
|
1176 | 1201 | |
|
1177 | 1202 | - local_ns, global_ns: working namespaces. If given as None, the |
|
1178 | 1203 | IPython-initialized one is updated with __main__.__dict__, so that |
|
1179 | 1204 | program variables become visible but user-specific configuration |
|
1180 | 1205 | remains possible. |
|
1181 | 1206 | |
|
1182 | 1207 | - stack_depth: specifies how many levels in the stack to go to |
|
1183 | 1208 | looking for namespaces (when local_ns and global_ns are None). This |
|
1184 | 1209 | allows an intermediate caller to make sure that this function gets |
|
1185 | 1210 | the namespace from the intended level in the stack. By default (0) |
|
1186 | 1211 | it will get its locals and globals from the immediate caller. |
|
1187 | 1212 | |
|
1188 | 1213 | Warning: it's possible to use this in a program which is being run by |
|
1189 | 1214 | IPython itself (via %run), but some funny things will happen (a few |
|
1190 | 1215 | globals get overwritten). In the future this will be cleaned up, as |
|
1191 | 1216 | there is no fundamental reason why it can't work perfectly.""" |
|
1192 | 1217 | |
|
1193 | 1218 | # Get locals and globals from caller |
|
1194 | 1219 | if local_ns is None or global_ns is None: |
|
1195 | 1220 | call_frame = sys._getframe(stack_depth).f_back |
|
1196 | 1221 | |
|
1197 | 1222 | if local_ns is None: |
|
1198 | 1223 | local_ns = call_frame.f_locals |
|
1199 | 1224 | if global_ns is None: |
|
1200 | 1225 | global_ns = call_frame.f_globals |
|
1201 | 1226 | |
|
1202 | 1227 | # Update namespaces and fire up interpreter |
|
1203 | 1228 | self.user_ns = local_ns |
|
1204 | 1229 | self.user_global_ns = global_ns |
|
1205 | 1230 | |
|
1206 | 1231 | # Patch for global embedding to make sure that things don't overwrite |
|
1207 | 1232 | # user globals accidentally. Thanks to Richard <rxe@renre-europe.com> |
|
1208 | 1233 | # FIXME. Test this a bit more carefully (the if.. is new) |
|
1209 | 1234 | if local_ns is None and global_ns is None: |
|
1210 | 1235 | self.user_global_ns.update(__main__.__dict__) |
|
1211 | 1236 | |
|
1212 | 1237 | # make sure the tab-completer has the correct frame information, so it |
|
1213 | 1238 | # actually completes using the frame's locals/globals |
|
1214 | 1239 | self.set_completer_frame(call_frame) |
|
1215 | 1240 | |
|
1216 | 1241 | self.interact(header) |
|
1217 | 1242 | |
|
1218 | 1243 | def interact(self, banner=None): |
|
1219 | 1244 | """Closely emulate the interactive Python console. |
|
1220 | 1245 | |
|
1221 | 1246 | The optional banner argument specify the banner to print |
|
1222 | 1247 | before the first interaction; by default it prints a banner |
|
1223 | 1248 | similar to the one printed by the real Python interpreter, |
|
1224 | 1249 | followed by the current class name in parentheses (so as not |
|
1225 | 1250 | to confuse this with the real interpreter -- since it's so |
|
1226 | 1251 | close!). |
|
1227 | 1252 | |
|
1228 | 1253 | """ |
|
1229 | 1254 | cprt = 'Type "copyright", "credits" or "license" for more information.' |
|
1230 | 1255 | if banner is None: |
|
1231 | 1256 | self.write("Python %s on %s\n%s\n(%s)\n" % |
|
1232 | 1257 | (sys.version, sys.platform, cprt, |
|
1233 | 1258 | self.__class__.__name__)) |
|
1234 | 1259 | else: |
|
1235 | 1260 | self.write(banner) |
|
1236 | 1261 | |
|
1237 | 1262 | more = 0 |
|
1238 | 1263 | |
|
1239 | 1264 | # Mark activity in the builtins |
|
1240 | 1265 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1241 | 1266 | |
|
1242 | 1267 | # compiled regexps for autoindent management |
|
1243 | 1268 | ini_spaces_re = re.compile(r'^(\s+)') |
|
1244 | 1269 | dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass') |
|
1245 | 1270 | |
|
1246 | 1271 | # exit_now is set by a call to %Exit or %Quit |
|
1247 | 1272 | while not self.exit_now: |
|
1248 | 1273 | try: |
|
1249 | 1274 | if more: |
|
1250 | 1275 | prompt = self.outputcache.prompt2 |
|
1251 | 1276 | if self.autoindent: |
|
1252 | 1277 | self.readline_startup_hook(self.pre_readline) |
|
1253 | 1278 | else: |
|
1254 | 1279 | prompt = self.outputcache.prompt1 |
|
1255 | 1280 | try: |
|
1256 | 1281 | line = self.raw_input(prompt,more) |
|
1257 | 1282 | if self.autoindent: |
|
1258 | 1283 | self.readline_startup_hook(None) |
|
1259 | 1284 | except EOFError: |
|
1260 | 1285 | if self.autoindent: |
|
1261 | 1286 | self.readline_startup_hook(None) |
|
1262 | 1287 | self.write("\n") |
|
1263 | 1288 | self.exit() |
|
1264 | 1289 | else: |
|
1265 | 1290 | more = self.push(line) |
|
1266 | 1291 | # Auto-indent management |
|
1267 | 1292 | if self.autoindent: |
|
1268 | 1293 | if line: |
|
1269 | 1294 | ini_spaces = ini_spaces_re.match(line) |
|
1270 | 1295 | if ini_spaces: |
|
1271 | 1296 | nspaces = ini_spaces.end() |
|
1272 | 1297 | else: |
|
1273 | 1298 | nspaces = 0 |
|
1274 | 1299 | self.indent_current_nsp = nspaces |
|
1275 | 1300 | |
|
1276 | 1301 | if line[-1] == ':': |
|
1277 | 1302 | self.indent_current_nsp += 4 |
|
1278 | 1303 | elif dedent_re.match(line): |
|
1279 | 1304 | self.indent_current_nsp -= 4 |
|
1280 | 1305 | else: |
|
1281 | 1306 | self.indent_current_nsp = 0 |
|
1282 | 1307 | |
|
1283 | 1308 | # indent_current is the actual string to be inserted |
|
1284 | 1309 | # by the readline hooks for indentation |
|
1285 | 1310 | self.indent_current = ' '* self.indent_current_nsp |
|
1286 | 1311 | |
|
1287 | 1312 | if (self.SyntaxTB.last_syntax_error and |
|
1288 | 1313 | self.rc.autoedit_syntax): |
|
1289 | 1314 | self.edit_syntax_error() |
|
1290 | 1315 | |
|
1291 | 1316 | except KeyboardInterrupt: |
|
1292 | 1317 | self.write("\nKeyboardInterrupt\n") |
|
1293 | 1318 | self.resetbuffer() |
|
1294 | 1319 | more = 0 |
|
1295 | 1320 | # keep cache in sync with the prompt counter: |
|
1296 | 1321 | self.outputcache.prompt_count -= 1 |
|
1297 | 1322 | |
|
1298 | 1323 | if self.autoindent: |
|
1299 | 1324 | self.indent_current_nsp = 0 |
|
1300 | 1325 | self.indent_current = ' '* self.indent_current_nsp |
|
1301 | 1326 | |
|
1302 | 1327 | except bdb.BdbQuit: |
|
1303 | 1328 | warn("The Python debugger has exited with a BdbQuit exception.\n" |
|
1304 | 1329 | "Because of how pdb handles the stack, it is impossible\n" |
|
1305 | 1330 | "for IPython to properly format this particular exception.\n" |
|
1306 | 1331 | "IPython will resume normal operation.") |
|
1307 | 1332 | |
|
1308 | 1333 | # We are off again... |
|
1309 | 1334 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
|
1310 | 1335 | |
|
1311 | 1336 | def excepthook(self, type, value, tb): |
|
1312 | 1337 | """One more defense for GUI apps that call sys.excepthook. |
|
1313 | 1338 | |
|
1314 | 1339 | GUI frameworks like wxPython trap exceptions and call |
|
1315 | 1340 | sys.excepthook themselves. I guess this is a feature that |
|
1316 | 1341 | enables them to keep running after exceptions that would |
|
1317 | 1342 | otherwise kill their mainloop. This is a bother for IPython |
|
1318 | 1343 | which excepts to catch all of the program exceptions with a try: |
|
1319 | 1344 | except: statement. |
|
1320 | 1345 | |
|
1321 | 1346 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if |
|
1322 | 1347 | any app directly invokes sys.excepthook, it will look to the user like |
|
1323 | 1348 | IPython crashed. In order to work around this, we can disable the |
|
1324 | 1349 | CrashHandler and replace it with this excepthook instead, which prints a |
|
1325 | 1350 | regular traceback using our InteractiveTB. In this fashion, apps which |
|
1326 | 1351 | call sys.excepthook will generate a regular-looking exception from |
|
1327 | 1352 | IPython, and the CrashHandler will only be triggered by real IPython |
|
1328 | 1353 | crashes. |
|
1329 | 1354 | |
|
1330 | 1355 | This hook should be used sparingly, only in places which are not likely |
|
1331 | 1356 | to be true IPython errors. |
|
1332 | 1357 | """ |
|
1333 | 1358 | |
|
1334 | 1359 | self.InteractiveTB(type, value, tb, tb_offset=0) |
|
1335 | 1360 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1336 | 1361 | self.readline.set_completer(self.Completer.complete) |
|
1337 | 1362 | |
|
1338 | 1363 | def call_alias(self,alias,rest=''): |
|
1339 | 1364 | """Call an alias given its name and the rest of the line. |
|
1340 | 1365 | |
|
1341 | 1366 | This function MUST be given a proper alias, because it doesn't make |
|
1342 | 1367 | any checks when looking up into the alias table. The caller is |
|
1343 | 1368 | responsible for invoking it only with a valid alias.""" |
|
1344 | 1369 | |
|
1345 | 1370 | #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg |
|
1346 | 1371 | nargs,cmd = self.alias_table[alias] |
|
1347 | 1372 | # Expand the %l special to be the user's input line |
|
1348 | 1373 | if cmd.find('%l') >= 0: |
|
1349 | 1374 | cmd = cmd.replace('%l',rest) |
|
1350 | 1375 | rest = '' |
|
1351 | 1376 | if nargs==0: |
|
1352 | 1377 | # Simple, argument-less aliases |
|
1353 | 1378 | cmd = '%s %s' % (cmd,rest) |
|
1354 | 1379 | else: |
|
1355 | 1380 | # Handle aliases with positional arguments |
|
1356 | 1381 | args = rest.split(None,nargs) |
|
1357 | 1382 | if len(args)< nargs: |
|
1358 | 1383 | error('Alias <%s> requires %s arguments, %s given.' % |
|
1359 | 1384 | (alias,nargs,len(args))) |
|
1360 | 1385 | return |
|
1361 | 1386 | cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) |
|
1362 | 1387 | # Now call the macro, evaluating in the user's namespace |
|
1363 | 1388 | try: |
|
1364 | 1389 | self.system(cmd) |
|
1365 | 1390 | except: |
|
1366 | 1391 | self.showtraceback() |
|
1367 | 1392 | |
|
1368 | 1393 | def runlines(self,lines): |
|
1369 | 1394 | """Run a string of one or more lines of source. |
|
1370 | 1395 | |
|
1371 | 1396 | This method is capable of running a string containing multiple source |
|
1372 | 1397 | lines, as if they had been entered at the IPython prompt. Since it |
|
1373 | 1398 | exposes IPython's processing machinery, the given strings can contain |
|
1374 | 1399 | magic calls (%magic), special shell access (!cmd), etc.""" |
|
1375 | 1400 | |
|
1376 | 1401 | # We must start with a clean buffer, in case this is run from an |
|
1377 | 1402 | # interactive IPython session (via a magic, for example). |
|
1378 | 1403 | self.resetbuffer() |
|
1379 | 1404 | lines = lines.split('\n') |
|
1380 | 1405 | more = 0 |
|
1381 | 1406 | for line in lines: |
|
1382 | 1407 | # skip blank lines so we don't mess up the prompt counter, but do |
|
1383 | 1408 | # NOT skip even a blank line if we are in a code block (more is |
|
1384 | 1409 | # true) |
|
1385 | 1410 | if line or more: |
|
1386 | 1411 | more = self.push((self.prefilter(line,more))) |
|
1387 | 1412 | # IPython's runsource returns None if there was an error |
|
1388 | 1413 | # compiling the code. This allows us to stop processing right |
|
1389 | 1414 | # away, so the user gets the error message at the right place. |
|
1390 | 1415 | if more is None: |
|
1391 | 1416 | break |
|
1392 | 1417 | # final newline in case the input didn't have it, so that the code |
|
1393 | 1418 | # actually does get executed |
|
1394 | 1419 | if more: |
|
1395 | 1420 | self.push('\n') |
|
1396 | 1421 | |
|
1397 | 1422 | def runsource(self, source, filename='<input>', symbol='single'): |
|
1398 | 1423 | """Compile and run some source in the interpreter. |
|
1399 | 1424 | |
|
1400 | 1425 | Arguments are as for compile_command(). |
|
1401 | 1426 | |
|
1402 | 1427 | One several things can happen: |
|
1403 | 1428 | |
|
1404 | 1429 | 1) The input is incorrect; compile_command() raised an |
|
1405 | 1430 | exception (SyntaxError or OverflowError). A syntax traceback |
|
1406 | 1431 | will be printed by calling the showsyntaxerror() method. |
|
1407 | 1432 | |
|
1408 | 1433 | 2) The input is incomplete, and more input is required; |
|
1409 | 1434 | compile_command() returned None. Nothing happens. |
|
1410 | 1435 | |
|
1411 | 1436 | 3) The input is complete; compile_command() returned a code |
|
1412 | 1437 | object. The code is executed by calling self.runcode() (which |
|
1413 | 1438 | also handles run-time exceptions, except for SystemExit). |
|
1414 | 1439 | |
|
1415 | 1440 | The return value is: |
|
1416 | 1441 | |
|
1417 | 1442 | - True in case 2 |
|
1418 | 1443 | |
|
1419 | 1444 | - False in the other cases, unless an exception is raised, where |
|
1420 | 1445 | None is returned instead. This can be used by external callers to |
|
1421 | 1446 | know whether to continue feeding input or not. |
|
1422 | 1447 | |
|
1423 | 1448 | The return value can be used to decide whether to use sys.ps1 or |
|
1424 | 1449 | sys.ps2 to prompt the next line.""" |
|
1425 | 1450 | |
|
1426 | 1451 | try: |
|
1427 | 1452 | code = self.compile(source,filename,symbol) |
|
1428 | 1453 | except (OverflowError, SyntaxError, ValueError): |
|
1429 | 1454 | # Case 1 |
|
1430 | 1455 | self.showsyntaxerror(filename) |
|
1431 | 1456 | return None |
|
1432 | 1457 | |
|
1433 | 1458 | if code is None: |
|
1434 | 1459 | # Case 2 |
|
1435 | 1460 | return True |
|
1436 | 1461 | |
|
1437 | 1462 | # Case 3 |
|
1438 | 1463 | # We store the code object so that threaded shells and |
|
1439 | 1464 | # custom exception handlers can access all this info if needed. |
|
1440 | 1465 | # The source corresponding to this can be obtained from the |
|
1441 | 1466 | # buffer attribute as '\n'.join(self.buffer). |
|
1442 | 1467 | self.code_to_run = code |
|
1443 | 1468 | # now actually execute the code object |
|
1444 | 1469 | if self.runcode(code) == 0: |
|
1445 | 1470 | return False |
|
1446 | 1471 | else: |
|
1447 | 1472 | return None |
|
1448 | 1473 | |
|
1449 | 1474 | def runcode(self,code_obj): |
|
1450 | 1475 | """Execute a code object. |
|
1451 | 1476 | |
|
1452 | 1477 | When an exception occurs, self.showtraceback() is called to display a |
|
1453 | 1478 | traceback. |
|
1454 | 1479 | |
|
1455 | 1480 | Return value: a flag indicating whether the code to be run completed |
|
1456 | 1481 | successfully: |
|
1457 | 1482 | |
|
1458 | 1483 | - 0: successful execution. |
|
1459 | 1484 | - 1: an error occurred. |
|
1460 | 1485 | """ |
|
1461 | 1486 | |
|
1462 | 1487 | # Set our own excepthook in case the user code tries to call it |
|
1463 | 1488 | # directly, so that the IPython crash handler doesn't get triggered |
|
1464 | 1489 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
1490 | ||
|
1491 | # we save the original sys.excepthook in the instance, in case config | |
|
1492 | # code (such as magics) needs access to it. | |
|
1493 | self.sys_excepthook = old_excepthook | |
|
1465 | 1494 | outflag = 1 # happens in more places, so it's easier as default |
|
1466 | 1495 | try: |
|
1467 | 1496 | try: |
|
1468 | 1497 | # Embedded instances require separate global/local namespaces |
|
1469 | 1498 | # so they can see both the surrounding (local) namespace and |
|
1470 | 1499 | # the module-level globals when called inside another function. |
|
1471 | 1500 | if self.embedded: |
|
1472 | 1501 | exec code_obj in self.user_global_ns, self.user_ns |
|
1473 | 1502 | # Normal (non-embedded) instances should only have a single |
|
1474 | 1503 | # namespace for user code execution, otherwise functions won't |
|
1475 | 1504 | # see interactive top-level globals. |
|
1476 | 1505 | else: |
|
1477 | 1506 | exec code_obj in self.user_ns |
|
1478 | 1507 | finally: |
|
1479 | 1508 | # Reset our crash handler in place |
|
1480 | 1509 | sys.excepthook = old_excepthook |
|
1481 | 1510 | except SystemExit: |
|
1482 | 1511 | self.resetbuffer() |
|
1483 | 1512 | self.showtraceback() |
|
1484 | 1513 | warn("Type exit or quit to exit IPython " |
|
1485 | 1514 | "(%Exit or %Quit do so unconditionally).",level=1) |
|
1486 | 1515 | except self.custom_exceptions: |
|
1487 | 1516 | etype,value,tb = sys.exc_info() |
|
1488 | 1517 | self.CustomTB(etype,value,tb) |
|
1489 | 1518 | except: |
|
1490 | 1519 | self.showtraceback() |
|
1491 | 1520 | else: |
|
1492 | 1521 | outflag = 0 |
|
1493 | 1522 | if softspace(sys.stdout, 0): |
|
1494 | 1523 | |
|
1495 | 1524 | # Flush out code object which has been run (and source) |
|
1496 | 1525 | self.code_to_run = None |
|
1497 | 1526 | return outflag |
|
1498 | 1527 | |
|
1499 | 1528 | def push(self, line): |
|
1500 | 1529 | """Push a line to the interpreter. |
|
1501 | 1530 | |
|
1502 | 1531 | The line should not have a trailing newline; it may have |
|
1503 | 1532 | internal newlines. The line is appended to a buffer and the |
|
1504 | 1533 | interpreter's runsource() method is called with the |
|
1505 | 1534 | concatenated contents of the buffer as source. If this |
|
1506 | 1535 | indicates that the command was executed or invalid, the buffer |
|
1507 | 1536 | is reset; otherwise, the command is incomplete, and the buffer |
|
1508 | 1537 | is left as it was after the line was appended. The return |
|
1509 | 1538 | value is 1 if more input is required, 0 if the line was dealt |
|
1510 | 1539 | with in some way (this is the same as runsource()). |
|
1511 | 1540 | |
|
1512 | 1541 | """ |
|
1513 | 1542 | self.buffer.append(line) |
|
1514 | 1543 | more = self.runsource('\n'.join(self.buffer), self.filename) |
|
1515 | 1544 | if not more: |
|
1516 | 1545 | self.resetbuffer() |
|
1517 | 1546 | return more |
|
1518 | 1547 | |
|
1519 | 1548 | def resetbuffer(self): |
|
1520 | 1549 | """Reset the input buffer.""" |
|
1521 | 1550 | self.buffer[:] = [] |
|
1522 | 1551 | |
|
1523 | 1552 | def raw_input(self,prompt='',continue_prompt=False): |
|
1524 | 1553 | """Write a prompt and read a line. |
|
1525 | 1554 | |
|
1526 | 1555 | The returned line does not include the trailing newline. |
|
1527 | 1556 | When the user enters the EOF key sequence, EOFError is raised. |
|
1528 | 1557 | |
|
1529 | 1558 | Optional inputs: |
|
1530 | 1559 | |
|
1531 | 1560 | - prompt(''): a string to be printed to prompt the user. |
|
1532 | 1561 | |
|
1533 | 1562 | - continue_prompt(False): whether this line is the first one or a |
|
1534 | 1563 | continuation in a sequence of inputs. |
|
1535 | 1564 | """ |
|
1536 | 1565 | |
|
1537 | 1566 | line = raw_input_original(prompt) |
|
1538 | 1567 | # Try to be reasonably smart about not re-indenting pasted input more |
|
1539 | 1568 | # than necessary. We do this by trimming out the auto-indent initial |
|
1540 | 1569 | # spaces, if the user's actual input started itself with whitespace. |
|
1541 | 1570 | if self.autoindent: |
|
1542 | 1571 | line2 = line[self.indent_current_nsp:] |
|
1543 | 1572 | if line2[0:1] in (' ','\t'): |
|
1544 | 1573 | line = line2 |
|
1545 | 1574 | return self.prefilter(line,continue_prompt) |
|
1546 | 1575 | |
|
1547 | 1576 | def split_user_input(self,line): |
|
1548 | 1577 | """Split user input into pre-char, function part and rest.""" |
|
1549 | 1578 | |
|
1550 | 1579 | lsplit = self.line_split.match(line) |
|
1551 | 1580 | if lsplit is None: # no regexp match returns None |
|
1552 | 1581 | try: |
|
1553 | 1582 | iFun,theRest = line.split(None,1) |
|
1554 | 1583 | except ValueError: |
|
1555 | 1584 | iFun,theRest = line,'' |
|
1556 | 1585 | pre = re.match('^(\s*)(.*)',line).groups()[0] |
|
1557 | 1586 | else: |
|
1558 | 1587 | pre,iFun,theRest = lsplit.groups() |
|
1559 | 1588 | |
|
1560 | 1589 | #print 'line:<%s>' % line # dbg |
|
1561 | 1590 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg |
|
1562 | 1591 | return pre,iFun.strip(),theRest |
|
1563 | 1592 | |
|
1564 | 1593 | def _prefilter(self, line, continue_prompt): |
|
1565 | 1594 | """Calls different preprocessors, depending on the form of line.""" |
|
1566 | 1595 | |
|
1567 | 1596 | # All handlers *must* return a value, even if it's blank (''). |
|
1568 | 1597 | |
|
1569 | 1598 | # Lines are NOT logged here. Handlers should process the line as |
|
1570 | 1599 | # needed, update the cache AND log it (so that the input cache array |
|
1571 | 1600 | # stays synced). |
|
1572 | 1601 | |
|
1573 | 1602 | # This function is _very_ delicate, and since it's also the one which |
|
1574 | 1603 | # determines IPython's response to user input, it must be as efficient |
|
1575 | 1604 | # as possible. For this reason it has _many_ returns in it, trying |
|
1576 | 1605 | # always to exit as quickly as it can figure out what it needs to do. |
|
1577 | 1606 | |
|
1578 | 1607 | # This function is the main responsible for maintaining IPython's |
|
1579 | 1608 | # behavior respectful of Python's semantics. So be _very_ careful if |
|
1580 | 1609 | # making changes to anything here. |
|
1581 | 1610 | |
|
1582 | 1611 | #..................................................................... |
|
1583 | 1612 | # Code begins |
|
1584 | 1613 | |
|
1585 | 1614 | #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg |
|
1586 | 1615 | |
|
1587 | 1616 | # save the line away in case we crash, so the post-mortem handler can |
|
1588 | 1617 | # record it |
|
1589 | 1618 | self._last_input_line = line |
|
1590 | 1619 | |
|
1591 | 1620 | #print '***line: <%s>' % line # dbg |
|
1592 | 1621 | |
|
1593 | 1622 | # the input history needs to track even empty lines |
|
1594 | 1623 | if not line.strip(): |
|
1595 | 1624 | if not continue_prompt: |
|
1596 | 1625 | self.outputcache.prompt_count -= 1 |
|
1597 | 1626 | return self.handle_normal(line,continue_prompt) |
|
1598 | 1627 | #return self.handle_normal('',continue_prompt) |
|
1599 | 1628 | |
|
1600 | 1629 | # print '***cont',continue_prompt # dbg |
|
1601 | 1630 | # special handlers are only allowed for single line statements |
|
1602 | 1631 | if continue_prompt and not self.rc.multi_line_specials: |
|
1603 | 1632 | return self.handle_normal(line,continue_prompt) |
|
1604 | 1633 | |
|
1605 | 1634 | # For the rest, we need the structure of the input |
|
1606 | 1635 | pre,iFun,theRest = self.split_user_input(line) |
|
1607 | 1636 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1608 | 1637 | |
|
1609 | 1638 | # First check for explicit escapes in the last/first character |
|
1610 | 1639 | handler = None |
|
1611 | 1640 | if line[-1] == self.ESC_HELP: |
|
1612 | 1641 | handler = self.esc_handlers.get(line[-1]) # the ? can be at the end |
|
1613 | 1642 | if handler is None: |
|
1614 | 1643 | # look at the first character of iFun, NOT of line, so we skip |
|
1615 | 1644 | # leading whitespace in multiline input |
|
1616 | 1645 | handler = self.esc_handlers.get(iFun[0:1]) |
|
1617 | 1646 | if handler is not None: |
|
1618 | 1647 | return handler(line,continue_prompt,pre,iFun,theRest) |
|
1619 | 1648 | # Emacs ipython-mode tags certain input lines |
|
1620 | 1649 | if line.endswith('# PYTHON-MODE'): |
|
1621 | 1650 | return self.handle_emacs(line,continue_prompt) |
|
1622 | 1651 | |
|
1623 | 1652 | # Next, check if we can automatically execute this thing |
|
1624 | 1653 | |
|
1625 | 1654 | # Allow ! in multi-line statements if multi_line_specials is on: |
|
1626 | 1655 | if continue_prompt and self.rc.multi_line_specials and \ |
|
1627 | 1656 | iFun.startswith(self.ESC_SHELL): |
|
1628 | 1657 | return self.handle_shell_escape(line,continue_prompt, |
|
1629 | 1658 | pre=pre,iFun=iFun, |
|
1630 | 1659 | theRest=theRest) |
|
1631 | 1660 | |
|
1632 | 1661 | # Let's try to find if the input line is a magic fn |
|
1633 | 1662 | oinfo = None |
|
1634 | 1663 | if hasattr(self,'magic_'+iFun): |
|
1635 | 1664 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1636 | 1665 | if oinfo['ismagic']: |
|
1637 | 1666 | # Be careful not to call magics when a variable assignment is |
|
1638 | 1667 | # being made (ls='hi', for example) |
|
1639 | 1668 | if self.rc.automagic and \ |
|
1640 | 1669 | (len(theRest)==0 or theRest[0] not in '!=()<>,') and \ |
|
1641 | 1670 | (self.rc.multi_line_specials or not continue_prompt): |
|
1642 | 1671 | return self.handle_magic(line,continue_prompt, |
|
1643 | 1672 | pre,iFun,theRest) |
|
1644 | 1673 | else: |
|
1645 | 1674 | return self.handle_normal(line,continue_prompt) |
|
1646 | 1675 | |
|
1647 | 1676 | # If the rest of the line begins with an (in)equality, assginment or |
|
1648 | 1677 | # function call, we should not call _ofind but simply execute it. |
|
1649 | 1678 | # This avoids spurious geattr() accesses on objects upon assignment. |
|
1650 | 1679 | # |
|
1651 | 1680 | # It also allows users to assign to either alias or magic names true |
|
1652 | 1681 | # python variables (the magic/alias systems always take second seat to |
|
1653 | 1682 | # true python code). |
|
1654 | 1683 | if theRest and theRest[0] in '!=()': |
|
1655 | 1684 | return self.handle_normal(line,continue_prompt) |
|
1656 | 1685 | |
|
1657 | 1686 | if oinfo is None: |
|
1658 | 1687 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1659 | 1688 | |
|
1660 | 1689 | if not oinfo['found']: |
|
1661 | 1690 | return self.handle_normal(line,continue_prompt) |
|
1662 | 1691 | else: |
|
1663 | 1692 | #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg |
|
1664 | 1693 | if oinfo['isalias']: |
|
1665 | 1694 | return self.handle_alias(line,continue_prompt, |
|
1666 | 1695 | pre,iFun,theRest) |
|
1667 | 1696 | |
|
1668 | 1697 | if self.rc.autocall and \ |
|
1669 | 1698 | not self.re_exclude_auto.match(theRest) and \ |
|
1670 | 1699 | self.re_fun_name.match(iFun) and \ |
|
1671 | 1700 | callable(oinfo['obj']) : |
|
1672 | 1701 | #print 'going auto' # dbg |
|
1673 | 1702 | return self.handle_auto(line,continue_prompt,pre,iFun,theRest) |
|
1674 | 1703 | else: |
|
1675 | 1704 | #print 'was callable?', callable(oinfo['obj']) # dbg |
|
1676 | 1705 | return self.handle_normal(line,continue_prompt) |
|
1677 | 1706 | |
|
1678 | 1707 | # If we get here, we have a normal Python line. Log and return. |
|
1679 | 1708 | return self.handle_normal(line,continue_prompt) |
|
1680 | 1709 | |
|
1681 | 1710 | def _prefilter_dumb(self, line, continue_prompt): |
|
1682 | 1711 | """simple prefilter function, for debugging""" |
|
1683 | 1712 | return self.handle_normal(line,continue_prompt) |
|
1684 | 1713 | |
|
1685 | 1714 | # Set the default prefilter() function (this can be user-overridden) |
|
1686 | 1715 | prefilter = _prefilter |
|
1687 | 1716 | |
|
1688 | 1717 | def handle_normal(self,line,continue_prompt=None, |
|
1689 | 1718 | pre=None,iFun=None,theRest=None): |
|
1690 | 1719 | """Handle normal input lines. Use as a template for handlers.""" |
|
1691 | 1720 | |
|
1692 | 1721 | # With autoindent on, we need some way to exit the input loop, and I |
|
1693 | 1722 | # don't want to force the user to have to backspace all the way to |
|
1694 | 1723 | # clear the line. The rule will be in this case, that either two |
|
1695 | 1724 | # lines of pure whitespace in a row, or a line of pure whitespace but |
|
1696 | 1725 | # of a size different to the indent level, will exit the input loop. |
|
1697 | 1726 | if (continue_prompt and self.autoindent and isspace(line) and |
|
1698 | 1727 | (line != self.indent_current or isspace(self.buffer[-1]))): |
|
1699 | 1728 | line = '' |
|
1700 | 1729 | |
|
1701 | 1730 | self.log(line,continue_prompt) |
|
1702 | 1731 | self.update_cache(line) |
|
1703 | 1732 | return line |
|
1704 | 1733 | |
|
1705 | 1734 | def handle_alias(self,line,continue_prompt=None, |
|
1706 | 1735 | pre=None,iFun=None,theRest=None): |
|
1707 | 1736 | """Handle alias input lines. """ |
|
1708 | 1737 | |
|
1709 | 1738 | theRest = esc_quotes(theRest) |
|
1710 | 1739 | line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest) |
|
1711 | 1740 | self.log(line_out,continue_prompt) |
|
1712 | 1741 | self.update_cache(line_out) |
|
1713 | 1742 | return line_out |
|
1714 | 1743 | |
|
1715 | 1744 | def handle_shell_escape(self, line, continue_prompt=None, |
|
1716 | 1745 | pre=None,iFun=None,theRest=None): |
|
1717 | 1746 | """Execute the line in a shell, empty return value""" |
|
1718 | 1747 | |
|
1719 | 1748 | #print 'line in :', `line` # dbg |
|
1720 | 1749 | # Example of a special handler. Others follow a similar pattern. |
|
1721 | 1750 | if continue_prompt: # multi-line statements |
|
1722 | 1751 | if iFun.startswith('!!'): |
|
1723 | 1752 | print 'SyntaxError: !! is not allowed in multiline statements' |
|
1724 | 1753 | return pre |
|
1725 | 1754 | else: |
|
1726 | 1755 | cmd = ("%s %s" % (iFun[1:],theRest)) #.replace('"','\\"') |
|
1727 | 1756 | #line_out = '%s%s.system("%s")' % (pre,self.name,cmd) |
|
1728 | 1757 | line_out = '%s%s.system(r"""%s"""[:-1])' % (pre,self.name,cmd + "_") |
|
1729 | 1758 | #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')' |
|
1730 | 1759 | else: # single-line input |
|
1731 | 1760 | if line.startswith('!!'): |
|
1732 | 1761 | # rewrite iFun/theRest to properly hold the call to %sx and |
|
1733 | 1762 | # the actual command to be executed, so handle_magic can work |
|
1734 | 1763 | # correctly |
|
1735 | 1764 | theRest = '%s %s' % (iFun[2:],theRest) |
|
1736 | 1765 | iFun = 'sx' |
|
1737 | 1766 | return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]), |
|
1738 | 1767 | continue_prompt,pre,iFun,theRest) |
|
1739 | 1768 | else: |
|
1740 | 1769 | #cmd = esc_quotes(line[1:]) |
|
1741 | 1770 | cmd=line[1:] |
|
1742 | 1771 | #line_out = '%s.system("%s")' % (self.name,cmd) |
|
1743 | 1772 | line_out = '%s.system(r"""%s"""[:-1])' % (self.name,cmd +"_") |
|
1744 | 1773 | #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')' |
|
1745 | 1774 | # update cache/log and return |
|
1746 | 1775 | self.log(line_out,continue_prompt) |
|
1747 | 1776 | self.update_cache(line_out) # readline cache gets normal line |
|
1748 | 1777 | #print 'line out r:', `line_out` # dbg |
|
1749 | 1778 | #print 'line out s:', line_out # dbg |
|
1750 | 1779 | return line_out |
|
1751 | 1780 | |
|
1752 | 1781 | def handle_magic(self, line, continue_prompt=None, |
|
1753 | 1782 | pre=None,iFun=None,theRest=None): |
|
1754 | 1783 | """Execute magic functions. |
|
1755 | 1784 | |
|
1756 | 1785 | Also log them with a prepended # so the log is clean Python.""" |
|
1757 | 1786 | |
|
1758 | 1787 | cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest))) |
|
1759 | 1788 | self.log(cmd,continue_prompt) |
|
1760 | 1789 | self.update_cache(line) |
|
1761 | 1790 | #print 'in handle_magic, cmd=<%s>' % cmd # dbg |
|
1762 | 1791 | return cmd |
|
1763 | 1792 | |
|
1764 | 1793 | def handle_auto(self, line, continue_prompt=None, |
|
1765 | 1794 | pre=None,iFun=None,theRest=None): |
|
1766 | 1795 | """Hande lines which can be auto-executed, quoting if requested.""" |
|
1767 | 1796 | |
|
1768 | 1797 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1769 | 1798 | |
|
1770 | 1799 | # This should only be active for single-line input! |
|
1771 | 1800 | if continue_prompt: |
|
1772 | 1801 | return line |
|
1773 | 1802 | |
|
1774 | 1803 | if pre == self.ESC_QUOTE: |
|
1775 | 1804 | # Auto-quote splitting on whitespace |
|
1776 | 1805 | newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) ) |
|
1777 | 1806 | elif pre == self.ESC_QUOTE2: |
|
1778 | 1807 | # Auto-quote whole string |
|
1779 | 1808 | newcmd = '%s("%s")' % (iFun,theRest) |
|
1780 | 1809 | else: |
|
1781 | 1810 | # Auto-paren |
|
1782 | 1811 | if theRest[0:1] in ('=','['): |
|
1783 | 1812 | # Don't autocall in these cases. They can be either |
|
1784 | 1813 | # rebindings of an existing callable's name, or item access |
|
1785 | 1814 | # for an object which is BOTH callable and implements |
|
1786 | 1815 | # __getitem__. |
|
1787 | 1816 | return '%s %s' % (iFun,theRest) |
|
1788 | 1817 | if theRest.endswith(';'): |
|
1789 | 1818 | newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1]) |
|
1790 | 1819 | else: |
|
1791 | 1820 | newcmd = '%s(%s)' % (iFun.rstrip(),theRest) |
|
1792 | 1821 | |
|
1793 | 1822 | print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd |
|
1794 | 1823 | # log what is now valid Python, not the actual user input (without the |
|
1795 | 1824 | # final newline) |
|
1796 | 1825 | self.log(newcmd,continue_prompt) |
|
1797 | 1826 | return newcmd |
|
1798 | 1827 | |
|
1799 | 1828 | def handle_help(self, line, continue_prompt=None, |
|
1800 | 1829 | pre=None,iFun=None,theRest=None): |
|
1801 | 1830 | """Try to get some help for the object. |
|
1802 | 1831 | |
|
1803 | 1832 | obj? or ?obj -> basic information. |
|
1804 | 1833 | obj?? or ??obj -> more details. |
|
1805 | 1834 | """ |
|
1806 | 1835 | |
|
1807 | 1836 | # We need to make sure that we don't process lines which would be |
|
1808 | 1837 | # otherwise valid python, such as "x=1 # what?" |
|
1809 | 1838 | try: |
|
1810 | 1839 | codeop.compile_command(line) |
|
1811 | 1840 | except SyntaxError: |
|
1812 | 1841 | # We should only handle as help stuff which is NOT valid syntax |
|
1813 | 1842 | if line[0]==self.ESC_HELP: |
|
1814 | 1843 | line = line[1:] |
|
1815 | 1844 | elif line[-1]==self.ESC_HELP: |
|
1816 | 1845 | line = line[:-1] |
|
1817 | 1846 | self.log('#?'+line) |
|
1818 | 1847 | self.update_cache(line) |
|
1819 | 1848 | if line: |
|
1820 | 1849 | self.magic_pinfo(line) |
|
1821 | 1850 | else: |
|
1822 | 1851 | page(self.usage,screen_lines=self.rc.screen_length) |
|
1823 | 1852 | return '' # Empty string is needed here! |
|
1824 | 1853 | except: |
|
1825 | 1854 | # Pass any other exceptions through to the normal handler |
|
1826 | 1855 | return self.handle_normal(line,continue_prompt) |
|
1827 | 1856 | else: |
|
1828 | 1857 | # If the code compiles ok, we should handle it normally |
|
1829 | 1858 | return self.handle_normal(line,continue_prompt) |
|
1830 | 1859 | |
|
1831 | 1860 | def handle_emacs(self,line,continue_prompt=None, |
|
1832 | 1861 | pre=None,iFun=None,theRest=None): |
|
1833 | 1862 | """Handle input lines marked by python-mode.""" |
|
1834 | 1863 | |
|
1835 | 1864 | # Currently, nothing is done. Later more functionality can be added |
|
1836 | 1865 | # here if needed. |
|
1837 | 1866 | |
|
1838 | 1867 | # The input cache shouldn't be updated |
|
1839 | 1868 | |
|
1840 | 1869 | return line |
|
1841 | 1870 | |
|
1842 | 1871 | def write(self,data): |
|
1843 | 1872 | """Write a string to the default output""" |
|
1844 | 1873 | Term.cout.write(data) |
|
1845 | 1874 | |
|
1846 | 1875 | def write_err(self,data): |
|
1847 | 1876 | """Write a string to the default error output""" |
|
1848 | 1877 | Term.cerr.write(data) |
|
1849 | 1878 | |
|
1850 | 1879 | def exit(self): |
|
1851 | 1880 | """Handle interactive exit. |
|
1852 | 1881 | |
|
1853 | 1882 | This method sets the exit_now attribute.""" |
|
1854 | 1883 | |
|
1855 | 1884 | if self.rc.confirm_exit: |
|
1856 | 1885 | if ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
1857 | 1886 | self.exit_now = True |
|
1858 | 1887 | else: |
|
1859 | 1888 | self.exit_now = True |
|
1860 | 1889 | return self.exit_now |
|
1861 | 1890 | |
|
1862 | 1891 | def safe_execfile(self,fname,*where,**kw): |
|
1863 | 1892 | fname = os.path.expanduser(fname) |
|
1864 | 1893 | |
|
1865 | 1894 | # find things also in current directory |
|
1866 | 1895 | dname = os.path.dirname(fname) |
|
1867 | 1896 | if not sys.path.count(dname): |
|
1868 | 1897 | sys.path.append(dname) |
|
1869 | 1898 | |
|
1870 | 1899 | try: |
|
1871 | 1900 | xfile = open(fname) |
|
1872 | 1901 | except: |
|
1873 | 1902 | print >> Term.cerr, \ |
|
1874 | 1903 | 'Could not open file <%s> for safe execution.' % fname |
|
1875 | 1904 | return None |
|
1876 | 1905 | |
|
1877 | 1906 | kw.setdefault('islog',0) |
|
1878 | 1907 | kw.setdefault('quiet',1) |
|
1879 | 1908 | kw.setdefault('exit_ignore',0) |
|
1880 | 1909 | first = xfile.readline() |
|
1881 | 1910 | _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip() |
|
1882 | 1911 | xfile.close() |
|
1883 | 1912 | # line by line execution |
|
1884 | 1913 | if first.startswith(_LOGHEAD) or kw['islog']: |
|
1885 | 1914 | print 'Loading log file <%s> one line at a time...' % fname |
|
1886 | 1915 | if kw['quiet']: |
|
1887 | 1916 | stdout_save = sys.stdout |
|
1888 | 1917 | sys.stdout = StringIO.StringIO() |
|
1889 | 1918 | try: |
|
1890 | 1919 | globs,locs = where[0:2] |
|
1891 | 1920 | except: |
|
1892 | 1921 | try: |
|
1893 | 1922 | globs = locs = where[0] |
|
1894 | 1923 | except: |
|
1895 | 1924 | globs = locs = globals() |
|
1896 | 1925 | badblocks = [] |
|
1897 | 1926 | |
|
1898 | 1927 | # we also need to identify indented blocks of code when replaying |
|
1899 | 1928 | # logs and put them together before passing them to an exec |
|
1900 | 1929 | # statement. This takes a bit of regexp and look-ahead work in the |
|
1901 | 1930 | # file. It's easiest if we swallow the whole thing in memory |
|
1902 | 1931 | # first, and manually walk through the lines list moving the |
|
1903 | 1932 | # counter ourselves. |
|
1904 | 1933 | indent_re = re.compile('\s+\S') |
|
1905 | 1934 | xfile = open(fname) |
|
1906 | 1935 | filelines = xfile.readlines() |
|
1907 | 1936 | xfile.close() |
|
1908 | 1937 | nlines = len(filelines) |
|
1909 | 1938 | lnum = 0 |
|
1910 | 1939 | while lnum < nlines: |
|
1911 | 1940 | line = filelines[lnum] |
|
1912 | 1941 | lnum += 1 |
|
1913 | 1942 | # don't re-insert logger status info into cache |
|
1914 | 1943 | if line.startswith('#log#'): |
|
1915 | 1944 | continue |
|
1916 | 1945 | elif line.startswith('#%s'% self.ESC_MAGIC): |
|
1917 | 1946 | self.update_cache(line[1:]) |
|
1918 | 1947 | line = magic2python(line) |
|
1919 | 1948 | elif line.startswith('#!'): |
|
1920 | 1949 | self.update_cache(line[1:]) |
|
1921 | 1950 | else: |
|
1922 | 1951 | # build a block of code (maybe a single line) for execution |
|
1923 | 1952 | block = line |
|
1924 | 1953 | try: |
|
1925 | 1954 | next = filelines[lnum] # lnum has already incremented |
|
1926 | 1955 | except: |
|
1927 | 1956 | next = None |
|
1928 | 1957 | while next and indent_re.match(next): |
|
1929 | 1958 | block += next |
|
1930 | 1959 | lnum += 1 |
|
1931 | 1960 | try: |
|
1932 | 1961 | next = filelines[lnum] |
|
1933 | 1962 | except: |
|
1934 | 1963 | next = None |
|
1935 | 1964 | # now execute the block of one or more lines |
|
1936 | 1965 | try: |
|
1937 | 1966 | exec block in globs,locs |
|
1938 | 1967 | self.update_cache(block.rstrip()) |
|
1939 | 1968 | except SystemExit: |
|
1940 | 1969 | pass |
|
1941 | 1970 | except: |
|
1942 | 1971 | badblocks.append(block.rstrip()) |
|
1943 | 1972 | if kw['quiet']: # restore stdout |
|
1944 | 1973 | sys.stdout.close() |
|
1945 | 1974 | sys.stdout = stdout_save |
|
1946 | 1975 | print 'Finished replaying log file <%s>' % fname |
|
1947 | 1976 | if badblocks: |
|
1948 | 1977 | print >> sys.stderr, ('\nThe following lines/blocks in file ' |
|
1949 | 1978 | '<%s> reported errors:' % fname) |
|
1950 | 1979 | |
|
1951 | 1980 | for badline in badblocks: |
|
1952 | 1981 | print >> sys.stderr, badline |
|
1953 | 1982 | else: # regular file execution |
|
1954 | 1983 | try: |
|
1955 | 1984 | execfile(fname,*where) |
|
1956 | 1985 | except SyntaxError: |
|
1957 |
etype, |
|
|
1986 | etype,evalue = sys.exc_info()[:2] | |
|
1958 | 1987 | self.SyntaxTB(etype,evalue,[]) |
|
1959 | 1988 | warn('Failure executing file: <%s>' % fname) |
|
1960 | 1989 | except SystemExit,status: |
|
1961 | 1990 | if not kw['exit_ignore']: |
|
1962 | 1991 | self.InteractiveTB() |
|
1963 | 1992 | warn('Failure executing file: <%s>' % fname) |
|
1964 | 1993 | except: |
|
1965 | 1994 | self.InteractiveTB() |
|
1966 | 1995 | warn('Failure executing file: <%s>' % fname) |
|
1967 | 1996 | |
|
1968 | 1997 | #************************* end of file <iplib.py> ***************************** |
@@ -1,739 +1,735 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | IPython -- An enhanced Interactive Python |
|
4 | 4 | |
|
5 | 5 | Requires Python 2.1 or better. |
|
6 | 6 | |
|
7 | 7 | This file contains the main make_IPython() starter function. |
|
8 | 8 | |
|
9 |
$Id: ipmaker.py 96 |
|
|
9 | $Id: ipmaker.py 965 2005-12-28 23:23:09Z fperez $""" | |
|
10 | 10 | |
|
11 | 11 | #***************************************************************************** |
|
12 | 12 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
13 | 13 | # |
|
14 | 14 | # Distributed under the terms of the BSD License. The full license is in |
|
15 | 15 | # the file COPYING, distributed as part of this software. |
|
16 | 16 | #***************************************************************************** |
|
17 | 17 | |
|
18 | 18 | from IPython import Release |
|
19 | 19 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
20 | 20 | __license__ = Release.license |
|
21 | 21 | __version__ = Release.version |
|
22 | 22 | |
|
23 | 23 | credits._Printer__data = """ |
|
24 | 24 | Python: %s |
|
25 | 25 | |
|
26 | 26 | IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users. |
|
27 | 27 | See http://ipython.scipy.org for more information.""" \ |
|
28 | 28 | % credits._Printer__data |
|
29 | 29 | |
|
30 | 30 | copyright._Printer__data += """ |
|
31 | 31 | |
|
32 | 32 | Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray. |
|
33 | 33 | All Rights Reserved.""" |
|
34 | 34 | |
|
35 | 35 | #**************************************************************************** |
|
36 | 36 | # Required modules |
|
37 | 37 | |
|
38 | 38 | # From the standard library |
|
39 | 39 | import __main__ |
|
40 | 40 | import __builtin__ |
|
41 | 41 | import os |
|
42 | 42 | import re |
|
43 | 43 | import sys |
|
44 | 44 | import types |
|
45 | 45 | from pprint import pprint,pformat |
|
46 | 46 | |
|
47 | 47 | # Our own |
|
48 | 48 | from IPython import DPyGetOpt |
|
49 | 49 | from IPython.Struct import Struct |
|
50 | 50 | from IPython.OutputTrap import OutputTrap |
|
51 | 51 | from IPython.ConfigLoader import ConfigLoader |
|
52 | 52 | from IPython.iplib import InteractiveShell,qw_lol,import_fail_info |
|
53 | 53 | from IPython.usage import cmd_line_usage,interactive_usage |
|
54 | 54 | from IPython.Prompts import CachedOutput |
|
55 | 55 | from IPython.genutils import * |
|
56 | 56 | |
|
57 | 57 | #----------------------------------------------------------------------------- |
|
58 | 58 | def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1, |
|
59 | 59 | rc_override=None,shell_class=InteractiveShell, |
|
60 | 60 | embedded=False,**kw): |
|
61 | 61 | """This is a dump of IPython into a single function. |
|
62 | 62 | |
|
63 | 63 | Later it will have to be broken up in a sensible manner. |
|
64 | 64 | |
|
65 | 65 | Arguments: |
|
66 | 66 | |
|
67 | 67 | - argv: a list similar to sys.argv[1:]. It should NOT contain the desired |
|
68 | 68 | script name, b/c DPyGetOpt strips the first argument only for the real |
|
69 | 69 | sys.argv. |
|
70 | 70 | |
|
71 | 71 | - user_ns: a dict to be used as the user's namespace.""" |
|
72 | 72 | |
|
73 | 73 | #---------------------------------------------------------------------- |
|
74 | 74 | # Defaults and initialization |
|
75 | 75 | |
|
76 | 76 | # For developer debugging, deactivates crash handler and uses pdb. |
|
77 | 77 | DEVDEBUG = False |
|
78 | 78 | |
|
79 | 79 | if argv is None: |
|
80 | 80 | argv = sys.argv |
|
81 | 81 | |
|
82 | 82 | # __IP is the main global that lives throughout and represents the whole |
|
83 | 83 | # application. If the user redefines it, all bets are off as to what |
|
84 | 84 | # happens. |
|
85 | 85 | |
|
86 | 86 | # __IP is the name of he global which the caller will have accessible as |
|
87 | 87 | # __IP.name. We set its name via the first parameter passed to |
|
88 | 88 | # InteractiveShell: |
|
89 | 89 | |
|
90 | 90 | IP = shell_class('__IP',user_ns=user_ns,user_global_ns=user_global_ns, |
|
91 | 91 | embedded=embedded,**kw) |
|
92 | 92 | |
|
93 | 93 | # Put 'help' in the user namespace |
|
94 | 94 | from site import _Helper |
|
95 | 95 | IP.user_ns['help'] = _Helper() |
|
96 | 96 | |
|
97 | ||
|
97 | 98 | if DEVDEBUG: |
|
98 | 99 | # For developer debugging only (global flag) |
|
99 | 100 | from IPython import ultraTB |
|
100 | 101 | sys.excepthook = ultraTB.VerboseTB(call_pdb=1) |
|
101 | else: | |
|
102 | # IPython itself shouldn't crash. This will produce a detailed | |
|
103 | # post-mortem if it does | |
|
104 | from IPython import CrashHandler | |
|
105 | sys.excepthook = CrashHandler.CrashHandler(IP) | |
|
106 | 102 | |
|
107 | 103 | IP.BANNER_PARTS = ['Python %s\n' |
|
108 | 104 | 'Type "copyright", "credits" or "license" ' |
|
109 | 105 | 'for more information.\n' |
|
110 | 106 | % (sys.version.split('\n')[0],), |
|
111 | 107 | "IPython %s -- An enhanced Interactive Python." |
|
112 | 108 | % (__version__,), |
|
113 | 109 | """? -> Introduction to IPython's features. |
|
114 | 110 | %magic -> Information about IPython's 'magic' % functions. |
|
115 | 111 | help -> Python's own help system. |
|
116 | 112 | object? -> Details about 'object'. ?object also works, ?? prints more. |
|
117 | 113 | """ ] |
|
118 | 114 | |
|
119 | 115 | IP.usage = interactive_usage |
|
120 | 116 | |
|
121 | 117 | # Platform-dependent suffix and directory names. We use _ipython instead |
|
122 | 118 | # of .ipython under win32 b/c there's software that breaks with .named |
|
123 | 119 | # directories on that platform. |
|
124 | 120 | if os.name == 'posix': |
|
125 | 121 | rc_suffix = '' |
|
126 | 122 | ipdir_def = '.ipython' |
|
127 | 123 | else: |
|
128 | 124 | rc_suffix = '.ini' |
|
129 | 125 | ipdir_def = '_ipython' |
|
130 | 126 | |
|
131 | 127 | # default directory for configuration |
|
132 | 128 | ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR', |
|
133 | 129 | os.path.join(IP.home_dir,ipdir_def))) |
|
134 | 130 | |
|
135 | 131 | # we need the directory where IPython itself is installed |
|
136 | 132 | import IPython |
|
137 | 133 | IPython_dir = os.path.dirname(IPython.__file__) |
|
138 | 134 | del IPython |
|
139 | 135 | |
|
140 | 136 | #------------------------------------------------------------------------- |
|
141 | 137 | # Command line handling |
|
142 | 138 | |
|
143 | 139 | # Valid command line options (uses DPyGetOpt syntax, like Perl's |
|
144 | 140 | # GetOpt::Long) |
|
145 | 141 | |
|
146 | 142 | # Any key not listed here gets deleted even if in the file (like session |
|
147 | 143 | # or profile). That's deliberate, to maintain the rc namespace clean. |
|
148 | 144 | |
|
149 | 145 | # Each set of options appears twice: under _conv only the names are |
|
150 | 146 | # listed, indicating which type they must be converted to when reading the |
|
151 | 147 | # ipythonrc file. And under DPyGetOpt they are listed with the regular |
|
152 | 148 | # DPyGetOpt syntax (=s,=i,:f,etc). |
|
153 | 149 | |
|
154 | 150 | # Make sure there's a space before each end of line (they get auto-joined!) |
|
155 | 151 | cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i ' |
|
156 | 152 | 'c=s classic|cl color_info! colors=s confirm_exit! ' |
|
157 | 153 | 'debug! deep_reload! editor=s log|l messages! nosep pdb! ' |
|
158 | 154 | 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s ' |
|
159 | 155 | 'quick screen_length|sl=i prompts_pad_left=i ' |
|
160 | 156 | 'logfile|lf=s logplay|lp=s profile|p=s ' |
|
161 | 157 | 'readline! readline_merge_completions! ' |
|
162 | 158 | 'readline_omit__names! ' |
|
163 | 159 | 'rcfile=s separate_in|si=s separate_out|so=s ' |
|
164 | 160 | 'separate_out2|so2=s xmode=s wildcards_case_sensitive! ' |
|
165 | 161 | 'magic_docstrings system_verbose! ' |
|
166 | 162 | 'multi_line_specials! ' |
|
167 | 163 | 'autoedit_syntax!') |
|
168 | 164 | |
|
169 | 165 | # Options that can *only* appear at the cmd line (not in rcfiles). |
|
170 | 166 | |
|
171 | 167 | # The "ignore" option is a kludge so that Emacs buffers don't crash, since |
|
172 | 168 | # the 'C-c !' command in emacs automatically appends a -i option at the end. |
|
173 | 169 | cmdline_only = ('help ignore|i ipythondir=s Version upgrade ' |
|
174 | 170 | 'gthread! qthread! wthread! pylab! tk!') |
|
175 | 171 | |
|
176 | 172 | # Build the actual name list to be used by DPyGetOpt |
|
177 | 173 | opts_names = qw(cmdline_opts) + qw(cmdline_only) |
|
178 | 174 | |
|
179 | 175 | # Set sensible command line defaults. |
|
180 | 176 | # This should have everything from cmdline_opts and cmdline_only |
|
181 | 177 | opts_def = Struct(autocall = 1, |
|
182 | 178 | autoedit_syntax = 1, |
|
183 | 179 | autoindent=0, |
|
184 | 180 | automagic = 1, |
|
185 | 181 | banner = 1, |
|
186 | 182 | cache_size = 1000, |
|
187 | 183 | c = '', |
|
188 | 184 | classic = 0, |
|
189 | 185 | colors = 'NoColor', |
|
190 | 186 | color_info = 0, |
|
191 | 187 | confirm_exit = 1, |
|
192 | 188 | debug = 0, |
|
193 | 189 | deep_reload = 0, |
|
194 | 190 | editor = '0', |
|
195 | 191 | help = 0, |
|
196 | 192 | ignore = 0, |
|
197 | 193 | ipythondir = ipythondir, |
|
198 | 194 | log = 0, |
|
199 | 195 | logfile = '', |
|
200 | 196 | logplay = '', |
|
201 | 197 | multi_line_specials = 1, |
|
202 | 198 | messages = 1, |
|
203 | 199 | nosep = 0, |
|
204 | 200 | pdb = 0, |
|
205 | 201 | pprint = 0, |
|
206 | 202 | profile = '', |
|
207 | 203 | prompt_in1 = 'In [\\#]: ', |
|
208 | 204 | prompt_in2 = ' .\\D.: ', |
|
209 | 205 | prompt_out = 'Out[\\#]: ', |
|
210 | 206 | prompts_pad_left = 1, |
|
211 | 207 | quick = 0, |
|
212 | 208 | readline = 1, |
|
213 | 209 | readline_merge_completions = 1, |
|
214 | 210 | readline_omit__names = 0, |
|
215 | 211 | rcfile = 'ipythonrc' + rc_suffix, |
|
216 | 212 | screen_length = 0, |
|
217 | 213 | separate_in = '\n', |
|
218 | 214 | separate_out = '\n', |
|
219 | 215 | separate_out2 = '', |
|
220 | 216 | system_verbose = 0, |
|
221 | 217 | gthread = 0, |
|
222 | 218 | qthread = 0, |
|
223 | 219 | wthread = 0, |
|
224 | 220 | pylab = 0, |
|
225 | 221 | tk = 0, |
|
226 | 222 | upgrade = 0, |
|
227 | 223 | Version = 0, |
|
228 | 224 | xmode = 'Verbose', |
|
229 | 225 | wildcards_case_sensitive = 1, |
|
230 | 226 | magic_docstrings = 0, # undocumented, for doc generation |
|
231 | 227 | ) |
|
232 | 228 | |
|
233 | 229 | # Things that will *only* appear in rcfiles (not at the command line). |
|
234 | 230 | # Make sure there's a space before each end of line (they get auto-joined!) |
|
235 | 231 | rcfile_opts = { qwflat: 'include import_mod import_all execfile ', |
|
236 | 232 | qw_lol: 'import_some ', |
|
237 | 233 | # for things with embedded whitespace: |
|
238 | 234 | list_strings:'execute alias readline_parse_and_bind ', |
|
239 | 235 | # Regular strings need no conversion: |
|
240 | 236 | None:'readline_remove_delims ', |
|
241 | 237 | } |
|
242 | 238 | # Default values for these |
|
243 | 239 | rc_def = Struct(include = [], |
|
244 | 240 | import_mod = [], |
|
245 | 241 | import_all = [], |
|
246 | 242 | import_some = [[]], |
|
247 | 243 | execute = [], |
|
248 | 244 | execfile = [], |
|
249 | 245 | alias = [], |
|
250 | 246 | readline_parse_and_bind = [], |
|
251 | 247 | readline_remove_delims = '', |
|
252 | 248 | ) |
|
253 | 249 | |
|
254 | 250 | # Build the type conversion dictionary from the above tables: |
|
255 | 251 | typeconv = rcfile_opts.copy() |
|
256 | 252 | typeconv.update(optstr2types(cmdline_opts)) |
|
257 | 253 | |
|
258 | 254 | # FIXME: the None key appears in both, put that back together by hand. Ugly! |
|
259 | 255 | typeconv[None] += ' ' + rcfile_opts[None] |
|
260 | 256 | |
|
261 | 257 | # Remove quotes at ends of all strings (used to protect spaces) |
|
262 | 258 | typeconv[unquote_ends] = typeconv[None] |
|
263 | 259 | del typeconv[None] |
|
264 | 260 | |
|
265 | 261 | # Build the list we'll use to make all config decisions with defaults: |
|
266 | 262 | opts_all = opts_def.copy() |
|
267 | 263 | opts_all.update(rc_def) |
|
268 | 264 | |
|
269 | 265 | # Build conflict resolver for recursive loading of config files: |
|
270 | 266 | # - preserve means the outermost file maintains the value, it is not |
|
271 | 267 | # overwritten if an included file has the same key. |
|
272 | 268 | # - add_flip applies + to the two values, so it better make sense to add |
|
273 | 269 | # those types of keys. But it flips them first so that things loaded |
|
274 | 270 | # deeper in the inclusion chain have lower precedence. |
|
275 | 271 | conflict = {'preserve': ' '.join([ typeconv[int], |
|
276 | 272 | typeconv[unquote_ends] ]), |
|
277 | 273 | 'add_flip': ' '.join([ typeconv[qwflat], |
|
278 | 274 | typeconv[qw_lol], |
|
279 | 275 | typeconv[list_strings] ]) |
|
280 | 276 | } |
|
281 | 277 | |
|
282 | 278 | # Now actually process the command line |
|
283 | 279 | getopt = DPyGetOpt.DPyGetOpt() |
|
284 | 280 | getopt.setIgnoreCase(0) |
|
285 | 281 | |
|
286 | 282 | getopt.parseConfiguration(opts_names) |
|
287 | 283 | |
|
288 | 284 | try: |
|
289 | 285 | getopt.processArguments(argv) |
|
290 | 286 | except: |
|
291 | 287 | print cmd_line_usage |
|
292 | 288 | warn('\nError in Arguments: ' + `sys.exc_value`) |
|
293 | 289 | sys.exit(1) |
|
294 | 290 | |
|
295 | 291 | # convert the options dict to a struct for much lighter syntax later |
|
296 | 292 | opts = Struct(getopt.optionValues) |
|
297 | 293 | args = getopt.freeValues |
|
298 | 294 | |
|
299 | 295 | # this is the struct (which has default values at this point) with which |
|
300 | 296 | # we make all decisions: |
|
301 | 297 | opts_all.update(opts) |
|
302 | 298 | |
|
303 | 299 | # Options that force an immediate exit |
|
304 | 300 | if opts_all.help: |
|
305 | 301 | page(cmd_line_usage) |
|
306 | 302 | sys.exit() |
|
307 | 303 | |
|
308 | 304 | if opts_all.Version: |
|
309 | 305 | print __version__ |
|
310 | 306 | sys.exit() |
|
311 | 307 | |
|
312 | 308 | if opts_all.magic_docstrings: |
|
313 | 309 | IP.magic_magic('-latex') |
|
314 | 310 | sys.exit() |
|
315 | 311 | |
|
316 | 312 | # Create user config directory if it doesn't exist. This must be done |
|
317 | 313 | # *after* getting the cmd line options. |
|
318 | 314 | if not os.path.isdir(opts_all.ipythondir): |
|
319 | 315 | IP.user_setup(opts_all.ipythondir,rc_suffix,'install') |
|
320 | 316 | |
|
321 | 317 | # upgrade user config files while preserving a copy of the originals |
|
322 | 318 | if opts_all.upgrade: |
|
323 | 319 | IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade') |
|
324 | 320 | |
|
325 | 321 | # check mutually exclusive options in the *original* command line |
|
326 | 322 | mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'), |
|
327 | 323 | qw('classic profile'),qw('classic rcfile')]) |
|
328 | 324 | |
|
329 | 325 | # default logfilename used when -log is called. |
|
330 | 326 | IP.LOGDEF = 'ipython.log' |
|
331 | 327 | |
|
332 | 328 | #--------------------------------------------------------------------------- |
|
333 | 329 | # Log replay |
|
334 | 330 | |
|
335 | 331 | # if -logplay, we need to 'become' the other session. That basically means |
|
336 | 332 | # replacing the current command line environment with that of the old |
|
337 | 333 | # session and moving on. |
|
338 | 334 | |
|
339 | 335 | # this is needed so that later we know we're in session reload mode, as |
|
340 | 336 | # opts_all will get overwritten: |
|
341 | 337 | load_logplay = 0 |
|
342 | 338 | |
|
343 | 339 | if opts_all.logplay: |
|
344 | 340 | load_logplay = opts_all.logplay |
|
345 | 341 | opts_debug_save = opts_all.debug |
|
346 | 342 | try: |
|
347 | 343 | logplay = open(opts_all.logplay) |
|
348 | 344 | except IOError: |
|
349 | 345 | if opts_all.debug: IP.InteractiveTB() |
|
350 | 346 | warn('Could not open logplay file '+`opts_all.logplay`) |
|
351 | 347 | # restore state as if nothing had happened and move on, but make |
|
352 | 348 | # sure that later we don't try to actually load the session file |
|
353 | 349 | logplay = None |
|
354 | 350 | load_logplay = 0 |
|
355 | 351 | del opts_all.logplay |
|
356 | 352 | else: |
|
357 | 353 | try: |
|
358 | 354 | logplay.readline() |
|
359 | 355 | logplay.readline(); |
|
360 | 356 | # this reloads that session's command line |
|
361 | 357 | cmd = logplay.readline()[6:] |
|
362 | 358 | exec cmd |
|
363 | 359 | # restore the true debug flag given so that the process of |
|
364 | 360 | # session loading itself can be monitored. |
|
365 | 361 | opts.debug = opts_debug_save |
|
366 | 362 | # save the logplay flag so later we don't overwrite the log |
|
367 | 363 | opts.logplay = load_logplay |
|
368 | 364 | # now we must update our own structure with defaults |
|
369 | 365 | opts_all.update(opts) |
|
370 | 366 | # now load args |
|
371 | 367 | cmd = logplay.readline()[6:] |
|
372 | 368 | exec cmd |
|
373 | 369 | logplay.close() |
|
374 | 370 | except: |
|
375 | 371 | logplay.close() |
|
376 | 372 | if opts_all.debug: IP.InteractiveTB() |
|
377 | 373 | warn("Logplay file lacking full configuration information.\n" |
|
378 | 374 | "I'll try to read it, but some things may not work.") |
|
379 | 375 | |
|
380 | 376 | #------------------------------------------------------------------------- |
|
381 | 377 | # set up output traps: catch all output from files, being run, modules |
|
382 | 378 | # loaded, etc. Then give it to the user in a clean form at the end. |
|
383 | 379 | |
|
384 | 380 | msg_out = 'Output messages. ' |
|
385 | 381 | msg_err = 'Error messages. ' |
|
386 | 382 | msg_sep = '\n' |
|
387 | 383 | msg = Struct(config = OutputTrap('Configuration Loader',msg_out, |
|
388 | 384 | msg_err,msg_sep,debug, |
|
389 | 385 | quiet_out=1), |
|
390 | 386 | user_exec = OutputTrap('User File Execution',msg_out, |
|
391 | 387 | msg_err,msg_sep,debug), |
|
392 | 388 | logplay = OutputTrap('Log Loader',msg_out, |
|
393 | 389 | msg_err,msg_sep,debug), |
|
394 | 390 | summary = '' |
|
395 | 391 | ) |
|
396 | 392 | |
|
397 | 393 | #------------------------------------------------------------------------- |
|
398 | 394 | # Process user ipythonrc-type configuration files |
|
399 | 395 | |
|
400 | 396 | # turn on output trapping and log to msg.config |
|
401 | 397 | # remember that with debug on, trapping is actually disabled |
|
402 | 398 | msg.config.trap_all() |
|
403 | 399 | |
|
404 | 400 | # look for rcfile in current or default directory |
|
405 | 401 | try: |
|
406 | 402 | opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir) |
|
407 | 403 | except IOError: |
|
408 | 404 | if opts_all.debug: IP.InteractiveTB() |
|
409 | 405 | warn('Configuration file %s not found. Ignoring request.' |
|
410 | 406 | % (opts_all.rcfile) ) |
|
411 | 407 | |
|
412 | 408 | # 'profiles' are a shorthand notation for config filenames |
|
413 | 409 | if opts_all.profile: |
|
414 | 410 | try: |
|
415 | 411 | opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile |
|
416 | 412 | + rc_suffix, |
|
417 | 413 | opts_all.ipythondir) |
|
418 | 414 | except IOError: |
|
419 | 415 | if opts_all.debug: IP.InteractiveTB() |
|
420 | 416 | opts.profile = '' # remove profile from options if invalid |
|
421 | 417 | warn('Profile configuration file %s not found. Ignoring request.' |
|
422 | 418 | % (opts_all.profile) ) |
|
423 | 419 | |
|
424 | 420 | # load the config file |
|
425 | 421 | rcfiledata = None |
|
426 | 422 | if opts_all.quick: |
|
427 | 423 | print 'Launching IPython in quick mode. No config file read.' |
|
428 | 424 | elif opts_all.classic: |
|
429 | 425 | print 'Launching IPython in classic mode. No config file read.' |
|
430 | 426 | elif opts_all.rcfile: |
|
431 | 427 | try: |
|
432 | 428 | cfg_loader = ConfigLoader(conflict) |
|
433 | 429 | rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv, |
|
434 | 430 | 'include',opts_all.ipythondir, |
|
435 | 431 | purge = 1, |
|
436 | 432 | unique = conflict['preserve']) |
|
437 | 433 | except: |
|
438 | 434 | IP.InteractiveTB() |
|
439 | 435 | warn('Problems loading configuration file '+ |
|
440 | 436 | `opts_all.rcfile`+ |
|
441 | 437 | '\nStarting with default -bare bones- configuration.') |
|
442 | 438 | else: |
|
443 | 439 | warn('No valid configuration file found in either currrent directory\n'+ |
|
444 | 440 | 'or in the IPython config. directory: '+`opts_all.ipythondir`+ |
|
445 | 441 | '\nProceeding with internal defaults.') |
|
446 | 442 | |
|
447 | 443 | #------------------------------------------------------------------------ |
|
448 | 444 | # Set exception handlers in mode requested by user. |
|
449 | 445 | otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode |
|
450 | 446 | IP.magic_xmode(opts_all.xmode) |
|
451 | 447 | otrap.release_out() |
|
452 | 448 | |
|
453 | 449 | #------------------------------------------------------------------------ |
|
454 | 450 | # Execute user config |
|
455 | 451 | |
|
456 | 452 | # Create a valid config structure with the right precedence order: |
|
457 | 453 | # defaults < rcfile < command line. This needs to be in the instance, so |
|
458 | 454 | # that method calls below that rely on it find it. |
|
459 | 455 | IP.rc = rc_def.copy() |
|
460 | 456 | |
|
461 | 457 | # Work with a local alias inside this routine to avoid unnecessary |
|
462 | 458 | # attribute lookups. |
|
463 | 459 | IP_rc = IP.rc |
|
464 | 460 | |
|
465 | 461 | IP_rc.update(opts_def) |
|
466 | 462 | if rcfiledata: |
|
467 | 463 | # now we can update |
|
468 | 464 | IP_rc.update(rcfiledata) |
|
469 | 465 | IP_rc.update(opts) |
|
470 | 466 | IP_rc.update(rc_override) |
|
471 | 467 | |
|
472 | 468 | # Store the original cmd line for reference: |
|
473 | 469 | IP_rc.opts = opts |
|
474 | 470 | IP_rc.args = args |
|
475 | 471 | |
|
476 | 472 | # create a *runtime* Struct like rc for holding parameters which may be |
|
477 | 473 | # created and/or modified by runtime user extensions. |
|
478 | 474 | IP.runtime_rc = Struct() |
|
479 | 475 | |
|
480 | 476 | # from this point on, all config should be handled through IP_rc, |
|
481 | 477 | # opts* shouldn't be used anymore. |
|
482 | 478 | |
|
483 | 479 | # add personal .ipython dir to sys.path so that users can put things in |
|
484 | 480 | # there for customization |
|
485 | 481 | sys.path.append(IP_rc.ipythondir) |
|
486 | 482 | sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran |
|
487 | 483 | |
|
488 | 484 | # update IP_rc with some special things that need manual |
|
489 | 485 | # tweaks. Basically options which affect other options. I guess this |
|
490 | 486 | # should just be written so that options are fully orthogonal and we |
|
491 | 487 | # wouldn't worry about this stuff! |
|
492 | 488 | |
|
493 | 489 | if IP_rc.classic: |
|
494 | 490 | IP_rc.quick = 1 |
|
495 | 491 | IP_rc.cache_size = 0 |
|
496 | 492 | IP_rc.pprint = 0 |
|
497 | 493 | IP_rc.prompt_in1 = '>>> ' |
|
498 | 494 | IP_rc.prompt_in2 = '... ' |
|
499 | 495 | IP_rc.prompt_out = '' |
|
500 | 496 | IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0' |
|
501 | 497 | IP_rc.colors = 'NoColor' |
|
502 | 498 | IP_rc.xmode = 'Plain' |
|
503 | 499 | |
|
504 | 500 | # configure readline |
|
505 | 501 | # Define the history file for saving commands in between sessions |
|
506 | 502 | if IP_rc.profile: |
|
507 | 503 | histfname = 'history-%s' % IP_rc.profile |
|
508 | 504 | else: |
|
509 | 505 | histfname = 'history' |
|
510 | 506 | IP.histfile = os.path.join(opts_all.ipythondir,histfname) |
|
511 | 507 | |
|
512 | 508 | # update exception handlers with rc file status |
|
513 | 509 | otrap.trap_out() # I don't want these messages ever. |
|
514 | 510 | IP.magic_xmode(IP_rc.xmode) |
|
515 | 511 | otrap.release_out() |
|
516 | 512 | |
|
517 | 513 | # activate logging if requested and not reloading a log |
|
518 | 514 | if IP_rc.logplay: |
|
519 | 515 | IP.magic_logstart(IP_rc.logplay + ' append') |
|
520 | 516 | elif IP_rc.logfile: |
|
521 | 517 | IP.magic_logstart(IP_rc.logfile) |
|
522 | 518 | elif IP_rc.log: |
|
523 | 519 | IP.magic_logstart() |
|
524 | 520 | |
|
525 | 521 | # find user editor so that it we don't have to look it up constantly |
|
526 | 522 | if IP_rc.editor.strip()=='0': |
|
527 | 523 | try: |
|
528 | 524 | ed = os.environ['EDITOR'] |
|
529 | 525 | except KeyError: |
|
530 | 526 | if os.name == 'posix': |
|
531 | 527 | ed = 'vi' # the only one guaranteed to be there! |
|
532 | 528 | else: |
|
533 | 529 | ed = 'notepad' # same in Windows! |
|
534 | 530 | IP_rc.editor = ed |
|
535 | 531 | |
|
536 | 532 | # Keep track of whether this is an embedded instance or not (useful for |
|
537 | 533 | # post-mortems). |
|
538 | 534 | IP_rc.embedded = IP.embedded |
|
539 | 535 | |
|
540 | 536 | # Recursive reload |
|
541 | 537 | try: |
|
542 | 538 | from IPython import deep_reload |
|
543 | 539 | if IP_rc.deep_reload: |
|
544 | 540 | __builtin__.reload = deep_reload.reload |
|
545 | 541 | else: |
|
546 | 542 | __builtin__.dreload = deep_reload.reload |
|
547 | 543 | del deep_reload |
|
548 | 544 | except ImportError: |
|
549 | 545 | pass |
|
550 | 546 | |
|
551 | 547 | # Save the current state of our namespace so that the interactive shell |
|
552 | 548 | # can later know which variables have been created by us from config files |
|
553 | 549 | # and loading. This way, loading a file (in any way) is treated just like |
|
554 | 550 | # defining things on the command line, and %who works as expected. |
|
555 | 551 | |
|
556 | 552 | # DON'T do anything that affects the namespace beyond this point! |
|
557 | 553 | IP.internal_ns.update(__main__.__dict__) |
|
558 | 554 | |
|
559 | 555 | #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who |
|
560 | 556 | |
|
561 | 557 | # Now run through the different sections of the users's config |
|
562 | 558 | if IP_rc.debug: |
|
563 | 559 | print 'Trying to execute the following configuration structure:' |
|
564 | 560 | print '(Things listed first are deeper in the inclusion tree and get' |
|
565 | 561 | print 'loaded first).\n' |
|
566 | 562 | pprint(IP_rc.__dict__) |
|
567 | 563 | |
|
568 | 564 | for mod in IP_rc.import_mod: |
|
569 | 565 | try: |
|
570 | 566 | exec 'import '+mod in IP.user_ns |
|
571 | 567 | except : |
|
572 | 568 | IP.InteractiveTB() |
|
573 | 569 | import_fail_info(mod) |
|
574 | 570 | |
|
575 | 571 | for mod_fn in IP_rc.import_some: |
|
576 | 572 | if mod_fn == []: break |
|
577 | 573 | mod,fn = mod_fn[0],','.join(mod_fn[1:]) |
|
578 | 574 | try: |
|
579 | 575 | exec 'from '+mod+' import '+fn in IP.user_ns |
|
580 | 576 | except : |
|
581 | 577 | IP.InteractiveTB() |
|
582 | 578 | import_fail_info(mod,fn) |
|
583 | 579 | |
|
584 | 580 | for mod in IP_rc.import_all: |
|
585 | 581 | try: |
|
586 | 582 | exec 'from '+mod+' import *' in IP.user_ns |
|
587 | 583 | except : |
|
588 | 584 | IP.InteractiveTB() |
|
589 | 585 | import_fail_info(mod) |
|
590 | 586 | |
|
591 | 587 | for code in IP_rc.execute: |
|
592 | 588 | try: |
|
593 | 589 | exec code in IP.user_ns |
|
594 | 590 | except: |
|
595 | 591 | IP.InteractiveTB() |
|
596 | 592 | warn('Failure executing code: ' + `code`) |
|
597 | 593 | |
|
598 | 594 | # Execute the files the user wants in ipythonrc |
|
599 | 595 | for file in IP_rc.execfile: |
|
600 | 596 | try: |
|
601 | 597 | file = filefind(file,sys.path+[IPython_dir]) |
|
602 | 598 | except IOError: |
|
603 | 599 | warn(itpl('File $file not found. Skipping it.')) |
|
604 | 600 | else: |
|
605 | 601 | IP.safe_execfile(os.path.expanduser(file),IP.user_ns) |
|
606 | 602 | |
|
607 | 603 | # release stdout and stderr and save config log into a global summary |
|
608 | 604 | msg.config.release_all() |
|
609 | 605 | if IP_rc.messages: |
|
610 | 606 | msg.summary += msg.config.summary_all() |
|
611 | 607 | |
|
612 | 608 | #------------------------------------------------------------------------ |
|
613 | 609 | # Setup interactive session |
|
614 | 610 | |
|
615 | 611 | # Now we should be fully configured. We can then execute files or load |
|
616 | 612 | # things only needed for interactive use. Then we'll open the shell. |
|
617 | 613 | |
|
618 | 614 | # Take a snapshot of the user namespace before opening the shell. That way |
|
619 | 615 | # we'll be able to identify which things were interactively defined and |
|
620 | 616 | # which were defined through config files. |
|
621 | 617 | IP.user_config_ns = IP.user_ns.copy() |
|
622 | 618 | |
|
623 | 619 | # Force reading a file as if it were a session log. Slower but safer. |
|
624 | 620 | if load_logplay: |
|
625 | 621 | print 'Replaying log...' |
|
626 | 622 | try: |
|
627 | 623 | if IP_rc.debug: |
|
628 | 624 | logplay_quiet = 0 |
|
629 | 625 | else: |
|
630 | 626 | logplay_quiet = 1 |
|
631 | 627 | |
|
632 | 628 | msg.logplay.trap_all() |
|
633 | 629 | IP.safe_execfile(load_logplay,IP.user_ns, |
|
634 | 630 | islog = 1, quiet = logplay_quiet) |
|
635 | 631 | msg.logplay.release_all() |
|
636 | 632 | if IP_rc.messages: |
|
637 | 633 | msg.summary += msg.logplay.summary_all() |
|
638 | 634 | except: |
|
639 | 635 | warn('Problems replaying logfile %s.' % load_logplay) |
|
640 | 636 | IP.InteractiveTB() |
|
641 | 637 | |
|
642 | 638 | # Load remaining files in command line |
|
643 | 639 | msg.user_exec.trap_all() |
|
644 | 640 | |
|
645 | 641 | # Do NOT execute files named in the command line as scripts to be loaded |
|
646 | 642 | # by embedded instances. Doing so has the potential for an infinite |
|
647 | 643 | # recursion if there are exceptions thrown in the process. |
|
648 | 644 | |
|
649 | 645 | # XXX FIXME: the execution of user files should be moved out to after |
|
650 | 646 | # ipython is fully initialized, just as if they were run via %run at the |
|
651 | 647 | # ipython prompt. This would also give them the benefit of ipython's |
|
652 | 648 | # nice tracebacks. |
|
653 | 649 | |
|
654 | 650 | if not embedded and IP_rc.args: |
|
655 | 651 | name_save = IP.user_ns['__name__'] |
|
656 | 652 | IP.user_ns['__name__'] = '__main__' |
|
657 | 653 | try: |
|
658 | 654 | # Set our own excepthook in case the user code tries to call it |
|
659 | 655 | # directly. This prevents triggering the IPython crash handler. |
|
660 | 656 | old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook |
|
661 | 657 | for run in args: |
|
662 | 658 | IP.safe_execfile(run,IP.user_ns) |
|
663 | 659 | finally: |
|
664 | 660 | # Reset our crash handler in place |
|
665 | 661 | sys.excepthook = old_excepthook |
|
666 | 662 | |
|
667 | 663 | IP.user_ns['__name__'] = name_save |
|
668 | 664 | |
|
669 | 665 | msg.user_exec.release_all() |
|
670 | 666 | if IP_rc.messages: |
|
671 | 667 | msg.summary += msg.user_exec.summary_all() |
|
672 | 668 | |
|
673 | 669 | # since we can't specify a null string on the cmd line, 0 is the equivalent: |
|
674 | 670 | if IP_rc.nosep: |
|
675 | 671 | IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0' |
|
676 | 672 | if IP_rc.separate_in == '0': IP_rc.separate_in = '' |
|
677 | 673 | if IP_rc.separate_out == '0': IP_rc.separate_out = '' |
|
678 | 674 | if IP_rc.separate_out2 == '0': IP_rc.separate_out2 = '' |
|
679 | 675 | IP_rc.separate_in = IP_rc.separate_in.replace('\\n','\n') |
|
680 | 676 | IP_rc.separate_out = IP_rc.separate_out.replace('\\n','\n') |
|
681 | 677 | IP_rc.separate_out2 = IP_rc.separate_out2.replace('\\n','\n') |
|
682 | 678 | |
|
683 | 679 | # Determine how many lines at the bottom of the screen are needed for |
|
684 | 680 | # showing prompts, so we can know wheter long strings are to be printed or |
|
685 | 681 | # paged: |
|
686 | 682 | num_lines_bot = IP_rc.separate_in.count('\n')+1 |
|
687 | 683 | IP_rc.screen_length = IP_rc.screen_length - num_lines_bot |
|
688 | 684 | # Initialize cache, set in/out prompts and printing system |
|
689 | 685 | IP.outputcache = CachedOutput(IP_rc.cache_size, |
|
690 | 686 | IP_rc.pprint, |
|
691 | 687 | input_sep = IP_rc.separate_in, |
|
692 | 688 | output_sep = IP_rc.separate_out, |
|
693 | 689 | output_sep2 = IP_rc.separate_out2, |
|
694 | 690 | ps1 = IP_rc.prompt_in1, |
|
695 | 691 | ps2 = IP_rc.prompt_in2, |
|
696 | 692 | ps_out = IP_rc.prompt_out, |
|
697 | 693 | user_ns = IP.user_ns, |
|
698 | 694 | input_hist = IP.input_hist, |
|
699 | 695 | pad_left = IP_rc.prompts_pad_left) |
|
700 | 696 | |
|
701 | 697 | # user may have over-ridden the default print hook: |
|
702 | 698 | try: |
|
703 | 699 | IP.outputcache.__class__.display = IP.hooks.display |
|
704 | 700 | except AttributeError: |
|
705 | 701 | pass |
|
706 | 702 | |
|
707 | 703 | # Set calling of pdb on exceptions |
|
708 | 704 | IP.InteractiveTB.call_pdb = IP_rc.pdb |
|
709 | 705 | |
|
710 | 706 | # I don't like assigning globally to sys, because it means when embedding |
|
711 | 707 | # instances, each embedded instance overrides the previous choice. But |
|
712 | 708 | # sys.displayhook seems to be called internally by exec, so I don't see a |
|
713 | 709 | # way around it. |
|
714 | 710 | sys.displayhook = IP.outputcache |
|
715 | 711 | |
|
716 | 712 | # we need to know globally if we're caching i/o or not |
|
717 | 713 | IP.do_full_cache = IP.outputcache.do_full_cache |
|
718 | 714 | |
|
719 | 715 | # configure startup banner |
|
720 | 716 | if IP_rc.c: # regular python doesn't print the banner with -c |
|
721 | 717 | IP_rc.banner = 0 |
|
722 | 718 | if IP_rc.banner: |
|
723 | 719 | BANN_P = IP.BANNER_PARTS |
|
724 | 720 | else: |
|
725 | 721 | BANN_P = [] |
|
726 | 722 | |
|
727 | 723 | if IP_rc.profile: BANN_P.append('IPython profile: %s\n' % IP_rc.profile) |
|
728 | 724 | |
|
729 | 725 | # add message log (possibly empty) |
|
730 | 726 | if msg.summary: BANN_P.append(msg.summary) |
|
731 | 727 | # Final banner is a string |
|
732 | 728 | IP.BANNER = '\n'.join(BANN_P) |
|
733 | 729 | |
|
734 | 730 | # Finalize the IPython instance. This assumes the rc structure is fully |
|
735 | 731 | # in place. |
|
736 | 732 | IP.post_config_initialization() |
|
737 | 733 | |
|
738 | 734 | return IP |
|
739 | 735 | #************************ end of file <ipmaker.py> ************************** |
@@ -1,796 +1,796 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 95 |
|
|
63 | $Id: ultraTB.py 965 2005-12-28 23:23:09Z fperez $""" | |
|
64 | 64 | |
|
65 | 65 | #***************************************************************************** |
|
66 | 66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
|
67 | 67 | # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu> |
|
68 | 68 | # |
|
69 | 69 | # Distributed under the terms of the BSD License. The full license is in |
|
70 | 70 | # the file COPYING, distributed as part of this software. |
|
71 | 71 | #***************************************************************************** |
|
72 | 72 | |
|
73 | 73 | from IPython import Release |
|
74 | 74 | __author__ = '%s <%s>\n%s <%s>' % (Release.authors['Nathan']+ |
|
75 | 75 | Release.authors['Fernando']) |
|
76 | 76 | __license__ = Release.license |
|
77 | 77 | |
|
78 | 78 | # Required modules |
|
79 | 79 | import inspect |
|
80 | 80 | import keyword |
|
81 | 81 | import linecache |
|
82 | 82 | import os |
|
83 | 83 | import pydoc |
|
84 | 84 | import string |
|
85 | 85 | import sys |
|
86 | 86 | import time |
|
87 | 87 | import tokenize |
|
88 | 88 | import traceback |
|
89 | 89 | import types |
|
90 | 90 | |
|
91 | 91 | # IPython's own modules |
|
92 | 92 | # Modified pdb which doesn't damage IPython's readline handling |
|
93 | 93 | from IPython import Debugger |
|
94 | 94 | from IPython.Struct import Struct |
|
95 | 95 | from IPython.excolors import ExceptionColors |
|
96 | 96 | from IPython.genutils import Term,uniq_stable,error,info |
|
97 | 97 | |
|
98 | 98 | #--------------------------------------------------------------------------- |
|
99 | 99 | # Code begins |
|
100 | 100 | |
|
101 | 101 | def inspect_error(): |
|
102 | 102 | """Print a message about internal inspect errors. |
|
103 | 103 | |
|
104 | 104 | These are unfortunately quite common.""" |
|
105 | 105 | |
|
106 | 106 | error('Internal Python error in the inspect module.\n' |
|
107 | 107 | 'Below is the traceback from this internal error.\n') |
|
108 | 108 | |
|
109 | 109 | class TBTools: |
|
110 | 110 | """Basic tools used by all traceback printer classes.""" |
|
111 | 111 | |
|
112 | 112 | def __init__(self,color_scheme = 'NoColor',call_pdb=False): |
|
113 | 113 | # Whether to call the interactive pdb debugger after printing |
|
114 | 114 | # tracebacks or not |
|
115 | 115 | self.call_pdb = call_pdb |
|
116 | 116 | |
|
117 | 117 | # Create color table |
|
118 | 118 | self.color_scheme_table = ExceptionColors |
|
119 | 119 | |
|
120 | 120 | self.set_colors(color_scheme) |
|
121 | 121 | self.old_scheme = color_scheme # save initial value for toggles |
|
122 | 122 | |
|
123 | 123 | if call_pdb: |
|
124 | 124 | self.pdb = Debugger.Pdb(self.color_scheme_table.active_scheme_name) |
|
125 | 125 | else: |
|
126 | 126 | self.pdb = None |
|
127 | 127 | |
|
128 | 128 | def set_colors(self,*args,**kw): |
|
129 | 129 | """Shorthand access to the color table scheme selector method.""" |
|
130 | 130 | |
|
131 | 131 | self.color_scheme_table.set_active_scheme(*args,**kw) |
|
132 | 132 | # for convenience, set Colors to the active scheme |
|
133 | 133 | self.Colors = self.color_scheme_table.active_colors |
|
134 | 134 | |
|
135 | 135 | def color_toggle(self): |
|
136 | 136 | """Toggle between the currently active color scheme and NoColor.""" |
|
137 | 137 | |
|
138 | 138 | if self.color_scheme_table.active_scheme_name == 'NoColor': |
|
139 | 139 | self.color_scheme_table.set_active_scheme(self.old_scheme) |
|
140 | 140 | self.Colors = self.color_scheme_table.active_colors |
|
141 | 141 | else: |
|
142 | 142 | self.old_scheme = self.color_scheme_table.active_scheme_name |
|
143 | 143 | self.color_scheme_table.set_active_scheme('NoColor') |
|
144 | 144 | self.Colors = self.color_scheme_table.active_colors |
|
145 | 145 | |
|
146 | 146 | #--------------------------------------------------------------------------- |
|
147 | 147 | class ListTB(TBTools): |
|
148 | 148 | """Print traceback information from a traceback list, with optional color. |
|
149 | 149 | |
|
150 | 150 | Calling: requires 3 arguments: |
|
151 | 151 | (etype, evalue, elist) |
|
152 | 152 | as would be obtained by: |
|
153 | 153 | etype, evalue, tb = sys.exc_info() |
|
154 | 154 | if tb: |
|
155 | 155 | elist = traceback.extract_tb(tb) |
|
156 | 156 | else: |
|
157 | 157 | elist = None |
|
158 | 158 | |
|
159 | 159 | It can thus be used by programs which need to process the traceback before |
|
160 | 160 | printing (such as console replacements based on the code module from the |
|
161 | 161 | standard library). |
|
162 | 162 | |
|
163 | 163 | Because they are meant to be called without a full traceback (only a |
|
164 | 164 | list), instances of this class can't call the interactive pdb debugger.""" |
|
165 | 165 | |
|
166 | 166 | def __init__(self,color_scheme = 'NoColor'): |
|
167 | 167 | TBTools.__init__(self,color_scheme = color_scheme,call_pdb=0) |
|
168 | 168 | |
|
169 | 169 | def __call__(self, etype, value, elist): |
|
170 | 170 | print >> Term.cerr, self.text(etype,value,elist) |
|
171 | 171 | |
|
172 | 172 | def text(self,etype, value, elist,context=5): |
|
173 | 173 | """Return a color formatted string with the traceback info.""" |
|
174 | 174 | |
|
175 | 175 | Colors = self.Colors |
|
176 | 176 | out_string = ['%s%s%s\n' % (Colors.topline,'-'*60,Colors.Normal)] |
|
177 | 177 | if elist: |
|
178 | 178 | out_string.append('Traceback %s(most recent call last)%s:' % \ |
|
179 | 179 | (Colors.normalEm, Colors.Normal) + '\n') |
|
180 | 180 | out_string.extend(self._format_list(elist)) |
|
181 | 181 | lines = self._format_exception_only(etype, value) |
|
182 | 182 | for line in lines[:-1]: |
|
183 | 183 | out_string.append(" "+line) |
|
184 | 184 | out_string.append(lines[-1]) |
|
185 | 185 | return ''.join(out_string) |
|
186 | 186 | |
|
187 | 187 | def _format_list(self, extracted_list): |
|
188 | 188 | """Format a list of traceback entry tuples for printing. |
|
189 | 189 | |
|
190 | 190 | Given a list of tuples as returned by extract_tb() or |
|
191 | 191 | extract_stack(), return a list of strings ready for printing. |
|
192 | 192 | Each string in the resulting list corresponds to the item with the |
|
193 | 193 | same index in the argument list. Each string ends in a newline; |
|
194 | 194 | the strings may contain internal newlines as well, for those items |
|
195 | 195 | whose source text line is not None. |
|
196 | 196 | |
|
197 | 197 | Lifted almost verbatim from traceback.py |
|
198 | 198 | """ |
|
199 | 199 | |
|
200 | 200 | Colors = self.Colors |
|
201 | 201 | list = [] |
|
202 | 202 | for filename, lineno, name, line in extracted_list[:-1]: |
|
203 | 203 | item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \ |
|
204 | 204 | (Colors.filename, filename, Colors.Normal, |
|
205 | 205 | Colors.lineno, lineno, Colors.Normal, |
|
206 | 206 | Colors.name, name, Colors.Normal) |
|
207 | 207 | if line: |
|
208 | 208 | item = item + ' %s\n' % line.strip() |
|
209 | 209 | list.append(item) |
|
210 | 210 | # Emphasize the last entry |
|
211 | 211 | filename, lineno, name, line = extracted_list[-1] |
|
212 | 212 | item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \ |
|
213 | 213 | (Colors.normalEm, |
|
214 | 214 | Colors.filenameEm, filename, Colors.normalEm, |
|
215 | 215 | Colors.linenoEm, lineno, Colors.normalEm, |
|
216 | 216 | Colors.nameEm, name, Colors.normalEm, |
|
217 | 217 | Colors.Normal) |
|
218 | 218 | if line: |
|
219 | 219 | item = item + '%s %s%s\n' % (Colors.line, line.strip(), |
|
220 | 220 | Colors.Normal) |
|
221 | 221 | list.append(item) |
|
222 | 222 | return list |
|
223 | 223 | |
|
224 | 224 | def _format_exception_only(self, etype, value): |
|
225 | 225 | """Format the exception part of a traceback. |
|
226 | 226 | |
|
227 | 227 | The arguments are the exception type and value such as given by |
|
228 | 228 | sys.last_type and sys.last_value. The return value is a list of |
|
229 | 229 | strings, each ending in a newline. Normally, the list contains a |
|
230 | 230 | single string; however, for SyntaxError exceptions, it contains |
|
231 | 231 | several lines that (when printed) display detailed information |
|
232 | 232 | about where the syntax error occurred. The message indicating |
|
233 | 233 | which exception occurred is the always last string in the list. |
|
234 | 234 | |
|
235 | 235 | Also lifted nearly verbatim from traceback.py |
|
236 | 236 | """ |
|
237 | 237 | |
|
238 | 238 | Colors = self.Colors |
|
239 | 239 | list = [] |
|
240 | 240 | if type(etype) == types.ClassType: |
|
241 | 241 | stype = Colors.excName + etype.__name__ + Colors.Normal |
|
242 | 242 | else: |
|
243 | 243 | stype = etype # String exceptions don't get special coloring |
|
244 | 244 | if value is None: |
|
245 | 245 | list.append( str(stype) + '\n') |
|
246 | 246 | else: |
|
247 | 247 | if etype is SyntaxError: |
|
248 | 248 | try: |
|
249 | 249 | msg, (filename, lineno, offset, line) = value |
|
250 | 250 | except: |
|
251 | 251 | pass |
|
252 | 252 | else: |
|
253 | 253 | #print 'filename is',filename # dbg |
|
254 | 254 | if not filename: filename = "<string>" |
|
255 | 255 | list.append('%s File %s"%s"%s, line %s%d%s\n' % \ |
|
256 | 256 | (Colors.normalEm, |
|
257 | 257 | Colors.filenameEm, filename, Colors.normalEm, |
|
258 | 258 | Colors.linenoEm, lineno, Colors.Normal )) |
|
259 | 259 | if line is not None: |
|
260 | 260 | i = 0 |
|
261 | 261 | while i < len(line) and line[i].isspace(): |
|
262 | 262 | i = i+1 |
|
263 | 263 | list.append('%s %s%s\n' % (Colors.line, |
|
264 | 264 | line.strip(), |
|
265 | 265 | Colors.Normal)) |
|
266 | 266 | if offset is not None: |
|
267 | 267 | s = ' ' |
|
268 | 268 | for c in line[i:offset-1]: |
|
269 | 269 | if c.isspace(): |
|
270 | 270 | s = s + c |
|
271 | 271 | else: |
|
272 | 272 | s = s + ' ' |
|
273 | 273 | list.append('%s%s^%s\n' % (Colors.caret, s, |
|
274 | 274 | Colors.Normal) ) |
|
275 | 275 | value = msg |
|
276 | 276 | s = self._some_str(value) |
|
277 | 277 | if s: |
|
278 | 278 | list.append('%s%s:%s %s\n' % (str(stype), Colors.excName, |
|
279 | 279 | Colors.Normal, s)) |
|
280 | 280 | else: |
|
281 | 281 | list.append('%s\n' % str(stype)) |
|
282 | 282 | return list |
|
283 | 283 | |
|
284 | 284 | def _some_str(self, value): |
|
285 | 285 | # Lifted from traceback.py |
|
286 | 286 | try: |
|
287 | 287 | return str(value) |
|
288 | 288 | except: |
|
289 | 289 | return '<unprintable %s object>' % type(value).__name__ |
|
290 | 290 | |
|
291 | 291 | #---------------------------------------------------------------------------- |
|
292 | 292 | class VerboseTB(TBTools): |
|
293 | 293 | """A port of Ka-Ping Yee's cgitb.py module that outputs color text instead |
|
294 | 294 | of HTML. Requires inspect and pydoc. Crazy, man. |
|
295 | 295 | |
|
296 | 296 | Modified version which optionally strips the topmost entries from the |
|
297 | 297 | traceback, to be used with alternate interpreters (because their own code |
|
298 | 298 | would appear in the traceback).""" |
|
299 | 299 | |
|
300 | 300 | def __init__(self,color_scheme = 'Linux',tb_offset=0,long_header=0, |
|
301 | 301 | call_pdb = 0, include_vars=1): |
|
302 | 302 | """Specify traceback offset, headers and color scheme. |
|
303 | 303 | |
|
304 | 304 | Define how many frames to drop from the tracebacks. Calling it with |
|
305 | 305 | tb_offset=1 allows use of this handler in interpreters which will have |
|
306 | 306 | their own code at the top of the traceback (VerboseTB will first |
|
307 | 307 | remove that frame before printing the traceback info).""" |
|
308 | 308 | TBTools.__init__(self,color_scheme=color_scheme,call_pdb=call_pdb) |
|
309 | 309 | self.tb_offset = tb_offset |
|
310 | 310 | self.long_header = long_header |
|
311 | 311 | self.include_vars = include_vars |
|
312 | 312 | |
|
313 | 313 | def text(self, etype, evalue, etb, context=5): |
|
314 | 314 | """Return a nice text document describing the traceback.""" |
|
315 | 315 | |
|
316 | 316 | # some locals |
|
317 | 317 | Colors = self.Colors # just a shorthand + quicker name lookup |
|
318 | 318 | ColorsNormal = Colors.Normal # used a lot |
|
319 | 319 | indent_size = 8 # we need some space to put line numbers before |
|
320 | 320 | indent = ' '*indent_size |
|
321 | 321 | numbers_width = indent_size - 1 # leave space between numbers & code |
|
322 | 322 | text_repr = pydoc.text.repr |
|
323 | 323 | exc = '%s%s%s' % (Colors.excName, str(etype), ColorsNormal) |
|
324 | 324 | em_normal = '%s\n%s%s' % (Colors.valEm, indent,ColorsNormal) |
|
325 | 325 | undefined = '%sundefined%s' % (Colors.em, ColorsNormal) |
|
326 | 326 | |
|
327 | 327 | # some internal-use functions |
|
328 | 328 | def eqrepr(value, repr=text_repr): return '=%s' % repr(value) |
|
329 | 329 | def nullrepr(value, repr=text_repr): return '' |
|
330 | 330 | |
|
331 | 331 | # meat of the code begins |
|
332 | 332 | if type(etype) is types.ClassType: |
|
333 | 333 | etype = etype.__name__ |
|
334 | 334 | |
|
335 | 335 | if self.long_header: |
|
336 | 336 | # Header with the exception type, python version, and date |
|
337 | 337 | pyver = 'Python ' + string.split(sys.version)[0] + ': ' + sys.executable |
|
338 | 338 | date = time.ctime(time.time()) |
|
339 | 339 | |
|
340 | 340 | head = '%s%s%s\n%s%s%s\n%s' % (Colors.topline, '-'*75, ColorsNormal, |
|
341 | 341 | exc, ' '*(75-len(str(etype))-len(pyver)), |
|
342 | 342 | pyver, string.rjust(date, 75) ) |
|
343 | 343 | head += "\nA problem occured executing Python code. Here is the sequence of function"\ |
|
344 | 344 | "\ncalls leading up to the error, with the most recent (innermost) call last." |
|
345 | 345 | else: |
|
346 | 346 | # Simplified header |
|
347 | 347 | head = '%s%s%s\n%s%s' % (Colors.topline, '-'*75, ColorsNormal,exc, |
|
348 | 348 | string.rjust('Traceback (most recent call last)', |
|
349 | 349 | 75 - len(str(etype)) ) ) |
|
350 | 350 | frames = [] |
|
351 | 351 | # Flush cache before calling inspect. This helps alleviate some of the |
|
352 | 352 | # problems with python 2.3's inspect.py. |
|
353 | 353 | linecache.checkcache() |
|
354 | 354 | # Drop topmost frames if requested |
|
355 | 355 | try: |
|
356 | 356 | records = inspect.getinnerframes(etb, context)[self.tb_offset:] |
|
357 | 357 | except: |
|
358 | 358 | |
|
359 | 359 | # FIXME: I've been getting many crash reports from python 2.3 |
|
360 | 360 | # users, traceable to inspect.py. If I can find a small test-case |
|
361 | 361 | # to reproduce this, I should either write a better workaround or |
|
362 | 362 | # file a bug report against inspect (if that's the real problem). |
|
363 | 363 | # So far, I haven't been able to find an isolated example to |
|
364 | 364 | # reproduce the problem. |
|
365 | 365 | inspect_error() |
|
366 | 366 | traceback.print_exc(file=Term.cerr) |
|
367 | 367 | info('\nUnfortunately, your original traceback can not be constructed.\n') |
|
368 | 368 | return '' |
|
369 | 369 | |
|
370 | 370 | # build some color string templates outside these nested loops |
|
371 | 371 | tpl_link = '%s%%s%s' % (Colors.filenameEm,ColorsNormal) |
|
372 | 372 | tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, |
|
373 | 373 | ColorsNormal) |
|
374 | 374 | tpl_call_fail = 'in %s%%s%s(***failed resolving arguments***)%s' % \ |
|
375 | 375 | (Colors.vName, Colors.valEm, ColorsNormal) |
|
376 | 376 | tpl_local_var = '%s%%s%s' % (Colors.vName, ColorsNormal) |
|
377 | 377 | tpl_global_var = '%sglobal%s %s%%s%s' % (Colors.em, ColorsNormal, |
|
378 | 378 | Colors.vName, ColorsNormal) |
|
379 | 379 | tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal) |
|
380 | 380 | tpl_line = '%s%%s%s %%s' % (Colors.lineno, ColorsNormal) |
|
381 | 381 | tpl_line_em = '%s%%s%s %%s%s' % (Colors.linenoEm,Colors.line, |
|
382 | 382 | ColorsNormal) |
|
383 | 383 | |
|
384 | 384 | # now, loop over all records printing context and info |
|
385 | 385 | abspath = os.path.abspath |
|
386 | 386 | for frame, file, lnum, func, lines, index in records: |
|
387 | 387 | #print '*** record:',file,lnum,func,lines,index # dbg |
|
388 | 388 | try: |
|
389 | 389 | file = file and abspath(file) or '?' |
|
390 | 390 | except OSError: |
|
391 | 391 | # if file is '<console>' or something not in the filesystem, |
|
392 | 392 | # the abspath call will throw an OSError. Just ignore it and |
|
393 | 393 | # keep the original file string. |
|
394 | 394 | pass |
|
395 | 395 | link = tpl_link % file |
|
396 | 396 | try: |
|
397 | 397 | args, varargs, varkw, locals = inspect.getargvalues(frame) |
|
398 | 398 | except: |
|
399 | 399 | # This can happen due to a bug in python2.3. We should be |
|
400 | 400 | # able to remove this try/except when 2.4 becomes a |
|
401 | 401 | # requirement. Bug details at http://python.org/sf/1005466 |
|
402 | 402 | inspect_error() |
|
403 | 403 | traceback.print_exc(file=Term.cerr) |
|
404 | 404 | info("\nIPython's exception reporting continues...\n") |
|
405 | 405 | |
|
406 | 406 | if func == '?': |
|
407 | 407 | call = '' |
|
408 | 408 | else: |
|
409 | 409 | # Decide whether to include variable details or not |
|
410 | 410 | var_repr = self.include_vars and eqrepr or nullrepr |
|
411 | 411 | try: |
|
412 | 412 | call = tpl_call % (func,inspect.formatargvalues(args, |
|
413 | 413 | varargs, varkw, |
|
414 | 414 | locals,formatvalue=var_repr)) |
|
415 | 415 | except KeyError: |
|
416 | 416 | # Very odd crash from inspect.formatargvalues(). The |
|
417 | 417 | # scenario under which it appeared was a call to |
|
418 | 418 | # view(array,scale) in NumTut.view.view(), where scale had |
|
419 | 419 | # been defined as a scalar (it should be a tuple). Somehow |
|
420 | 420 | # inspect messes up resolving the argument list of view() |
|
421 | 421 | # and barfs out. At some point I should dig into this one |
|
422 | 422 | # and file a bug report about it. |
|
423 | 423 | inspect_error() |
|
424 | 424 | traceback.print_exc(file=Term.cerr) |
|
425 | 425 | info("\nIPython's exception reporting continues...\n") |
|
426 | 426 | call = tpl_call_fail % func |
|
427 | 427 | |
|
428 | 428 | # Initialize a list of names on the current line, which the |
|
429 | 429 | # tokenizer below will populate. |
|
430 | 430 | names = [] |
|
431 | 431 | |
|
432 | 432 | def tokeneater(token_type, token, start, end, line): |
|
433 | 433 | """Stateful tokeneater which builds dotted names. |
|
434 | 434 | |
|
435 | 435 | The list of names it appends to (from the enclosing scope) can |
|
436 | 436 | contain repeated composite names. This is unavoidable, since |
|
437 | 437 | there is no way to disambguate partial dotted structures until |
|
438 | 438 | the full list is known. The caller is responsible for pruning |
|
439 | 439 | the final list of duplicates before using it.""" |
|
440 | 440 | |
|
441 | 441 | # build composite names |
|
442 | 442 | if token == '.': |
|
443 | 443 | try: |
|
444 | 444 | names[-1] += '.' |
|
445 | 445 | # store state so the next token is added for x.y.z names |
|
446 | 446 | tokeneater.name_cont = True |
|
447 | 447 | return |
|
448 | 448 | except IndexError: |
|
449 | 449 | pass |
|
450 | 450 | if token_type == tokenize.NAME and token not in keyword.kwlist: |
|
451 | 451 | if tokeneater.name_cont: |
|
452 | 452 | # Dotted names |
|
453 | 453 | names[-1] += token |
|
454 | 454 | tokeneater.name_cont = False |
|
455 | 455 | else: |
|
456 | 456 | # Regular new names. We append everything, the caller |
|
457 | 457 | # will be responsible for pruning the list later. It's |
|
458 | 458 | # very tricky to try to prune as we go, b/c composite |
|
459 | 459 | # names can fool us. The pruning at the end is easy |
|
460 | 460 | # to do (or the caller can print a list with repeated |
|
461 | 461 | # names if so desired. |
|
462 | 462 | names.append(token) |
|
463 | 463 | elif token_type == tokenize.NEWLINE: |
|
464 | 464 | raise IndexError |
|
465 | 465 | # we need to store a bit of state in the tokenizer to build |
|
466 | 466 | # dotted names |
|
467 | 467 | tokeneater.name_cont = False |
|
468 | 468 | |
|
469 | 469 | def linereader(file=file, lnum=[lnum], getline=linecache.getline): |
|
470 | 470 | line = getline(file, lnum[0]) |
|
471 | 471 | lnum[0] += 1 |
|
472 | 472 | return line |
|
473 | 473 | |
|
474 | 474 | # Build the list of names on this line of code where the exception |
|
475 | 475 | # occurred. |
|
476 | 476 | try: |
|
477 | 477 | # This builds the names list in-place by capturing it from the |
|
478 | 478 | # enclosing scope. |
|
479 | 479 | tokenize.tokenize(linereader, tokeneater) |
|
480 | 480 | except IndexError: |
|
481 | 481 | # signals exit of tokenizer |
|
482 | 482 | pass |
|
483 | 483 | except tokenize.TokenError,msg: |
|
484 | 484 | _m = ("An unexpected error occurred while tokenizing input\n" |
|
485 | 485 | "The following traceback may be corrupted or invalid\n" |
|
486 | 486 | "The error message is: %s\n" % msg) |
|
487 | 487 | error(_m) |
|
488 | 488 | |
|
489 | 489 | # prune names list of duplicates, but keep the right order |
|
490 | 490 | unique_names = uniq_stable(names) |
|
491 | 491 | |
|
492 | 492 | # Start loop over vars |
|
493 | 493 | lvals = [] |
|
494 | 494 | if self.include_vars: |
|
495 | 495 | for name_full in unique_names: |
|
496 | 496 | name_base = name_full.split('.',1)[0] |
|
497 | 497 | if name_base in frame.f_code.co_varnames: |
|
498 | 498 | if locals.has_key(name_base): |
|
499 | 499 | try: |
|
500 | 500 | value = repr(eval(name_full,locals)) |
|
501 | 501 | except: |
|
502 | 502 | value = undefined |
|
503 | 503 | else: |
|
504 | 504 | value = undefined |
|
505 | 505 | name = tpl_local_var % name_full |
|
506 | 506 | else: |
|
507 | 507 | if frame.f_globals.has_key(name_base): |
|
508 | 508 | try: |
|
509 | 509 | value = repr(eval(name_full,frame.f_globals)) |
|
510 | 510 | except: |
|
511 | 511 | value = undefined |
|
512 | 512 | else: |
|
513 | 513 | value = undefined |
|
514 | 514 | name = tpl_global_var % name_full |
|
515 | 515 | lvals.append(tpl_name_val % (name,value)) |
|
516 | 516 | if lvals: |
|
517 | 517 | lvals = '%s%s' % (indent,em_normal.join(lvals)) |
|
518 | 518 | else: |
|
519 | 519 | lvals = '' |
|
520 | 520 | |
|
521 | 521 | level = '%s %s\n' % (link,call) |
|
522 | 522 | excerpt = [] |
|
523 | 523 | if index is not None: |
|
524 | 524 | i = lnum - index |
|
525 | 525 | for line in lines: |
|
526 | 526 | if i == lnum: |
|
527 | 527 | # This is the line with the error |
|
528 | 528 | pad = numbers_width - len(str(i)) |
|
529 | 529 | if pad >= 3: |
|
530 | 530 | marker = '-'*(pad-3) + '-> ' |
|
531 | 531 | elif pad == 2: |
|
532 | 532 | marker = '> ' |
|
533 | 533 | elif pad == 1: |
|
534 | 534 | marker = '>' |
|
535 | 535 | else: |
|
536 | 536 | marker = '' |
|
537 | 537 | num = '%s%s' % (marker,i) |
|
538 | 538 | line = tpl_line_em % (num,line) |
|
539 | 539 | else: |
|
540 | 540 | num = '%*s' % (numbers_width,i) |
|
541 | 541 | line = tpl_line % (num,line) |
|
542 | 542 | |
|
543 | 543 | excerpt.append(line) |
|
544 | 544 | if self.include_vars and i == lnum: |
|
545 | 545 | excerpt.append('%s\n' % lvals) |
|
546 | 546 | i += 1 |
|
547 | 547 | frames.append('%s%s' % (level,''.join(excerpt)) ) |
|
548 | 548 | |
|
549 | 549 | # Get (safely) a string form of the exception info |
|
550 | 550 | try: |
|
551 | 551 | etype_str,evalue_str = map(str,(etype,evalue)) |
|
552 | 552 | except: |
|
553 | 553 | # User exception is improperly defined. |
|
554 | 554 | etype,evalue = str,sys.exc_info()[:2] |
|
555 | 555 | etype_str,evalue_str = map(str,(etype,evalue)) |
|
556 | 556 | # ... and format it |
|
557 | 557 | exception = ['%s%s%s: %s' % (Colors.excName, etype_str, |
|
558 | 558 | ColorsNormal, evalue_str)] |
|
559 | 559 | if type(evalue) is types.InstanceType: |
|
560 | 560 | try: |
|
561 | 561 | names = [w for w in dir(evalue) if isinstance(w, basestring)] |
|
562 | 562 | except: |
|
563 | 563 | # Every now and then, an object with funny inernals blows up |
|
564 | 564 | # when dir() is called on it. We do the best we can to report |
|
565 | 565 | # the problem and continue |
|
566 | 566 | _m = '%sException reporting error (object with broken dir())%s:' |
|
567 | 567 | exception.append(_m % (Colors.excName,ColorsNormal)) |
|
568 | 568 | etype_str,evalue_str = map(str,sys.exc_info()[:2]) |
|
569 | 569 | exception.append('%s%s%s: %s' % (Colors.excName,etype_str, |
|
570 | 570 | ColorsNormal, evalue_str)) |
|
571 | 571 | names = [] |
|
572 | 572 | for name in names: |
|
573 | 573 | value = text_repr(getattr(evalue, name)) |
|
574 | 574 | exception.append('\n%s%s = %s' % (indent, name, value)) |
|
575 | 575 | # return all our info assembled as a single string |
|
576 | 576 | return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) ) |
|
577 | 577 | |
|
578 | 578 | def debugger(self): |
|
579 | 579 | """Call up the pdb debugger if desired, always clean up the tb reference. |
|
580 | 580 | |
|
581 | 581 | If the call_pdb flag is set, the pdb interactive debugger is |
|
582 | 582 | invoked. In all cases, the self.tb reference to the current traceback |
|
583 | 583 | is deleted to prevent lingering references which hamper memory |
|
584 | 584 | management. |
|
585 | 585 | |
|
586 | 586 | Note that each call to pdb() does an 'import readline', so if your app |
|
587 | 587 | requires a special setup for the readline completers, you'll have to |
|
588 | 588 | fix that by hand after invoking the exception handler.""" |
|
589 | 589 | |
|
590 | 590 | if self.call_pdb: |
|
591 | 591 | if self.pdb is None: |
|
592 | 592 | self.pdb = Debugger.Pdb( |
|
593 | 593 | self.color_scheme_table.active_scheme_name) |
|
594 | 594 | # the system displayhook may have changed, restore the original |
|
595 | 595 | # for pdb |
|
596 | 596 | dhook = sys.displayhook |
|
597 | 597 | sys.displayhook = sys.__displayhook__ |
|
598 | 598 | self.pdb.reset() |
|
599 | 599 | # Find the right frame so we don't pop up inside ipython itself |
|
600 | 600 | etb = self.tb |
|
601 | 601 | while self.tb.tb_next is not None: |
|
602 | 602 | self.tb = self.tb.tb_next |
|
603 | 603 | try: |
|
604 | 604 | if etb and etb.tb_next: |
|
605 | 605 | etb = etb.tb_next |
|
606 | 606 | self.pdb.botframe = etb.tb_frame |
|
607 | 607 | self.pdb.interaction(self.tb.tb_frame, self.tb) |
|
608 | 608 | except: |
|
609 | 609 | print '*** ERROR ***' |
|
610 | 610 | print 'This version of pdb has a bug and crashed.' |
|
611 | 611 | print 'Returning to IPython...' |
|
612 | 612 | sys.displayhook = dhook |
|
613 | 613 | del self.tb |
|
614 | 614 | |
|
615 | 615 | def handler(self, info=None): |
|
616 | 616 | (etype, evalue, etb) = info or sys.exc_info() |
|
617 | 617 | self.tb = etb |
|
618 | 618 | print >> Term.cerr, self.text(etype, evalue, etb) |
|
619 | 619 | |
|
620 | 620 | # Changed so an instance can just be called as VerboseTB_inst() and print |
|
621 | 621 | # out the right info on its own. |
|
622 | 622 | def __call__(self, etype=None, evalue=None, etb=None): |
|
623 | 623 | """This hook can replace sys.excepthook (for Python 2.1 or higher).""" |
|
624 |
if etb is |
|
|
625 | self.handler((etype, evalue, etb)) | |
|
626 | else: | |
|
624 | if etb is None: | |
|
627 | 625 | self.handler() |
|
626 | else: | |
|
627 | self.handler((etype, evalue, etb)) | |
|
628 | 628 | self.debugger() |
|
629 | 629 | |
|
630 | 630 | #---------------------------------------------------------------------------- |
|
631 | 631 | class FormattedTB(VerboseTB,ListTB): |
|
632 | 632 | """Subclass ListTB but allow calling with a traceback. |
|
633 | 633 | |
|
634 | 634 | It can thus be used as a sys.excepthook for Python > 2.1. |
|
635 | 635 | |
|
636 | 636 | Also adds 'Context' and 'Verbose' modes, not available in ListTB. |
|
637 | 637 | |
|
638 | 638 | Allows a tb_offset to be specified. This is useful for situations where |
|
639 | 639 | one needs to remove a number of topmost frames from the traceback (such as |
|
640 | 640 | occurs with python programs that themselves execute other python code, |
|
641 | 641 | like Python shells). """ |
|
642 | 642 | |
|
643 | 643 | def __init__(self, mode = 'Plain', color_scheme='Linux', |
|
644 | 644 | tb_offset = 0,long_header=0,call_pdb=0,include_vars=0): |
|
645 | 645 | |
|
646 | 646 | # NEVER change the order of this list. Put new modes at the end: |
|
647 | 647 | self.valid_modes = ['Plain','Context','Verbose'] |
|
648 | 648 | self.verbose_modes = self.valid_modes[1:3] |
|
649 | 649 | |
|
650 | 650 | VerboseTB.__init__(self,color_scheme,tb_offset,long_header, |
|
651 | 651 | call_pdb=call_pdb,include_vars=include_vars) |
|
652 | 652 | self.set_mode(mode) |
|
653 | 653 | |
|
654 | 654 | def _extract_tb(self,tb): |
|
655 | 655 | if tb: |
|
656 | 656 | return traceback.extract_tb(tb) |
|
657 | 657 | else: |
|
658 | 658 | return None |
|
659 | 659 | |
|
660 | 660 | def text(self, etype, value, tb,context=5,mode=None): |
|
661 | 661 | """Return formatted traceback. |
|
662 | 662 | |
|
663 | 663 | If the optional mode parameter is given, it overrides the current |
|
664 | 664 | mode.""" |
|
665 | 665 | |
|
666 | 666 | if mode is None: |
|
667 | 667 | mode = self.mode |
|
668 | 668 | if mode in self.verbose_modes: |
|
669 | 669 | # verbose modes need a full traceback |
|
670 | 670 | return VerboseTB.text(self,etype, value, tb,context=5) |
|
671 | 671 | else: |
|
672 | 672 | # We must check the source cache because otherwise we can print |
|
673 | 673 | # out-of-date source code. |
|
674 | 674 | linecache.checkcache() |
|
675 | 675 | # Now we can extract and format the exception |
|
676 | 676 | elist = self._extract_tb(tb) |
|
677 | 677 | if len(elist) > self.tb_offset: |
|
678 | 678 | del elist[:self.tb_offset] |
|
679 | 679 | return ListTB.text(self,etype,value,elist) |
|
680 | 680 | |
|
681 | 681 | def set_mode(self,mode=None): |
|
682 | 682 | """Switch to the desired mode. |
|
683 | 683 | |
|
684 | 684 | If mode is not specified, cycles through the available modes.""" |
|
685 | 685 | |
|
686 | 686 | if not mode: |
|
687 | 687 | new_idx = ( self.valid_modes.index(self.mode) + 1 ) % \ |
|
688 | 688 | len(self.valid_modes) |
|
689 | 689 | self.mode = self.valid_modes[new_idx] |
|
690 | 690 | elif mode not in self.valid_modes: |
|
691 | 691 | raise ValueError, 'Unrecognized mode in FormattedTB: <'+mode+'>\n'\ |
|
692 | 692 | 'Valid modes: '+str(self.valid_modes) |
|
693 | 693 | else: |
|
694 | 694 | self.mode = mode |
|
695 | 695 | # include variable details only in 'Verbose' mode |
|
696 | 696 | self.include_vars = (self.mode == self.valid_modes[2]) |
|
697 | 697 | |
|
698 | 698 | # some convenient shorcuts |
|
699 | 699 | def plain(self): |
|
700 | 700 | self.set_mode(self.valid_modes[0]) |
|
701 | 701 | |
|
702 | 702 | def context(self): |
|
703 | 703 | self.set_mode(self.valid_modes[1]) |
|
704 | 704 | |
|
705 | 705 | def verbose(self): |
|
706 | 706 | self.set_mode(self.valid_modes[2]) |
|
707 | 707 | |
|
708 | 708 | #---------------------------------------------------------------------------- |
|
709 | 709 | class AutoFormattedTB(FormattedTB): |
|
710 | 710 | """A traceback printer which can be called on the fly. |
|
711 | 711 | |
|
712 | 712 | It will find out about exceptions by itself. |
|
713 | 713 | |
|
714 | 714 | A brief example: |
|
715 | 715 | |
|
716 | 716 | AutoTB = AutoFormattedTB(mode = 'Verbose',color_scheme='Linux') |
|
717 | 717 | try: |
|
718 | 718 | ... |
|
719 | 719 | except: |
|
720 | 720 | AutoTB() # or AutoTB(out=logfile) where logfile is an open file object |
|
721 | 721 | """ |
|
722 | 722 | def __call__(self,etype=None,evalue=None,etb=None, |
|
723 | 723 | out=None,tb_offset=None): |
|
724 | 724 | """Print out a formatted exception traceback. |
|
725 | 725 | |
|
726 | 726 | Optional arguments: |
|
727 | 727 | - out: an open file-like object to direct output to. |
|
728 | 728 | |
|
729 | 729 | - tb_offset: the number of frames to skip over in the stack, on a |
|
730 | 730 | per-call basis (this overrides temporarily the instance's tb_offset |
|
731 | 731 | given at initialization time. """ |
|
732 | 732 | |
|
733 | 733 | if out is None: |
|
734 | 734 | out = Term.cerr |
|
735 | 735 | if tb_offset is not None: |
|
736 | 736 | tb_offset, self.tb_offset = self.tb_offset, tb_offset |
|
737 | 737 | print >> out, self.text(etype, evalue, etb) |
|
738 | 738 | self.tb_offset = tb_offset |
|
739 | 739 | else: |
|
740 | 740 | print >> out, self.text(etype, evalue, etb) |
|
741 | 741 | self.debugger() |
|
742 | 742 | |
|
743 | 743 | def text(self,etype=None,value=None,tb=None,context=5,mode=None): |
|
744 | 744 | if etype is None: |
|
745 | 745 | etype,value,tb = sys.exc_info() |
|
746 | 746 | self.tb = tb |
|
747 | 747 | return FormattedTB.text(self,etype,value,tb,context=5,mode=mode) |
|
748 | 748 | |
|
749 | 749 | #--------------------------------------------------------------------------- |
|
750 | 750 | # A simple class to preserve Nathan's original functionality. |
|
751 | 751 | class ColorTB(FormattedTB): |
|
752 | 752 | """Shorthand to initialize a FormattedTB in Linux colors mode.""" |
|
753 | 753 | def __init__(self,color_scheme='Linux',call_pdb=0): |
|
754 | 754 | FormattedTB.__init__(self,color_scheme=color_scheme, |
|
755 | 755 | call_pdb=call_pdb) |
|
756 | 756 | |
|
757 | 757 | #---------------------------------------------------------------------------- |
|
758 | 758 | # module testing (minimal) |
|
759 | 759 | if __name__ == "__main__": |
|
760 | 760 | def spam(c, (d, e)): |
|
761 | 761 | x = c + d |
|
762 | 762 | y = c * d |
|
763 | 763 | foo(x, y) |
|
764 | 764 | |
|
765 | 765 | def foo(a, b, bar=1): |
|
766 | 766 | eggs(a, b + bar) |
|
767 | 767 | |
|
768 | 768 | def eggs(f, g, z=globals()): |
|
769 | 769 | h = f + g |
|
770 | 770 | i = f - g |
|
771 | 771 | return h / i |
|
772 | 772 | |
|
773 | 773 | print '' |
|
774 | 774 | print '*** Before ***' |
|
775 | 775 | try: |
|
776 | 776 | print spam(1, (2, 3)) |
|
777 | 777 | except: |
|
778 | 778 | traceback.print_exc() |
|
779 | 779 | print '' |
|
780 | 780 | |
|
781 | 781 | handler = ColorTB() |
|
782 | 782 | print '*** ColorTB ***' |
|
783 | 783 | try: |
|
784 | 784 | print spam(1, (2, 3)) |
|
785 | 785 | except: |
|
786 | 786 | apply(handler, sys.exc_info() ) |
|
787 | 787 | print '' |
|
788 | 788 | |
|
789 | 789 | handler = VerboseTB() |
|
790 | 790 | print '*** VerboseTB ***' |
|
791 | 791 | try: |
|
792 | 792 | print spam(1, (2, 3)) |
|
793 | 793 | except: |
|
794 | 794 | apply(handler, sys.exc_info() ) |
|
795 | 795 | print '' |
|
796 | 796 |
@@ -1,4587 +1,4599 b'' | |||
|
1 | 1 | 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 2 | |
|
3 | 3 | * IPython/iplib.py (handle_shell_escape): add Ville's patch to |
|
4 | 4 | better hadnle backslashes in paths. See the thread 'More Windows |
|
5 | 5 | questions part 2 - \/ characters revisited' on the iypthon user |
|
6 | 6 | list: |
|
7 | 7 | http://scipy.net/pipermail/ipython-user/2005-June/000907.html |
|
8 | ||
|
8 | 9 | (InteractiveShell.__init__): fix tab-completion bug in threaded shells. |
|
9 | 10 | |
|
11 | (InteractiveShell.__init__): change threaded shells to not use the | |
|
12 | ipython crash handler. This was causing more problems than not, | |
|
13 | as exceptions in the main thread (GUI code, typically) would | |
|
14 | always show up as a 'crash', when they really weren't. | |
|
15 | ||
|
16 | The colors and exception mode commands (%colors/%xmode) have been | |
|
17 | synchronized to also take this into account, so users can get | |
|
18 | verbose exceptions for their threaded code as well. I also added | |
|
19 | support for activating pdb inside this exception handler as well, | |
|
20 | so now GUI authors can use IPython's enhanced pdb at runtime. | |
|
21 | ||
|
10 | 22 | * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag |
|
11 | 23 | true by default, and add it to the shipped ipythonrc file. Since |
|
12 | 24 | this asks the user before proceeding, I think it's OK to make it |
|
13 | 25 | true by default. |
|
14 | 26 | |
|
15 | 27 | * IPython/Magic.py (magic_exit): make new exit/quit magics instead |
|
16 | 28 | of the previous special-casing of input in the eval loop. I think |
|
17 | 29 | this is cleaner, as they really are commands and shouldn't have |
|
18 | 30 | a special role in the middle of the core code. |
|
19 | 31 | |
|
20 | 32 | 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu> |
|
21 | 33 | |
|
22 | 34 | * IPython/iplib.py (edit_syntax_error): added support for |
|
23 | 35 | automatically reopening the editor if the file had a syntax error |
|
24 | 36 | in it. Thanks to scottt who provided the patch at: |
|
25 | 37 | http://www.scipy.net/roundup/ipython/issue36 (slightly modified |
|
26 | 38 | version committed). |
|
27 | 39 | |
|
28 | 40 | * IPython/iplib.py (handle_normal): add suport for multi-line |
|
29 | 41 | input with emtpy lines. This fixes |
|
30 | 42 | http://www.scipy.net/roundup/ipython/issue43 and a similar |
|
31 | 43 | discussion on the user list. |
|
32 | 44 | |
|
33 | 45 | WARNING: a behavior change is necessarily introduced to support |
|
34 | 46 | blank lines: now a single blank line with whitespace does NOT |
|
35 | 47 | break the input loop, which means that when autoindent is on, by |
|
36 | 48 | default hitting return on the next (indented) line does NOT exit. |
|
37 | 49 | |
|
38 | 50 | Instead, to exit a multiline input you can either have: |
|
39 | 51 | |
|
40 | 52 | - TWO whitespace lines (just hit return again), or |
|
41 | 53 | - a single whitespace line of a different length than provided |
|
42 | 54 | by the autoindent (add or remove a space). |
|
43 | 55 | |
|
44 | 56 | * IPython/completer.py (MagicCompleter.__init__): new 'completer' |
|
45 | 57 | module to better organize all readline-related functionality. |
|
46 | 58 | I've deleted FlexCompleter and put all completion clases here. |
|
47 | 59 | |
|
48 | 60 | * IPython/iplib.py (raw_input): improve indentation management. |
|
49 | 61 | It is now possible to paste indented code with autoindent on, and |
|
50 | 62 | the code is interpreted correctly (though it still looks bad on |
|
51 | 63 | screen, due to the line-oriented nature of ipython). |
|
52 | 64 | (MagicCompleter.complete): change behavior so that a TAB key on an |
|
53 | 65 | otherwise empty line actually inserts a tab, instead of completing |
|
54 | 66 | on the entire global namespace. This makes it easier to use the |
|
55 | 67 | TAB key for indentation. After a request by Hans Meine |
|
56 | 68 | <hans_meine-AT-gmx.net> |
|
57 | 69 | (_prefilter): add support so that typing plain 'exit' or 'quit' |
|
58 | 70 | does a sensible thing. Originally I tried to deviate as little as |
|
59 | 71 | possible from the default python behavior, but even that one may |
|
60 | 72 | change in this direction (thread on python-dev to that effect). |
|
61 | 73 | Regardless, ipython should do the right thing even if CPython's |
|
62 | 74 | '>>>' prompt doesn't. |
|
63 | 75 | (InteractiveShell): removed subclassing code.InteractiveConsole |
|
64 | 76 | class. By now we'd overridden just about all of its methods: I've |
|
65 | 77 | copied the remaining two over, and now ipython is a standalone |
|
66 | 78 | class. This will provide a clearer picture for the chainsaw |
|
67 | 79 | branch refactoring. |
|
68 | 80 | |
|
69 | 81 | 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu> |
|
70 | 82 | |
|
71 | 83 | * IPython/ultraTB.py (VerboseTB.text): harden reporting against |
|
72 | 84 | failures for objects which break when dir() is called on them. |
|
73 | 85 | |
|
74 | 86 | * IPython/FlexCompleter.py (Completer.__init__): Added support for |
|
75 | 87 | distinct local and global namespaces in the completer API. This |
|
76 | 88 | change allows us top properly handle completion with distinct |
|
77 | 89 | scopes, including in embedded instances (this had never really |
|
78 | 90 | worked correctly). |
|
79 | 91 | |
|
80 | 92 | Note: this introduces a change in the constructor for |
|
81 | 93 | MagicCompleter, as a new global_namespace parameter is now the |
|
82 | 94 | second argument (the others were bumped one position). |
|
83 | 95 | |
|
84 | 96 | 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu> |
|
85 | 97 | |
|
86 | 98 | * IPython/iplib.py (embed_mainloop): fix tab-completion in |
|
87 | 99 | embedded instances (which can be done now thanks to Vivian's |
|
88 | 100 | frame-handling fixes for pdb). |
|
89 | 101 | (InteractiveShell.__init__): Fix namespace handling problem in |
|
90 | 102 | embedded instances. We were overwriting __main__ unconditionally, |
|
91 | 103 | and this should only be done for 'full' (non-embedded) IPython; |
|
92 | 104 | embedded instances must respect the caller's __main__. Thanks to |
|
93 | 105 | a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com> |
|
94 | 106 | |
|
95 | 107 | 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu> |
|
96 | 108 | |
|
97 | 109 | * setup.py: added download_url to setup(). This registers the |
|
98 | 110 | download address at PyPI, which is not only useful to humans |
|
99 | 111 | browsing the site, but is also picked up by setuptools (the Eggs |
|
100 | 112 | machinery). Thanks to Ville and R. Kern for the info/discussion |
|
101 | 113 | on this. |
|
102 | 114 | |
|
103 | 115 | 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu> |
|
104 | 116 | |
|
105 | 117 | * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements. |
|
106 | 118 | This brings a lot of nice functionality to the pdb mode, which now |
|
107 | 119 | has tab-completion, syntax highlighting, and better stack handling |
|
108 | 120 | than before. Many thanks to Vivian De Smedt |
|
109 | 121 | <vivian-AT-vdesmedt.com> for the original patches. |
|
110 | 122 | |
|
111 | 123 | 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu> |
|
112 | 124 | |
|
113 | 125 | * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling |
|
114 | 126 | sequence to consistently accept the banner argument. The |
|
115 | 127 | inconsistency was tripping SAGE, thanks to Gary Zablackis |
|
116 | 128 | <gzabl-AT-yahoo.com> for the report. |
|
117 | 129 | |
|
118 | 130 | 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu> |
|
119 | 131 | |
|
120 | 132 | * IPython/iplib.py (InteractiveShell.post_config_initialization): |
|
121 | 133 | Fix bug where a naked 'alias' call in the ipythonrc file would |
|
122 | 134 | cause a crash. Bug reported by Jorgen Stenarson. |
|
123 | 135 | |
|
124 | 136 | 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu> |
|
125 | 137 | |
|
126 | 138 | * IPython/ipmaker.py (make_IPython): cleanups which should improve |
|
127 | 139 | startup time. |
|
128 | 140 | |
|
129 | 141 | * IPython/iplib.py (runcode): my globals 'fix' for embedded |
|
130 | 142 | instances had introduced a bug with globals in normal code. Now |
|
131 | 143 | it's working in all cases. |
|
132 | 144 | |
|
133 | 145 | * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and |
|
134 | 146 | API changes. A new ipytonrc option, 'wildcards_case_sensitive' |
|
135 | 147 | has been introduced to set the default case sensitivity of the |
|
136 | 148 | searches. Users can still select either mode at runtime on a |
|
137 | 149 | per-search basis. |
|
138 | 150 | |
|
139 | 151 | 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu> |
|
140 | 152 | |
|
141 | 153 | * IPython/wildcard.py (NameSpace.__init__): fix resolution of |
|
142 | 154 | attributes in wildcard searches for subclasses. Modified version |
|
143 | 155 | of a patch by Jorgen. |
|
144 | 156 | |
|
145 | 157 | 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu> |
|
146 | 158 | |
|
147 | 159 | * IPython/iplib.py (embed_mainloop): Fix handling of globals for |
|
148 | 160 | embedded instances. I added a user_global_ns attribute to the |
|
149 | 161 | InteractiveShell class to handle this. |
|
150 | 162 | |
|
151 | 163 | 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu> |
|
152 | 164 | |
|
153 | 165 | * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to |
|
154 | 166 | idle_add, which fixes horrible keyboard lag problems under gtk 2.6 |
|
155 | 167 | (reported under win32, but may happen also in other platforms). |
|
156 | 168 | Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm> |
|
157 | 169 | |
|
158 | 170 | 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu> |
|
159 | 171 | |
|
160 | 172 | * IPython/Magic.py (magic_psearch): new support for wildcard |
|
161 | 173 | patterns. Now, typing ?a*b will list all names which begin with a |
|
162 | 174 | and end in b, for example. The %psearch magic has full |
|
163 | 175 | docstrings. Many thanks to JΓΆrgen Stenarson |
|
164 | 176 | <jorgen.stenarson-AT-bostream.nu>, author of the patches |
|
165 | 177 | implementing this functionality. |
|
166 | 178 | |
|
167 | 179 | 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu> |
|
168 | 180 | |
|
169 | 181 | * Manual: fixed long-standing annoyance of double-dashes (as in |
|
170 | 182 | --prefix=~, for example) being stripped in the HTML version. This |
|
171 | 183 | is a latex2html bug, but a workaround was provided. Many thanks |
|
172 | 184 | to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed |
|
173 | 185 | help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball |
|
174 | 186 | rolling. This seemingly small issue had tripped a number of users |
|
175 | 187 | when first installing, so I'm glad to see it gone. |
|
176 | 188 | |
|
177 | 189 | 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu> |
|
178 | 190 | |
|
179 | 191 | * IPython/Extensions/numeric_formats.py: fix missing import, |
|
180 | 192 | reported by Stephen Walton. |
|
181 | 193 | |
|
182 | 194 | 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu> |
|
183 | 195 | |
|
184 | 196 | * IPython/demo.py: finish demo module, fully documented now. |
|
185 | 197 | |
|
186 | 198 | * IPython/genutils.py (file_read): simple little utility to read a |
|
187 | 199 | file and ensure it's closed afterwards. |
|
188 | 200 | |
|
189 | 201 | 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu> |
|
190 | 202 | |
|
191 | 203 | * IPython/demo.py (Demo.__init__): added support for individually |
|
192 | 204 | tagging blocks for automatic execution. |
|
193 | 205 | |
|
194 | 206 | * IPython/Magic.py (magic_pycat): new %pycat magic for showing |
|
195 | 207 | syntax-highlighted python sources, requested by John. |
|
196 | 208 | |
|
197 | 209 | 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu> |
|
198 | 210 | |
|
199 | 211 | * IPython/demo.py (Demo.again): fix bug where again() blocks after |
|
200 | 212 | finishing. |
|
201 | 213 | |
|
202 | 214 | * IPython/genutils.py (shlex_split): moved from Magic to here, |
|
203 | 215 | where all 2.2 compatibility stuff lives. I needed it for demo.py. |
|
204 | 216 | |
|
205 | 217 | * IPython/demo.py (Demo.__init__): added support for silent |
|
206 | 218 | blocks, improved marks as regexps, docstrings written. |
|
207 | 219 | (Demo.__init__): better docstring, added support for sys.argv. |
|
208 | 220 | |
|
209 | 221 | * IPython/genutils.py (marquee): little utility used by the demo |
|
210 | 222 | code, handy in general. |
|
211 | 223 | |
|
212 | 224 | * IPython/demo.py (Demo.__init__): new class for interactive |
|
213 | 225 | demos. Not documented yet, I just wrote it in a hurry for |
|
214 | 226 | scipy'05. Will docstring later. |
|
215 | 227 | |
|
216 | 228 | 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu> |
|
217 | 229 | |
|
218 | 230 | * IPython/Shell.py (sigint_handler): Drastic simplification which |
|
219 | 231 | also seems to make Ctrl-C work correctly across threads! This is |
|
220 | 232 | so simple, that I can't beleive I'd missed it before. Needs more |
|
221 | 233 | testing, though. |
|
222 | 234 | (KBINT): Never mind, revert changes. I'm sure I'd tried something |
|
223 | 235 | like this before... |
|
224 | 236 | |
|
225 | 237 | * IPython/genutils.py (get_home_dir): add protection against |
|
226 | 238 | non-dirs in win32 registry. |
|
227 | 239 | |
|
228 | 240 | * IPython/iplib.py (InteractiveShell.alias_table_validate): fix |
|
229 | 241 | bug where dict was mutated while iterating (pysh crash). |
|
230 | 242 | |
|
231 | 243 | 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu> |
|
232 | 244 | |
|
233 | 245 | * IPython/iplib.py (handle_auto): Fix inconsistency arising from |
|
234 | 246 | spurious newlines added by this routine. After a report by |
|
235 | 247 | F. Mantegazza. |
|
236 | 248 | |
|
237 | 249 | 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu> |
|
238 | 250 | |
|
239 | 251 | * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0") |
|
240 | 252 | calls. These were a leftover from the GTK 1.x days, and can cause |
|
241 | 253 | problems in certain cases (after a report by John Hunter). |
|
242 | 254 | |
|
243 | 255 | * IPython/iplib.py (InteractiveShell.__init__): Trap exception if |
|
244 | 256 | os.getcwd() fails at init time. Thanks to patch from David Remahl |
|
245 | 257 | <chmod007-AT-mac.com>. |
|
246 | 258 | (InteractiveShell.__init__): prevent certain special magics from |
|
247 | 259 | being shadowed by aliases. Closes |
|
248 | 260 | http://www.scipy.net/roundup/ipython/issue41. |
|
249 | 261 | |
|
250 | 262 | 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu> |
|
251 | 263 | |
|
252 | 264 | * IPython/iplib.py (InteractiveShell.complete): Added new |
|
253 | 265 | top-level completion method to expose the completion mechanism |
|
254 | 266 | beyond readline-based environments. |
|
255 | 267 | |
|
256 | 268 | 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu> |
|
257 | 269 | |
|
258 | 270 | * tools/ipsvnc (svnversion): fix svnversion capture. |
|
259 | 271 | |
|
260 | 272 | * IPython/iplib.py (InteractiveShell.__init__): Add has_readline |
|
261 | 273 | attribute to self, which was missing. Before, it was set by a |
|
262 | 274 | routine which in certain cases wasn't being called, so the |
|
263 | 275 | instance could end up missing the attribute. This caused a crash. |
|
264 | 276 | Closes http://www.scipy.net/roundup/ipython/issue40. |
|
265 | 277 | |
|
266 | 278 | 2005-08-16 Fernando Perez <fperez@colorado.edu> |
|
267 | 279 | |
|
268 | 280 | * IPython/ultraTB.py (VerboseTB.text): don't crash if object |
|
269 | 281 | contains non-string attribute. Closes |
|
270 | 282 | http://www.scipy.net/roundup/ipython/issue38. |
|
271 | 283 | |
|
272 | 284 | 2005-08-14 Fernando Perez <fperez@colorado.edu> |
|
273 | 285 | |
|
274 | 286 | * tools/ipsvnc: Minor improvements, to add changeset info. |
|
275 | 287 | |
|
276 | 288 | 2005-08-12 Fernando Perez <fperez@colorado.edu> |
|
277 | 289 | |
|
278 | 290 | * IPython/iplib.py (runsource): remove self.code_to_run_src |
|
279 | 291 | attribute. I realized this is nothing more than |
|
280 | 292 | '\n'.join(self.buffer), and having the same data in two different |
|
281 | 293 | places is just asking for synchronization bugs. This may impact |
|
282 | 294 | people who have custom exception handlers, so I need to warn |
|
283 | 295 | ipython-dev about it (F. Mantegazza may use them). |
|
284 | 296 | |
|
285 | 297 | 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu> |
|
286 | 298 | |
|
287 | 299 | * IPython/genutils.py: fix 2.2 compatibility (generators) |
|
288 | 300 | |
|
289 | 301 | 2005-07-18 Fernando Perez <fperez@colorado.edu> |
|
290 | 302 | |
|
291 | 303 | * IPython/genutils.py (get_home_dir): fix to help users with |
|
292 | 304 | invalid $HOME under win32. |
|
293 | 305 | |
|
294 | 306 | 2005-07-17 Fernando Perez <fperez@colorado.edu> |
|
295 | 307 | |
|
296 | 308 | * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove |
|
297 | 309 | some old hacks and clean up a bit other routines; code should be |
|
298 | 310 | simpler and a bit faster. |
|
299 | 311 | |
|
300 | 312 | * IPython/iplib.py (interact): removed some last-resort attempts |
|
301 | 313 | to survive broken stdout/stderr. That code was only making it |
|
302 | 314 | harder to abstract out the i/o (necessary for gui integration), |
|
303 | 315 | and the crashes it could prevent were extremely rare in practice |
|
304 | 316 | (besides being fully user-induced in a pretty violent manner). |
|
305 | 317 | |
|
306 | 318 | * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff. |
|
307 | 319 | Nothing major yet, but the code is simpler to read; this should |
|
308 | 320 | make it easier to do more serious modifications in the future. |
|
309 | 321 | |
|
310 | 322 | * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh, |
|
311 | 323 | which broke in .15 (thanks to a report by Ville). |
|
312 | 324 | |
|
313 | 325 | * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not |
|
314 | 326 | be quite correct, I know next to nothing about unicode). This |
|
315 | 327 | will allow unicode strings to be used in prompts, amongst other |
|
316 | 328 | cases. It also will prevent ipython from crashing when unicode |
|
317 | 329 | shows up unexpectedly in many places. If ascii encoding fails, we |
|
318 | 330 | assume utf_8. Currently the encoding is not a user-visible |
|
319 | 331 | setting, though it could be made so if there is demand for it. |
|
320 | 332 | |
|
321 | 333 | * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack. |
|
322 | 334 | |
|
323 | 335 | * IPython/Struct.py (Struct.merge): switch keys() to iterator. |
|
324 | 336 | |
|
325 | 337 | * IPython/background_jobs.py: moved 2.2 compatibility to genutils. |
|
326 | 338 | |
|
327 | 339 | * IPython/genutils.py: Add 2.2 compatibility here, so all other |
|
328 | 340 | code can work transparently for 2.2/2.3. |
|
329 | 341 | |
|
330 | 342 | 2005-07-16 Fernando Perez <fperez@colorado.edu> |
|
331 | 343 | |
|
332 | 344 | * IPython/ultraTB.py (ExceptionColors): Make a global variable |
|
333 | 345 | out of the color scheme table used for coloring exception |
|
334 | 346 | tracebacks. This allows user code to add new schemes at runtime. |
|
335 | 347 | This is a minimally modified version of the patch at |
|
336 | 348 | http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw |
|
337 | 349 | for the contribution. |
|
338 | 350 | |
|
339 | 351 | * IPython/FlexCompleter.py (Completer.attr_matches): Add a |
|
340 | 352 | slightly modified version of the patch in |
|
341 | 353 | http://www.scipy.net/roundup/ipython/issue34, which also allows me |
|
342 | 354 | to remove the previous try/except solution (which was costlier). |
|
343 | 355 | Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix. |
|
344 | 356 | |
|
345 | 357 | 2005-06-08 Fernando Perez <fperez@colorado.edu> |
|
346 | 358 | |
|
347 | 359 | * IPython/iplib.py (write/write_err): Add methods to abstract all |
|
348 | 360 | I/O a bit more. |
|
349 | 361 | |
|
350 | 362 | * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation |
|
351 | 363 | warning, reported by Aric Hagberg, fix by JD Hunter. |
|
352 | 364 | |
|
353 | 365 | 2005-06-02 *** Released version 0.6.15 |
|
354 | 366 | |
|
355 | 367 | 2005-06-01 Fernando Perez <fperez@colorado.edu> |
|
356 | 368 | |
|
357 | 369 | * IPython/iplib.py (MagicCompleter.file_matches): Fix |
|
358 | 370 | tab-completion of filenames within open-quoted strings. Note that |
|
359 | 371 | this requires that in ~/.ipython/ipythonrc, users change the |
|
360 | 372 | readline delimiters configuration to read: |
|
361 | 373 | |
|
362 | 374 | readline_remove_delims -/~ |
|
363 | 375 | |
|
364 | 376 | |
|
365 | 377 | 2005-05-31 *** Released version 0.6.14 |
|
366 | 378 | |
|
367 | 379 | 2005-05-29 Fernando Perez <fperez@colorado.edu> |
|
368 | 380 | |
|
369 | 381 | * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks |
|
370 | 382 | with files not on the filesystem. Reported by Eliyahu Sandler |
|
371 | 383 | <eli@gondolin.net> |
|
372 | 384 | |
|
373 | 385 | 2005-05-22 Fernando Perez <fperez@colorado.edu> |
|
374 | 386 | |
|
375 | 387 | * IPython/iplib.py: Fix a few crashes in the --upgrade option. |
|
376 | 388 | After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>. |
|
377 | 389 | |
|
378 | 390 | 2005-05-19 Fernando Perez <fperez@colorado.edu> |
|
379 | 391 | |
|
380 | 392 | * IPython/iplib.py (safe_execfile): close a file which could be |
|
381 | 393 | left open (causing problems in win32, which locks open files). |
|
382 | 394 | Thanks to a bug report by D Brown <dbrown2@yahoo.com>. |
|
383 | 395 | |
|
384 | 396 | 2005-05-18 Fernando Perez <fperez@colorado.edu> |
|
385 | 397 | |
|
386 | 398 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all |
|
387 | 399 | keyword arguments correctly to safe_execfile(). |
|
388 | 400 | |
|
389 | 401 | 2005-05-13 Fernando Perez <fperez@colorado.edu> |
|
390 | 402 | |
|
391 | 403 | * ipython.1: Added info about Qt to manpage, and threads warning |
|
392 | 404 | to usage page (invoked with --help). |
|
393 | 405 | |
|
394 | 406 | * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added |
|
395 | 407 | new matcher (it goes at the end of the priority list) to do |
|
396 | 408 | tab-completion on named function arguments. Submitted by George |
|
397 | 409 | Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at |
|
398 | 410 | http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html |
|
399 | 411 | for more details. |
|
400 | 412 | |
|
401 | 413 | * IPython/Magic.py (magic_run): Added new -e flag to ignore |
|
402 | 414 | SystemExit exceptions in the script being run. Thanks to a report |
|
403 | 415 | by danny shevitz <danny_shevitz-AT-yahoo.com>, about this |
|
404 | 416 | producing very annoying behavior when running unit tests. |
|
405 | 417 | |
|
406 | 418 | 2005-05-12 Fernando Perez <fperez@colorado.edu> |
|
407 | 419 | |
|
408 | 420 | * IPython/iplib.py (handle_auto): fixed auto-quoting and parens, |
|
409 | 421 | which I'd broken (again) due to a changed regexp. In the process, |
|
410 | 422 | added ';' as an escape to auto-quote the whole line without |
|
411 | 423 | splitting its arguments. Thanks to a report by Jerry McRae |
|
412 | 424 | <qrs0xyc02-AT-sneakemail.com>. |
|
413 | 425 | |
|
414 | 426 | * IPython/ultraTB.py (VerboseTB.text): protect against rare but |
|
415 | 427 | possible crashes caused by a TokenError. Reported by Ed Schofield |
|
416 | 428 | <schofield-AT-ftw.at>. |
|
417 | 429 | |
|
418 | 430 | 2005-05-06 Fernando Perez <fperez@colorado.edu> |
|
419 | 431 | |
|
420 | 432 | * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6. |
|
421 | 433 | |
|
422 | 434 | 2005-04-29 Fernando Perez <fperez@colorado.edu> |
|
423 | 435 | |
|
424 | 436 | * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière |
|
425 | 437 | <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin |
|
426 | 438 | Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option |
|
427 | 439 | which provides support for Qt interactive usage (similar to the |
|
428 | 440 | existing one for WX and GTK). This had been often requested. |
|
429 | 441 | |
|
430 | 442 | 2005-04-14 *** Released version 0.6.13 |
|
431 | 443 | |
|
432 | 444 | 2005-04-08 Fernando Perez <fperez@colorado.edu> |
|
433 | 445 | |
|
434 | 446 | * IPython/Magic.py (Magic._ofind): remove docstring evaluation |
|
435 | 447 | from _ofind, which gets called on almost every input line. Now, |
|
436 | 448 | we only try to get docstrings if they are actually going to be |
|
437 | 449 | used (the overhead of fetching unnecessary docstrings can be |
|
438 | 450 | noticeable for certain objects, such as Pyro proxies). |
|
439 | 451 | |
|
440 | 452 | * IPython/iplib.py (MagicCompleter.python_matches): Change the API |
|
441 | 453 | for completers. For some reason I had been passing them the state |
|
442 | 454 | variable, which completers never actually need, and was in |
|
443 | 455 | conflict with the rlcompleter API. Custom completers ONLY need to |
|
444 | 456 | take the text parameter. |
|
445 | 457 | |
|
446 | 458 | * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics |
|
447 | 459 | work correctly in pysh. I've also moved all the logic which used |
|
448 | 460 | to be in pysh.py here, which will prevent problems with future |
|
449 | 461 | upgrades. However, this time I must warn users to update their |
|
450 | 462 | pysh profile to include the line |
|
451 | 463 | |
|
452 | 464 | import_all IPython.Extensions.InterpreterExec |
|
453 | 465 | |
|
454 | 466 | because otherwise things won't work for them. They MUST also |
|
455 | 467 | delete pysh.py and the line |
|
456 | 468 | |
|
457 | 469 | execfile pysh.py |
|
458 | 470 | |
|
459 | 471 | from their ipythonrc-pysh. |
|
460 | 472 | |
|
461 | 473 | * IPython/FlexCompleter.py (Completer.attr_matches): Make more |
|
462 | 474 | robust in the face of objects whose dir() returns non-strings |
|
463 | 475 | (which it shouldn't, but some broken libs like ITK do). Thanks to |
|
464 | 476 | a patch by John Hunter (implemented differently, though). Also |
|
465 | 477 | minor improvements by using .extend instead of + on lists. |
|
466 | 478 | |
|
467 | 479 | * pysh.py: |
|
468 | 480 | |
|
469 | 481 | 2005-04-06 Fernando Perez <fperez@colorado.edu> |
|
470 | 482 | |
|
471 | 483 | * IPython/ipmaker.py (make_IPython): Make multi_line_specials on |
|
472 | 484 | by default, so that all users benefit from it. Those who don't |
|
473 | 485 | want it can still turn it off. |
|
474 | 486 | |
|
475 | 487 | * IPython/UserConfig/ipythonrc: Add multi_line_specials to the |
|
476 | 488 | config file, I'd forgotten about this, so users were getting it |
|
477 | 489 | off by default. |
|
478 | 490 | |
|
479 | 491 | * IPython/iplib.py (ipmagic): big overhaul of the magic system for |
|
480 | 492 | consistency. Now magics can be called in multiline statements, |
|
481 | 493 | and python variables can be expanded in magic calls via $var. |
|
482 | 494 | This makes the magic system behave just like aliases or !system |
|
483 | 495 | calls. |
|
484 | 496 | |
|
485 | 497 | 2005-03-28 Fernando Perez <fperez@colorado.edu> |
|
486 | 498 | |
|
487 | 499 | * IPython/iplib.py (handle_auto): cleanup to use %s instead of |
|
488 | 500 | expensive string additions for building command. Add support for |
|
489 | 501 | trailing ';' when autocall is used. |
|
490 | 502 | |
|
491 | 503 | 2005-03-26 Fernando Perez <fperez@colorado.edu> |
|
492 | 504 | |
|
493 | 505 | * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31. |
|
494 | 506 | Bugfix by A. Schmolck, the ipython.el maintainer. Also make |
|
495 | 507 | ipython.el robust against prompts with any number of spaces |
|
496 | 508 | (including 0) after the ':' character. |
|
497 | 509 | |
|
498 | 510 | * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in |
|
499 | 511 | continuation prompt, which misled users to think the line was |
|
500 | 512 | already indented. Closes debian Bug#300847, reported to me by |
|
501 | 513 | Norbert Tretkowski <tretkowski-AT-inittab.de>. |
|
502 | 514 | |
|
503 | 515 | 2005-03-23 Fernando Perez <fperez@colorado.edu> |
|
504 | 516 | |
|
505 | 517 | * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are |
|
506 | 518 | properly aligned if they have embedded newlines. |
|
507 | 519 | |
|
508 | 520 | * IPython/iplib.py (runlines): Add a public method to expose |
|
509 | 521 | IPython's code execution machinery, so that users can run strings |
|
510 | 522 | as if they had been typed at the prompt interactively. |
|
511 | 523 | (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__ |
|
512 | 524 | methods which can call the system shell, but with python variable |
|
513 | 525 | expansion. The three such methods are: __IPYTHON__.system, |
|
514 | 526 | .getoutput and .getoutputerror. These need to be documented in a |
|
515 | 527 | 'public API' section (to be written) of the manual. |
|
516 | 528 | |
|
517 | 529 | 2005-03-20 Fernando Perez <fperez@colorado.edu> |
|
518 | 530 | |
|
519 | 531 | * IPython/iplib.py (InteractiveShell.set_custom_exc): new system |
|
520 | 532 | for custom exception handling. This is quite powerful, and it |
|
521 | 533 | allows for user-installable exception handlers which can trap |
|
522 | 534 | custom exceptions at runtime and treat them separately from |
|
523 | 535 | IPython's default mechanisms. At the request of FrΓ©dΓ©ric |
|
524 | 536 | Mantegazza <mantegazza-AT-ill.fr>. |
|
525 | 537 | (InteractiveShell.set_custom_completer): public API function to |
|
526 | 538 | add new completers at runtime. |
|
527 | 539 | |
|
528 | 540 | 2005-03-19 Fernando Perez <fperez@colorado.edu> |
|
529 | 541 | |
|
530 | 542 | * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to |
|
531 | 543 | allow objects which provide their docstrings via non-standard |
|
532 | 544 | mechanisms (like Pyro proxies) to still be inspected by ipython's |
|
533 | 545 | ? system. |
|
534 | 546 | |
|
535 | 547 | * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e |
|
536 | 548 | automatic capture system. I tried quite hard to make it work |
|
537 | 549 | reliably, and simply failed. I tried many combinations with the |
|
538 | 550 | subprocess module, but eventually nothing worked in all needed |
|
539 | 551 | cases (not blocking stdin for the child, duplicating stdout |
|
540 | 552 | without blocking, etc). The new %sc/%sx still do capture to these |
|
541 | 553 | magical list/string objects which make shell use much more |
|
542 | 554 | conveninent, so not all is lost. |
|
543 | 555 | |
|
544 | 556 | XXX - FIX MANUAL for the change above! |
|
545 | 557 | |
|
546 | 558 | (runsource): I copied code.py's runsource() into ipython to modify |
|
547 | 559 | it a bit. Now the code object and source to be executed are |
|
548 | 560 | stored in ipython. This makes this info accessible to third-party |
|
549 | 561 | tools, like custom exception handlers. After a request by FrΓ©dΓ©ric |
|
550 | 562 | Mantegazza <mantegazza-AT-ill.fr>. |
|
551 | 563 | |
|
552 | 564 | * IPython/UserConfig/ipythonrc: Add up/down arrow keys to |
|
553 | 565 | history-search via readline (like C-p/C-n). I'd wanted this for a |
|
554 | 566 | long time, but only recently found out how to do it. For users |
|
555 | 567 | who already have their ipythonrc files made and want this, just |
|
556 | 568 | add: |
|
557 | 569 | |
|
558 | 570 | readline_parse_and_bind "\e[A": history-search-backward |
|
559 | 571 | readline_parse_and_bind "\e[B": history-search-forward |
|
560 | 572 | |
|
561 | 573 | 2005-03-18 Fernando Perez <fperez@colorado.edu> |
|
562 | 574 | |
|
563 | 575 | * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy |
|
564 | 576 | LSString and SList classes which allow transparent conversions |
|
565 | 577 | between list mode and whitespace-separated string. |
|
566 | 578 | (magic_r): Fix recursion problem in %r. |
|
567 | 579 | |
|
568 | 580 | * IPython/genutils.py (LSString): New class to be used for |
|
569 | 581 | automatic storage of the results of all alias/system calls in _o |
|
570 | 582 | and _e (stdout/err). These provide a .l/.list attribute which |
|
571 | 583 | does automatic splitting on newlines. This means that for most |
|
572 | 584 | uses, you'll never need to do capturing of output with %sc/%sx |
|
573 | 585 | anymore, since ipython keeps this always done for you. Note that |
|
574 | 586 | only the LAST results are stored, the _o/e variables are |
|
575 | 587 | overwritten on each call. If you need to save their contents |
|
576 | 588 | further, simply bind them to any other name. |
|
577 | 589 | |
|
578 | 590 | 2005-03-17 Fernando Perez <fperez@colorado.edu> |
|
579 | 591 | |
|
580 | 592 | * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for |
|
581 | 593 | prompt namespace handling. |
|
582 | 594 | |
|
583 | 595 | 2005-03-16 Fernando Perez <fperez@colorado.edu> |
|
584 | 596 | |
|
585 | 597 | * IPython/Prompts.py (CachedOutput.__init__): Fix default and |
|
586 | 598 | classic prompts to be '>>> ' (final space was missing, and it |
|
587 | 599 | trips the emacs python mode). |
|
588 | 600 | (BasePrompt.__str__): Added safe support for dynamic prompt |
|
589 | 601 | strings. Now you can set your prompt string to be '$x', and the |
|
590 | 602 | value of x will be printed from your interactive namespace. The |
|
591 | 603 | interpolation syntax includes the full Itpl support, so |
|
592 | 604 | ${foo()+x+bar()} is a valid prompt string now, and the function |
|
593 | 605 | calls will be made at runtime. |
|
594 | 606 | |
|
595 | 607 | 2005-03-15 Fernando Perez <fperez@colorado.edu> |
|
596 | 608 | |
|
597 | 609 | * IPython/Magic.py (magic_history): renamed %hist to %history, to |
|
598 | 610 | avoid name clashes in pylab. %hist still works, it just forwards |
|
599 | 611 | the call to %history. |
|
600 | 612 | |
|
601 | 613 | 2005-03-02 *** Released version 0.6.12 |
|
602 | 614 | |
|
603 | 615 | 2005-03-02 Fernando Perez <fperez@colorado.edu> |
|
604 | 616 | |
|
605 | 617 | * IPython/iplib.py (handle_magic): log magic calls properly as |
|
606 | 618 | ipmagic() function calls. |
|
607 | 619 | |
|
608 | 620 | * IPython/Magic.py (magic_time): Improved %time to support |
|
609 | 621 | statements and provide wall-clock as well as CPU time. |
|
610 | 622 | |
|
611 | 623 | 2005-02-27 Fernando Perez <fperez@colorado.edu> |
|
612 | 624 | |
|
613 | 625 | * IPython/hooks.py: New hooks module, to expose user-modifiable |
|
614 | 626 | IPython functionality in a clean manner. For now only the editor |
|
615 | 627 | hook is actually written, and other thigns which I intend to turn |
|
616 | 628 | into proper hooks aren't yet there. The display and prefilter |
|
617 | 629 | stuff, for example, should be hooks. But at least now the |
|
618 | 630 | framework is in place, and the rest can be moved here with more |
|
619 | 631 | time later. IPython had had a .hooks variable for a long time for |
|
620 | 632 | this purpose, but I'd never actually used it for anything. |
|
621 | 633 | |
|
622 | 634 | 2005-02-26 Fernando Perez <fperez@colorado.edu> |
|
623 | 635 | |
|
624 | 636 | * IPython/ipmaker.py (make_IPython): make the default ipython |
|
625 | 637 | directory be called _ipython under win32, to follow more the |
|
626 | 638 | naming peculiarities of that platform (where buggy software like |
|
627 | 639 | Visual Sourcesafe breaks with .named directories). Reported by |
|
628 | 640 | Ville Vainio. |
|
629 | 641 | |
|
630 | 642 | 2005-02-23 Fernando Perez <fperez@colorado.edu> |
|
631 | 643 | |
|
632 | 644 | * IPython/iplib.py (InteractiveShell.__init__): removed a few |
|
633 | 645 | auto_aliases for win32 which were causing problems. Users can |
|
634 | 646 | define the ones they personally like. |
|
635 | 647 | |
|
636 | 648 | 2005-02-21 Fernando Perez <fperez@colorado.edu> |
|
637 | 649 | |
|
638 | 650 | * IPython/Magic.py (magic_time): new magic to time execution of |
|
639 | 651 | expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>. |
|
640 | 652 | |
|
641 | 653 | 2005-02-19 Fernando Perez <fperez@colorado.edu> |
|
642 | 654 | |
|
643 | 655 | * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings |
|
644 | 656 | into keys (for prompts, for example). |
|
645 | 657 | |
|
646 | 658 | * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty |
|
647 | 659 | prompts in case users want them. This introduces a small behavior |
|
648 | 660 | change: ipython does not automatically add a space to all prompts |
|
649 | 661 | anymore. To get the old prompts with a space, users should add it |
|
650 | 662 | manually to their ipythonrc file, so for example prompt_in1 should |
|
651 | 663 | now read 'In [\#]: ' instead of 'In [\#]:'. |
|
652 | 664 | (BasePrompt.__init__): New option prompts_pad_left (only in rc |
|
653 | 665 | file) to control left-padding of secondary prompts. |
|
654 | 666 | |
|
655 | 667 | * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if |
|
656 | 668 | the profiler can't be imported. Fix for Debian, which removed |
|
657 | 669 | profile.py because of License issues. I applied a slightly |
|
658 | 670 | modified version of the original Debian patch at |
|
659 | 671 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500. |
|
660 | 672 | |
|
661 | 673 | 2005-02-17 Fernando Perez <fperez@colorado.edu> |
|
662 | 674 | |
|
663 | 675 | * IPython/genutils.py (native_line_ends): Fix bug which would |
|
664 | 676 | cause improper line-ends under win32 b/c I was not opening files |
|
665 | 677 | in binary mode. Bug report and fix thanks to Ville. |
|
666 | 678 | |
|
667 | 679 | * IPython/iplib.py (handle_auto): Fix bug which I introduced when |
|
668 | 680 | trying to catch spurious foo[1] autocalls. My fix actually broke |
|
669 | 681 | ',/' autoquote/call with explicit escape (bad regexp). |
|
670 | 682 | |
|
671 | 683 | 2005-02-15 *** Released version 0.6.11 |
|
672 | 684 | |
|
673 | 685 | 2005-02-14 Fernando Perez <fperez@colorado.edu> |
|
674 | 686 | |
|
675 | 687 | * IPython/background_jobs.py: New background job management |
|
676 | 688 | subsystem. This is implemented via a new set of classes, and |
|
677 | 689 | IPython now provides a builtin 'jobs' object for background job |
|
678 | 690 | execution. A convenience %bg magic serves as a lightweight |
|
679 | 691 | frontend for starting the more common type of calls. This was |
|
680 | 692 | inspired by discussions with B. Granger and the BackgroundCommand |
|
681 | 693 | class described in the book Python Scripting for Computational |
|
682 | 694 | Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting |
|
683 | 695 | (although ultimately no code from this text was used, as IPython's |
|
684 | 696 | system is a separate implementation). |
|
685 | 697 | |
|
686 | 698 | * IPython/iplib.py (MagicCompleter.python_matches): add new option |
|
687 | 699 | to control the completion of single/double underscore names |
|
688 | 700 | separately. As documented in the example ipytonrc file, the |
|
689 | 701 | readline_omit__names variable can now be set to 2, to omit even |
|
690 | 702 | single underscore names. Thanks to a patch by Brian Wong |
|
691 | 703 | <BrianWong-AT-AirgoNetworks.Com>. |
|
692 | 704 | (InteractiveShell.__init__): Fix bug which would cause foo[1] to |
|
693 | 705 | be autocalled as foo([1]) if foo were callable. A problem for |
|
694 | 706 | things which are both callable and implement __getitem__. |
|
695 | 707 | (init_readline): Fix autoindentation for win32. Thanks to a patch |
|
696 | 708 | by Vivian De Smedt <vivian-AT-vdesmedt.com>. |
|
697 | 709 | |
|
698 | 710 | 2005-02-12 Fernando Perez <fperez@colorado.edu> |
|
699 | 711 | |
|
700 | 712 | * IPython/ipmaker.py (make_IPython): Disabled the stout traps |
|
701 | 713 | which I had written long ago to sort out user error messages which |
|
702 | 714 | may occur during startup. This seemed like a good idea initially, |
|
703 | 715 | but it has proven a disaster in retrospect. I don't want to |
|
704 | 716 | change much code for now, so my fix is to set the internal 'debug' |
|
705 | 717 | flag to true everywhere, whose only job was precisely to control |
|
706 | 718 | this subsystem. This closes issue 28 (as well as avoiding all |
|
707 | 719 | sorts of strange hangups which occur from time to time). |
|
708 | 720 | |
|
709 | 721 | 2005-02-07 Fernando Perez <fperez@colorado.edu> |
|
710 | 722 | |
|
711 | 723 | * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the |
|
712 | 724 | previous call produced a syntax error. |
|
713 | 725 | |
|
714 | 726 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
715 | 727 | classes without constructor. |
|
716 | 728 | |
|
717 | 729 | 2005-02-06 Fernando Perez <fperez@colorado.edu> |
|
718 | 730 | |
|
719 | 731 | * IPython/iplib.py (MagicCompleter.complete): Extend the list of |
|
720 | 732 | completions with the results of each matcher, so we return results |
|
721 | 733 | to the user from all namespaces. This breaks with ipython |
|
722 | 734 | tradition, but I think it's a nicer behavior. Now you get all |
|
723 | 735 | possible completions listed, from all possible namespaces (python, |
|
724 | 736 | filesystem, magics...) After a request by John Hunter |
|
725 | 737 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
726 | 738 | |
|
727 | 739 | 2005-02-05 Fernando Perez <fperez@colorado.edu> |
|
728 | 740 | |
|
729 | 741 | * IPython/Magic.py (magic_prun): Fix bug where prun would fail if |
|
730 | 742 | the call had quote characters in it (the quotes were stripped). |
|
731 | 743 | |
|
732 | 744 | 2005-01-31 Fernando Perez <fperez@colorado.edu> |
|
733 | 745 | |
|
734 | 746 | * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on |
|
735 | 747 | Itpl.itpl() to make the code more robust against psyco |
|
736 | 748 | optimizations. |
|
737 | 749 | |
|
738 | 750 | * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead |
|
739 | 751 | of causing an exception. Quicker, cleaner. |
|
740 | 752 | |
|
741 | 753 | 2005-01-28 Fernando Perez <fperez@colorado.edu> |
|
742 | 754 | |
|
743 | 755 | * scripts/ipython_win_post_install.py (install): hardcode |
|
744 | 756 | sys.prefix+'python.exe' as the executable path. It turns out that |
|
745 | 757 | during the post-installation run, sys.executable resolves to the |
|
746 | 758 | name of the binary installer! I should report this as a distutils |
|
747 | 759 | bug, I think. I updated the .10 release with this tiny fix, to |
|
748 | 760 | avoid annoying the lists further. |
|
749 | 761 | |
|
750 | 762 | 2005-01-27 *** Released version 0.6.10 |
|
751 | 763 | |
|
752 | 764 | 2005-01-27 Fernando Perez <fperez@colorado.edu> |
|
753 | 765 | |
|
754 | 766 | * IPython/numutils.py (norm): Added 'inf' as optional name for |
|
755 | 767 | L-infinity norm, included references to mathworld.com for vector |
|
756 | 768 | norm definitions. |
|
757 | 769 | (amin/amax): added amin/amax for array min/max. Similar to what |
|
758 | 770 | pylab ships with after the recent reorganization of names. |
|
759 | 771 | (spike/spike_odd): removed deprecated spike/spike_odd functions. |
|
760 | 772 | |
|
761 | 773 | * ipython.el: committed Alex's recent fixes and improvements. |
|
762 | 774 | Tested with python-mode from CVS, and it looks excellent. Since |
|
763 | 775 | python-mode hasn't released anything in a while, I'm temporarily |
|
764 | 776 | putting a copy of today's CVS (v 4.70) of python-mode in: |
|
765 | 777 | http://ipython.scipy.org/tmp/python-mode.el |
|
766 | 778 | |
|
767 | 779 | * scripts/ipython_win_post_install.py (install): Win32 fix to use |
|
768 | 780 | sys.executable for the executable name, instead of assuming it's |
|
769 | 781 | called 'python.exe' (the post-installer would have produced broken |
|
770 | 782 | setups on systems with a differently named python binary). |
|
771 | 783 | |
|
772 | 784 | * IPython/PyColorize.py (Parser.__call__): change explicit '\n' |
|
773 | 785 | references to os.linesep, to make the code more |
|
774 | 786 | platform-independent. This is also part of the win32 coloring |
|
775 | 787 | fixes. |
|
776 | 788 | |
|
777 | 789 | * IPython/genutils.py (page_dumb): Remove attempts to chop long |
|
778 | 790 | lines, which actually cause coloring bugs because the length of |
|
779 | 791 | the line is very difficult to correctly compute with embedded |
|
780 | 792 | escapes. This was the source of all the coloring problems under |
|
781 | 793 | Win32. I think that _finally_, Win32 users have a properly |
|
782 | 794 | working ipython in all respects. This would never have happened |
|
783 | 795 | if not for Gary Bishop and Viktor Ransmayr's great help and work. |
|
784 | 796 | |
|
785 | 797 | 2005-01-26 *** Released version 0.6.9 |
|
786 | 798 | |
|
787 | 799 | 2005-01-25 Fernando Perez <fperez@colorado.edu> |
|
788 | 800 | |
|
789 | 801 | * setup.py: finally, we have a true Windows installer, thanks to |
|
790 | 802 | the excellent work of Viktor Ransmayr |
|
791 | 803 | <viktor.ransmayr-AT-t-online.de>. The docs have been updated for |
|
792 | 804 | Windows users. The setup routine is quite a bit cleaner thanks to |
|
793 | 805 | this, and the post-install script uses the proper functions to |
|
794 | 806 | allow a clean de-installation using the standard Windows Control |
|
795 | 807 | Panel. |
|
796 | 808 | |
|
797 | 809 | * IPython/genutils.py (get_home_dir): changed to use the $HOME |
|
798 | 810 | environment variable under all OSes (including win32) if |
|
799 | 811 | available. This will give consistency to win32 users who have set |
|
800 | 812 | this variable for any reason. If os.environ['HOME'] fails, the |
|
801 | 813 | previous policy of using HOMEDRIVE\HOMEPATH kicks in. |
|
802 | 814 | |
|
803 | 815 | 2005-01-24 Fernando Perez <fperez@colorado.edu> |
|
804 | 816 | |
|
805 | 817 | * IPython/numutils.py (empty_like): add empty_like(), similar to |
|
806 | 818 | zeros_like() but taking advantage of the new empty() Numeric routine. |
|
807 | 819 | |
|
808 | 820 | 2005-01-23 *** Released version 0.6.8 |
|
809 | 821 | |
|
810 | 822 | 2005-01-22 Fernando Perez <fperez@colorado.edu> |
|
811 | 823 | |
|
812 | 824 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the |
|
813 | 825 | automatic show() calls. After discussing things with JDH, it |
|
814 | 826 | turns out there are too many corner cases where this can go wrong. |
|
815 | 827 | It's best not to try to be 'too smart', and simply have ipython |
|
816 | 828 | reproduce as much as possible the default behavior of a normal |
|
817 | 829 | python shell. |
|
818 | 830 | |
|
819 | 831 | * IPython/iplib.py (InteractiveShell.__init__): Modified the |
|
820 | 832 | line-splitting regexp and _prefilter() to avoid calling getattr() |
|
821 | 833 | on assignments. This closes |
|
822 | 834 | http://www.scipy.net/roundup/ipython/issue24. Note that Python's |
|
823 | 835 | readline uses getattr(), so a simple <TAB> keypress is still |
|
824 | 836 | enough to trigger getattr() calls on an object. |
|
825 | 837 | |
|
826 | 838 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
827 | 839 | |
|
828 | 840 | * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run |
|
829 | 841 | docstring under pylab so it doesn't mask the original. |
|
830 | 842 | |
|
831 | 843 | 2005-01-21 *** Released version 0.6.7 |
|
832 | 844 | |
|
833 | 845 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
834 | 846 | |
|
835 | 847 | * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with |
|
836 | 848 | signal handling for win32 users in multithreaded mode. |
|
837 | 849 | |
|
838 | 850 | 2005-01-17 Fernando Perez <fperez@colorado.edu> |
|
839 | 851 | |
|
840 | 852 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
841 | 853 | instances with no __init__. After a crash report by Norbert Nemec |
|
842 | 854 | <Norbert-AT-nemec-online.de>. |
|
843 | 855 | |
|
844 | 856 | 2005-01-14 Fernando Perez <fperez@colorado.edu> |
|
845 | 857 | |
|
846 | 858 | * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of |
|
847 | 859 | names for verbose exceptions, when multiple dotted names and the |
|
848 | 860 | 'parent' object were present on the same line. |
|
849 | 861 | |
|
850 | 862 | 2005-01-11 Fernando Perez <fperez@colorado.edu> |
|
851 | 863 | |
|
852 | 864 | * IPython/genutils.py (flag_calls): new utility to trap and flag |
|
853 | 865 | calls in functions. I need it to clean up matplotlib support. |
|
854 | 866 | Also removed some deprecated code in genutils. |
|
855 | 867 | |
|
856 | 868 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so |
|
857 | 869 | that matplotlib scripts called with %run, which don't call show() |
|
858 | 870 | themselves, still have their plotting windows open. |
|
859 | 871 | |
|
860 | 872 | 2005-01-05 Fernando Perez <fperez@colorado.edu> |
|
861 | 873 | |
|
862 | 874 | * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw |
|
863 | 875 | <astraw-AT-caltech.edu>, to fix gtk deprecation warnings. |
|
864 | 876 | |
|
865 | 877 | 2004-12-19 Fernando Perez <fperez@colorado.edu> |
|
866 | 878 | |
|
867 | 879 | * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of |
|
868 | 880 | parent_runcode, which was an eyesore. The same result can be |
|
869 | 881 | obtained with Python's regular superclass mechanisms. |
|
870 | 882 | |
|
871 | 883 | 2004-12-17 Fernando Perez <fperez@colorado.edu> |
|
872 | 884 | |
|
873 | 885 | * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem |
|
874 | 886 | reported by Prabhu. |
|
875 | 887 | (Magic.magic_sx): direct all errors to Term.cerr (defaults to |
|
876 | 888 | sys.stderr) instead of explicitly calling sys.stderr. This helps |
|
877 | 889 | maintain our I/O abstractions clean, for future GUI embeddings. |
|
878 | 890 | |
|
879 | 891 | * IPython/genutils.py (info): added new utility for sys.stderr |
|
880 | 892 | unified info message handling (thin wrapper around warn()). |
|
881 | 893 | |
|
882 | 894 | * IPython/ultraTB.py (VerboseTB.text): Fix misreported global |
|
883 | 895 | composite (dotted) names on verbose exceptions. |
|
884 | 896 | (VerboseTB.nullrepr): harden against another kind of errors which |
|
885 | 897 | Python's inspect module can trigger, and which were crashing |
|
886 | 898 | IPython. Thanks to a report by Marco Lombardi |
|
887 | 899 | <mlombard-AT-ma010192.hq.eso.org>. |
|
888 | 900 | |
|
889 | 901 | 2004-12-13 *** Released version 0.6.6 |
|
890 | 902 | |
|
891 | 903 | 2004-12-12 Fernando Perez <fperez@colorado.edu> |
|
892 | 904 | |
|
893 | 905 | * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors |
|
894 | 906 | generated by pygtk upon initialization if it was built without |
|
895 | 907 | threads (for matplotlib users). After a crash reported by |
|
896 | 908 | Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>. |
|
897 | 909 | |
|
898 | 910 | * IPython/ipmaker.py (make_IPython): fix small bug in the |
|
899 | 911 | import_some parameter for multiple imports. |
|
900 | 912 | |
|
901 | 913 | * IPython/iplib.py (ipmagic): simplified the interface of |
|
902 | 914 | ipmagic() to take a single string argument, just as it would be |
|
903 | 915 | typed at the IPython cmd line. |
|
904 | 916 | (ipalias): Added new ipalias() with an interface identical to |
|
905 | 917 | ipmagic(). This completes exposing a pure python interface to the |
|
906 | 918 | alias and magic system, which can be used in loops or more complex |
|
907 | 919 | code where IPython's automatic line mangling is not active. |
|
908 | 920 | |
|
909 | 921 | * IPython/genutils.py (timing): changed interface of timing to |
|
910 | 922 | simply run code once, which is the most common case. timings() |
|
911 | 923 | remains unchanged, for the cases where you want multiple runs. |
|
912 | 924 | |
|
913 | 925 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a |
|
914 | 926 | bug where Python2.2 crashes with exec'ing code which does not end |
|
915 | 927 | in a single newline. Python 2.3 is OK, so I hadn't noticed this |
|
916 | 928 | before. |
|
917 | 929 | |
|
918 | 930 | 2004-12-10 Fernando Perez <fperez@colorado.edu> |
|
919 | 931 | |
|
920 | 932 | * IPython/Magic.py (Magic.magic_prun): changed name of option from |
|
921 | 933 | -t to -T, to accomodate the new -t flag in %run (the %run and |
|
922 | 934 | %prun options are kind of intermixed, and it's not easy to change |
|
923 | 935 | this with the limitations of python's getopt). |
|
924 | 936 | |
|
925 | 937 | * IPython/Magic.py (Magic.magic_run): Added new -t option to time |
|
926 | 938 | the execution of scripts. It's not as fine-tuned as timeit.py, |
|
927 | 939 | but it works from inside ipython (and under 2.2, which lacks |
|
928 | 940 | timeit.py). Optionally a number of runs > 1 can be given for |
|
929 | 941 | timing very short-running code. |
|
930 | 942 | |
|
931 | 943 | * IPython/genutils.py (uniq_stable): new routine which returns a |
|
932 | 944 | list of unique elements in any iterable, but in stable order of |
|
933 | 945 | appearance. I needed this for the ultraTB fixes, and it's a handy |
|
934 | 946 | utility. |
|
935 | 947 | |
|
936 | 948 | * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of |
|
937 | 949 | dotted names in Verbose exceptions. This had been broken since |
|
938 | 950 | the very start, now x.y will properly be printed in a Verbose |
|
939 | 951 | traceback, instead of x being shown and y appearing always as an |
|
940 | 952 | 'undefined global'. Getting this to work was a bit tricky, |
|
941 | 953 | because by default python tokenizers are stateless. Saved by |
|
942 | 954 | python's ability to easily add a bit of state to an arbitrary |
|
943 | 955 | function (without needing to build a full-blown callable object). |
|
944 | 956 | |
|
945 | 957 | Also big cleanup of this code, which had horrendous runtime |
|
946 | 958 | lookups of zillions of attributes for colorization. Moved all |
|
947 | 959 | this code into a few templates, which make it cleaner and quicker. |
|
948 | 960 | |
|
949 | 961 | Printout quality was also improved for Verbose exceptions: one |
|
950 | 962 | variable per line, and memory addresses are printed (this can be |
|
951 | 963 | quite handy in nasty debugging situations, which is what Verbose |
|
952 | 964 | is for). |
|
953 | 965 | |
|
954 | 966 | * IPython/ipmaker.py (make_IPython): Do NOT execute files named in |
|
955 | 967 | the command line as scripts to be loaded by embedded instances. |
|
956 | 968 | Doing so has the potential for an infinite recursion if there are |
|
957 | 969 | exceptions thrown in the process. This fixes a strange crash |
|
958 | 970 | reported by Philippe MULLER <muller-AT-irit.fr>. |
|
959 | 971 | |
|
960 | 972 | 2004-12-09 Fernando Perez <fperez@colorado.edu> |
|
961 | 973 | |
|
962 | 974 | * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support |
|
963 | 975 | to reflect new names in matplotlib, which now expose the |
|
964 | 976 | matlab-compatible interface via a pylab module instead of the |
|
965 | 977 | 'matlab' name. The new code is backwards compatible, so users of |
|
966 | 978 | all matplotlib versions are OK. Patch by J. Hunter. |
|
967 | 979 | |
|
968 | 980 | * IPython/OInspect.py (Inspector.pinfo): Add to object? printing |
|
969 | 981 | of __init__ docstrings for instances (class docstrings are already |
|
970 | 982 | automatically printed). Instances with customized docstrings |
|
971 | 983 | (indep. of the class) are also recognized and all 3 separate |
|
972 | 984 | docstrings are printed (instance, class, constructor). After some |
|
973 | 985 | comments/suggestions by J. Hunter. |
|
974 | 986 | |
|
975 | 987 | 2004-12-05 Fernando Perez <fperez@colorado.edu> |
|
976 | 988 | |
|
977 | 989 | * IPython/iplib.py (MagicCompleter.complete): Remove annoying |
|
978 | 990 | warnings when tab-completion fails and triggers an exception. |
|
979 | 991 | |
|
980 | 992 | 2004-12-03 Fernando Perez <fperez@colorado.edu> |
|
981 | 993 | |
|
982 | 994 | * IPython/Magic.py (magic_prun): Fix bug where an exception would |
|
983 | 995 | be triggered when using 'run -p'. An incorrect option flag was |
|
984 | 996 | being set ('d' instead of 'D'). |
|
985 | 997 | (manpage): fix missing escaped \- sign. |
|
986 | 998 | |
|
987 | 999 | 2004-11-30 *** Released version 0.6.5 |
|
988 | 1000 | |
|
989 | 1001 | 2004-11-30 Fernando Perez <fperez@colorado.edu> |
|
990 | 1002 | |
|
991 | 1003 | * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint |
|
992 | 1004 | setting with -d option. |
|
993 | 1005 | |
|
994 | 1006 | * setup.py (docfiles): Fix problem where the doc glob I was using |
|
995 | 1007 | was COMPLETELY BROKEN. It was giving the right files by pure |
|
996 | 1008 | accident, but failed once I tried to include ipython.el. Note: |
|
997 | 1009 | glob() does NOT allow you to do exclusion on multiple endings! |
|
998 | 1010 | |
|
999 | 1011 | 2004-11-29 Fernando Perez <fperez@colorado.edu> |
|
1000 | 1012 | |
|
1001 | 1013 | * IPython/usage.py (__doc__): cleaned up usage docstring, by using |
|
1002 | 1014 | the manpage as the source. Better formatting & consistency. |
|
1003 | 1015 | |
|
1004 | 1016 | * IPython/Magic.py (magic_run): Added new -d option, to run |
|
1005 | 1017 | scripts under the control of the python pdb debugger. Note that |
|
1006 | 1018 | this required changing the %prun option -d to -D, to avoid a clash |
|
1007 | 1019 | (since %run must pass options to %prun, and getopt is too dumb to |
|
1008 | 1020 | handle options with string values with embedded spaces). Thanks |
|
1009 | 1021 | to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>. |
|
1010 | 1022 | (magic_who_ls): added type matching to %who and %whos, so that one |
|
1011 | 1023 | can filter their output to only include variables of certain |
|
1012 | 1024 | types. Another suggestion by Matthew. |
|
1013 | 1025 | (magic_whos): Added memory summaries in kb and Mb for arrays. |
|
1014 | 1026 | (magic_who): Improve formatting (break lines every 9 vars). |
|
1015 | 1027 | |
|
1016 | 1028 | 2004-11-28 Fernando Perez <fperez@colorado.edu> |
|
1017 | 1029 | |
|
1018 | 1030 | * IPython/Logger.py (Logger.log): Fix bug in syncing the input |
|
1019 | 1031 | cache when empty lines were present. |
|
1020 | 1032 | |
|
1021 | 1033 | 2004-11-24 Fernando Perez <fperez@colorado.edu> |
|
1022 | 1034 | |
|
1023 | 1035 | * IPython/usage.py (__doc__): document the re-activated threading |
|
1024 | 1036 | options for WX and GTK. |
|
1025 | 1037 | |
|
1026 | 1038 | 2004-11-23 Fernando Perez <fperez@colorado.edu> |
|
1027 | 1039 | |
|
1028 | 1040 | * IPython/Shell.py (start): Added Prabhu's big patch to reactivate |
|
1029 | 1041 | the -wthread and -gthread options, along with a new -tk one to try |
|
1030 | 1042 | and coordinate Tk threading with wx/gtk. The tk support is very |
|
1031 | 1043 | platform dependent, since it seems to require Tcl and Tk to be |
|
1032 | 1044 | built with threads (Fedora1/2 appears NOT to have it, but in |
|
1033 | 1045 | Prabhu's Debian boxes it works OK). But even with some Tk |
|
1034 | 1046 | limitations, this is a great improvement. |
|
1035 | 1047 | |
|
1036 | 1048 | * IPython/Prompts.py (prompt_specials_color): Added \t for time |
|
1037 | 1049 | info in user prompts. Patch by Prabhu. |
|
1038 | 1050 | |
|
1039 | 1051 | 2004-11-18 Fernando Perez <fperez@colorado.edu> |
|
1040 | 1052 | |
|
1041 | 1053 | * IPython/genutils.py (ask_yes_no): Add check for a max of 20 |
|
1042 | 1054 | EOFErrors and bail, to avoid infinite loops if a non-terminating |
|
1043 | 1055 | file is fed into ipython. Patch submitted in issue 19 by user, |
|
1044 | 1056 | many thanks. |
|
1045 | 1057 | |
|
1046 | 1058 | * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger |
|
1047 | 1059 | autoquote/parens in continuation prompts, which can cause lots of |
|
1048 | 1060 | problems. Closes roundup issue 20. |
|
1049 | 1061 | |
|
1050 | 1062 | 2004-11-17 Fernando Perez <fperez@colorado.edu> |
|
1051 | 1063 | |
|
1052 | 1064 | * debian/control (Build-Depends-Indep): Fix dpatch dependency, |
|
1053 | 1065 | reported as debian bug #280505. I'm not sure my local changelog |
|
1054 | 1066 | entry has the proper debian format (Jack?). |
|
1055 | 1067 | |
|
1056 | 1068 | 2004-11-08 *** Released version 0.6.4 |
|
1057 | 1069 | |
|
1058 | 1070 | 2004-11-08 Fernando Perez <fperez@colorado.edu> |
|
1059 | 1071 | |
|
1060 | 1072 | * IPython/iplib.py (init_readline): Fix exit message for Windows |
|
1061 | 1073 | when readline is active. Thanks to a report by Eric Jones |
|
1062 | 1074 | <eric-AT-enthought.com>. |
|
1063 | 1075 | |
|
1064 | 1076 | 2004-11-07 Fernando Perez <fperez@colorado.edu> |
|
1065 | 1077 | |
|
1066 | 1078 | * IPython/genutils.py (page): Add a trap for OSError exceptions, |
|
1067 | 1079 | sometimes seen by win2k/cygwin users. |
|
1068 | 1080 | |
|
1069 | 1081 | 2004-11-06 Fernando Perez <fperez@colorado.edu> |
|
1070 | 1082 | |
|
1071 | 1083 | * IPython/iplib.py (interact): Change the handling of %Exit from |
|
1072 | 1084 | trying to propagate a SystemExit to an internal ipython flag. |
|
1073 | 1085 | This is less elegant than using Python's exception mechanism, but |
|
1074 | 1086 | I can't get that to work reliably with threads, so under -pylab |
|
1075 | 1087 | %Exit was hanging IPython. Cross-thread exception handling is |
|
1076 | 1088 | really a bitch. Thaks to a bug report by Stephen Walton |
|
1077 | 1089 | <stephen.walton-AT-csun.edu>. |
|
1078 | 1090 | |
|
1079 | 1091 | 2004-11-04 Fernando Perez <fperez@colorado.edu> |
|
1080 | 1092 | |
|
1081 | 1093 | * IPython/iplib.py (raw_input_original): store a pointer to the |
|
1082 | 1094 | true raw_input to harden against code which can modify it |
|
1083 | 1095 | (wx.py.PyShell does this and would otherwise crash ipython). |
|
1084 | 1096 | Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>. |
|
1085 | 1097 | |
|
1086 | 1098 | * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for |
|
1087 | 1099 | Ctrl-C problem, which does not mess up the input line. |
|
1088 | 1100 | |
|
1089 | 1101 | 2004-11-03 Fernando Perez <fperez@colorado.edu> |
|
1090 | 1102 | |
|
1091 | 1103 | * IPython/Release.py: Changed licensing to BSD, in all files. |
|
1092 | 1104 | (name): lowercase name for tarball/RPM release. |
|
1093 | 1105 | |
|
1094 | 1106 | * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for |
|
1095 | 1107 | use throughout ipython. |
|
1096 | 1108 | |
|
1097 | 1109 | * IPython/Magic.py (Magic._ofind): Switch to using the new |
|
1098 | 1110 | OInspect.getdoc() function. |
|
1099 | 1111 | |
|
1100 | 1112 | * IPython/Shell.py (sigint_handler): Hack to ignore the execution |
|
1101 | 1113 | of the line currently being canceled via Ctrl-C. It's extremely |
|
1102 | 1114 | ugly, but I don't know how to do it better (the problem is one of |
|
1103 | 1115 | handling cross-thread exceptions). |
|
1104 | 1116 | |
|
1105 | 1117 | 2004-10-28 Fernando Perez <fperez@colorado.edu> |
|
1106 | 1118 | |
|
1107 | 1119 | * IPython/Shell.py (signal_handler): add signal handlers to trap |
|
1108 | 1120 | SIGINT and SIGSEGV in threaded code properly. Thanks to a bug |
|
1109 | 1121 | report by Francesc Alted. |
|
1110 | 1122 | |
|
1111 | 1123 | 2004-10-21 Fernando Perez <fperez@colorado.edu> |
|
1112 | 1124 | |
|
1113 | 1125 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @ |
|
1114 | 1126 | to % for pysh syntax extensions. |
|
1115 | 1127 | |
|
1116 | 1128 | 2004-10-09 Fernando Perez <fperez@colorado.edu> |
|
1117 | 1129 | |
|
1118 | 1130 | * IPython/Magic.py (Magic.magic_whos): modify output of Numeric |
|
1119 | 1131 | arrays to print a more useful summary, without calling str(arr). |
|
1120 | 1132 | This avoids the problem of extremely lengthy computations which |
|
1121 | 1133 | occur if arr is large, and appear to the user as a system lockup |
|
1122 | 1134 | with 100% cpu activity. After a suggestion by Kristian Sandberg |
|
1123 | 1135 | <Kristian.Sandberg@colorado.edu>. |
|
1124 | 1136 | (Magic.__init__): fix bug in global magic escapes not being |
|
1125 | 1137 | correctly set. |
|
1126 | 1138 | |
|
1127 | 1139 | 2004-10-08 Fernando Perez <fperez@colorado.edu> |
|
1128 | 1140 | |
|
1129 | 1141 | * IPython/Magic.py (__license__): change to absolute imports of |
|
1130 | 1142 | ipython's own internal packages, to start adapting to the absolute |
|
1131 | 1143 | import requirement of PEP-328. |
|
1132 | 1144 | |
|
1133 | 1145 | * IPython/genutils.py (__author__): Fix coding to utf-8 on all |
|
1134 | 1146 | files, and standardize author/license marks through the Release |
|
1135 | 1147 | module instead of having per/file stuff (except for files with |
|
1136 | 1148 | particular licenses, like the MIT/PSF-licensed codes). |
|
1137 | 1149 | |
|
1138 | 1150 | * IPython/Debugger.py: remove dead code for python 2.1 |
|
1139 | 1151 | |
|
1140 | 1152 | 2004-10-04 Fernando Perez <fperez@colorado.edu> |
|
1141 | 1153 | |
|
1142 | 1154 | * IPython/iplib.py (ipmagic): New function for accessing magics |
|
1143 | 1155 | via a normal python function call. |
|
1144 | 1156 | |
|
1145 | 1157 | * IPython/Magic.py (Magic.magic_magic): Change the magic escape |
|
1146 | 1158 | from '@' to '%', to accomodate the new @decorator syntax of python |
|
1147 | 1159 | 2.4. |
|
1148 | 1160 | |
|
1149 | 1161 | 2004-09-29 Fernando Perez <fperez@colorado.edu> |
|
1150 | 1162 | |
|
1151 | 1163 | * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to |
|
1152 | 1164 | matplotlib.use to prevent running scripts which try to switch |
|
1153 | 1165 | interactive backends from within ipython. This will just crash |
|
1154 | 1166 | the python interpreter, so we can't allow it (but a detailed error |
|
1155 | 1167 | is given to the user). |
|
1156 | 1168 | |
|
1157 | 1169 | 2004-09-28 Fernando Perez <fperez@colorado.edu> |
|
1158 | 1170 | |
|
1159 | 1171 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): |
|
1160 | 1172 | matplotlib-related fixes so that using @run with non-matplotlib |
|
1161 | 1173 | scripts doesn't pop up spurious plot windows. This requires |
|
1162 | 1174 | matplotlib >= 0.63, where I had to make some changes as well. |
|
1163 | 1175 | |
|
1164 | 1176 | * IPython/ipmaker.py (make_IPython): update version requirement to |
|
1165 | 1177 | python 2.2. |
|
1166 | 1178 | |
|
1167 | 1179 | * IPython/iplib.py (InteractiveShell.mainloop): Add an optional |
|
1168 | 1180 | banner arg for embedded customization. |
|
1169 | 1181 | |
|
1170 | 1182 | * IPython/Magic.py (Magic.__init__): big cleanup to remove all |
|
1171 | 1183 | explicit uses of __IP as the IPython's instance name. Now things |
|
1172 | 1184 | are properly handled via the shell.name value. The actual code |
|
1173 | 1185 | is a bit ugly b/c I'm doing it via a global in Magic.py, but this |
|
1174 | 1186 | is much better than before. I'll clean things completely when the |
|
1175 | 1187 | magic stuff gets a real overhaul. |
|
1176 | 1188 | |
|
1177 | 1189 | * ipython.1: small fixes, sent in by Jack Moffit. He also sent in |
|
1178 | 1190 | minor changes to debian dir. |
|
1179 | 1191 | |
|
1180 | 1192 | * IPython/iplib.py (InteractiveShell.__init__): Fix adding a |
|
1181 | 1193 | pointer to the shell itself in the interactive namespace even when |
|
1182 | 1194 | a user-supplied dict is provided. This is needed for embedding |
|
1183 | 1195 | purposes (found by tests with Michel Sanner). |
|
1184 | 1196 | |
|
1185 | 1197 | 2004-09-27 Fernando Perez <fperez@colorado.edu> |
|
1186 | 1198 | |
|
1187 | 1199 | * IPython/UserConfig/ipythonrc: remove []{} from |
|
1188 | 1200 | readline_remove_delims, so that things like [modname.<TAB> do |
|
1189 | 1201 | proper completion. This disables [].TAB, but that's a less common |
|
1190 | 1202 | case than module names in list comprehensions, for example. |
|
1191 | 1203 | Thanks to a report by Andrea Riciputi. |
|
1192 | 1204 | |
|
1193 | 1205 | 2004-09-09 Fernando Perez <fperez@colorado.edu> |
|
1194 | 1206 | |
|
1195 | 1207 | * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid |
|
1196 | 1208 | blocking problems in win32 and osx. Fix by John. |
|
1197 | 1209 | |
|
1198 | 1210 | 2004-09-08 Fernando Perez <fperez@colorado.edu> |
|
1199 | 1211 | |
|
1200 | 1212 | * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug |
|
1201 | 1213 | for Win32 and OSX. Fix by John Hunter. |
|
1202 | 1214 | |
|
1203 | 1215 | 2004-08-30 *** Released version 0.6.3 |
|
1204 | 1216 | |
|
1205 | 1217 | 2004-08-30 Fernando Perez <fperez@colorado.edu> |
|
1206 | 1218 | |
|
1207 | 1219 | * setup.py (isfile): Add manpages to list of dependent files to be |
|
1208 | 1220 | updated. |
|
1209 | 1221 | |
|
1210 | 1222 | 2004-08-27 Fernando Perez <fperez@colorado.edu> |
|
1211 | 1223 | |
|
1212 | 1224 | * IPython/Shell.py (start): I've disabled -wthread and -gthread |
|
1213 | 1225 | for now. They don't really work with standalone WX/GTK code |
|
1214 | 1226 | (though matplotlib IS working fine with both of those backends). |
|
1215 | 1227 | This will neeed much more testing. I disabled most things with |
|
1216 | 1228 | comments, so turning it back on later should be pretty easy. |
|
1217 | 1229 | |
|
1218 | 1230 | * IPython/iplib.py (InteractiveShell.__init__): Fix accidental |
|
1219 | 1231 | autocalling of expressions like r'foo', by modifying the line |
|
1220 | 1232 | split regexp. Closes |
|
1221 | 1233 | http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas |
|
1222 | 1234 | Riley <ipythonbugs-AT-sabi.net>. |
|
1223 | 1235 | (InteractiveShell.mainloop): honor --nobanner with banner |
|
1224 | 1236 | extensions. |
|
1225 | 1237 | |
|
1226 | 1238 | * IPython/Shell.py: Significant refactoring of all classes, so |
|
1227 | 1239 | that we can really support ALL matplotlib backends and threading |
|
1228 | 1240 | models (John spotted a bug with Tk which required this). Now we |
|
1229 | 1241 | should support single-threaded, WX-threads and GTK-threads, both |
|
1230 | 1242 | for generic code and for matplotlib. |
|
1231 | 1243 | |
|
1232 | 1244 | * IPython/ipmaker.py (__call__): Changed -mpthread option to |
|
1233 | 1245 | -pylab, to simplify things for users. Will also remove the pylab |
|
1234 | 1246 | profile, since now all of matplotlib configuration is directly |
|
1235 | 1247 | handled here. This also reduces startup time. |
|
1236 | 1248 | |
|
1237 | 1249 | * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of |
|
1238 | 1250 | shell wasn't being correctly called. Also in IPShellWX. |
|
1239 | 1251 | |
|
1240 | 1252 | * IPython/iplib.py (InteractiveShell.__init__): Added option to |
|
1241 | 1253 | fine-tune banner. |
|
1242 | 1254 | |
|
1243 | 1255 | * IPython/numutils.py (spike): Deprecate these spike functions, |
|
1244 | 1256 | delete (long deprecated) gnuplot_exec handler. |
|
1245 | 1257 | |
|
1246 | 1258 | 2004-08-26 Fernando Perez <fperez@colorado.edu> |
|
1247 | 1259 | |
|
1248 | 1260 | * ipython.1: Update for threading options, plus some others which |
|
1249 | 1261 | were missing. |
|
1250 | 1262 | |
|
1251 | 1263 | * IPython/ipmaker.py (__call__): Added -wthread option for |
|
1252 | 1264 | wxpython thread handling. Make sure threading options are only |
|
1253 | 1265 | valid at the command line. |
|
1254 | 1266 | |
|
1255 | 1267 | * scripts/ipython: moved shell selection into a factory function |
|
1256 | 1268 | in Shell.py, to keep the starter script to a minimum. |
|
1257 | 1269 | |
|
1258 | 1270 | 2004-08-25 Fernando Perez <fperez@colorado.edu> |
|
1259 | 1271 | |
|
1260 | 1272 | * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by |
|
1261 | 1273 | John. Along with some recent changes he made to matplotlib, the |
|
1262 | 1274 | next versions of both systems should work very well together. |
|
1263 | 1275 | |
|
1264 | 1276 | 2004-08-24 Fernando Perez <fperez@colorado.edu> |
|
1265 | 1277 | |
|
1266 | 1278 | * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I |
|
1267 | 1279 | tried to switch the profiling to using hotshot, but I'm getting |
|
1268 | 1280 | strange errors from prof.runctx() there. I may be misreading the |
|
1269 | 1281 | docs, but it looks weird. For now the profiling code will |
|
1270 | 1282 | continue to use the standard profiler. |
|
1271 | 1283 | |
|
1272 | 1284 | 2004-08-23 Fernando Perez <fperez@colorado.edu> |
|
1273 | 1285 | |
|
1274 | 1286 | * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX |
|
1275 | 1287 | threaded shell, by John Hunter. It's not quite ready yet, but |
|
1276 | 1288 | close. |
|
1277 | 1289 | |
|
1278 | 1290 | 2004-08-22 Fernando Perez <fperez@colorado.edu> |
|
1279 | 1291 | |
|
1280 | 1292 | * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also |
|
1281 | 1293 | in Magic and ultraTB. |
|
1282 | 1294 | |
|
1283 | 1295 | * ipython.1: document threading options in manpage. |
|
1284 | 1296 | |
|
1285 | 1297 | * scripts/ipython: Changed name of -thread option to -gthread, |
|
1286 | 1298 | since this is GTK specific. I want to leave the door open for a |
|
1287 | 1299 | -wthread option for WX, which will most likely be necessary. This |
|
1288 | 1300 | change affects usage and ipmaker as well. |
|
1289 | 1301 | |
|
1290 | 1302 | * IPython/Shell.py (matplotlib_shell): Add a factory function to |
|
1291 | 1303 | handle the matplotlib shell issues. Code by John Hunter |
|
1292 | 1304 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
1293 | 1305 | (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's |
|
1294 | 1306 | broken (and disabled for end users) for now, but it puts the |
|
1295 | 1307 | infrastructure in place. |
|
1296 | 1308 | |
|
1297 | 1309 | 2004-08-21 Fernando Perez <fperez@colorado.edu> |
|
1298 | 1310 | |
|
1299 | 1311 | * ipythonrc-pylab: Add matplotlib support. |
|
1300 | 1312 | |
|
1301 | 1313 | * matplotlib_config.py: new files for matplotlib support, part of |
|
1302 | 1314 | the pylab profile. |
|
1303 | 1315 | |
|
1304 | 1316 | * IPython/usage.py (__doc__): documented the threading options. |
|
1305 | 1317 | |
|
1306 | 1318 | 2004-08-20 Fernando Perez <fperez@colorado.edu> |
|
1307 | 1319 | |
|
1308 | 1320 | * ipython: Modified the main calling routine to handle the -thread |
|
1309 | 1321 | and -mpthread options. This needs to be done as a top-level hack, |
|
1310 | 1322 | because it determines which class to instantiate for IPython |
|
1311 | 1323 | itself. |
|
1312 | 1324 | |
|
1313 | 1325 | * IPython/Shell.py (MTInteractiveShell.__init__): New set of |
|
1314 | 1326 | classes to support multithreaded GTK operation without blocking, |
|
1315 | 1327 | and matplotlib with all backends. This is a lot of still very |
|
1316 | 1328 | experimental code, and threads are tricky. So it may still have a |
|
1317 | 1329 | few rough edges... This code owes a lot to |
|
1318 | 1330 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by |
|
1319 | 1331 | Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and |
|
1320 | 1332 | to John Hunter for all the matplotlib work. |
|
1321 | 1333 | |
|
1322 | 1334 | * IPython/ipmaker.py (__call__): Added -thread and -mpthread |
|
1323 | 1335 | options for gtk thread and matplotlib support. |
|
1324 | 1336 | |
|
1325 | 1337 | 2004-08-16 Fernando Perez <fperez@colorado.edu> |
|
1326 | 1338 | |
|
1327 | 1339 | * IPython/iplib.py (InteractiveShell.__init__): don't trigger |
|
1328 | 1340 | autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug |
|
1329 | 1341 | reported by Stephen Walton <stephen.walton-AT-csun.edu>. |
|
1330 | 1342 | |
|
1331 | 1343 | 2004-08-11 Fernando Perez <fperez@colorado.edu> |
|
1332 | 1344 | |
|
1333 | 1345 | * setup.py (isfile): Fix build so documentation gets updated for |
|
1334 | 1346 | rpms (it was only done for .tgz builds). |
|
1335 | 1347 | |
|
1336 | 1348 | 2004-08-10 Fernando Perez <fperez@colorado.edu> |
|
1337 | 1349 | |
|
1338 | 1350 | * genutils.py (Term): Fix misspell of stdin stream (sin->cin). |
|
1339 | 1351 | |
|
1340 | 1352 | * iplib.py : Silence syntax error exceptions in tab-completion. |
|
1341 | 1353 | |
|
1342 | 1354 | 2004-08-05 Fernando Perez <fperez@colorado.edu> |
|
1343 | 1355 | |
|
1344 | 1356 | * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set |
|
1345 | 1357 | 'color off' mark for continuation prompts. This was causing long |
|
1346 | 1358 | continuation lines to mis-wrap. |
|
1347 | 1359 | |
|
1348 | 1360 | 2004-08-01 Fernando Perez <fperez@colorado.edu> |
|
1349 | 1361 | |
|
1350 | 1362 | * IPython/ipmaker.py (make_IPython): Allow the shell class used |
|
1351 | 1363 | for building ipython to be a parameter. All this is necessary |
|
1352 | 1364 | right now to have a multithreaded version, but this insane |
|
1353 | 1365 | non-design will be cleaned up soon. For now, it's a hack that |
|
1354 | 1366 | works. |
|
1355 | 1367 | |
|
1356 | 1368 | * IPython/Shell.py (IPShell.__init__): Stop using mutable default |
|
1357 | 1369 | args in various places. No bugs so far, but it's a dangerous |
|
1358 | 1370 | practice. |
|
1359 | 1371 | |
|
1360 | 1372 | 2004-07-31 Fernando Perez <fperez@colorado.edu> |
|
1361 | 1373 | |
|
1362 | 1374 | * IPython/iplib.py (complete): ignore SyntaxError exceptions to |
|
1363 | 1375 | fix completion of files with dots in their names under most |
|
1364 | 1376 | profiles (pysh was OK because the completion order is different). |
|
1365 | 1377 | |
|
1366 | 1378 | 2004-07-27 Fernando Perez <fperez@colorado.edu> |
|
1367 | 1379 | |
|
1368 | 1380 | * IPython/iplib.py (InteractiveShell.__init__): build dict of |
|
1369 | 1381 | keywords manually, b/c the one in keyword.py was removed in python |
|
1370 | 1382 | 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>. |
|
1371 | 1383 | This is NOT a bug under python 2.3 and earlier. |
|
1372 | 1384 | |
|
1373 | 1385 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1374 | 1386 | |
|
1375 | 1387 | * IPython/ultraTB.py (VerboseTB.text): Add another |
|
1376 | 1388 | linecache.checkcache() call to try to prevent inspect.py from |
|
1377 | 1389 | crashing under python 2.3. I think this fixes |
|
1378 | 1390 | http://www.scipy.net/roundup/ipython/issue17. |
|
1379 | 1391 | |
|
1380 | 1392 | 2004-07-26 *** Released version 0.6.2 |
|
1381 | 1393 | |
|
1382 | 1394 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1383 | 1395 | |
|
1384 | 1396 | * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would |
|
1385 | 1397 | fail for any number. |
|
1386 | 1398 | (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for |
|
1387 | 1399 | empty bookmarks. |
|
1388 | 1400 | |
|
1389 | 1401 | 2004-07-26 *** Released version 0.6.1 |
|
1390 | 1402 | |
|
1391 | 1403 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1392 | 1404 | |
|
1393 | 1405 | * ipython_win_post_install.py (run): Added pysh shortcut for Windows. |
|
1394 | 1406 | |
|
1395 | 1407 | * IPython/iplib.py (protect_filename): Applied Ville's patch for |
|
1396 | 1408 | escaping '()[]{}' in filenames. |
|
1397 | 1409 | |
|
1398 | 1410 | * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for |
|
1399 | 1411 | Python 2.2 users who lack a proper shlex.split. |
|
1400 | 1412 | |
|
1401 | 1413 | 2004-07-19 Fernando Perez <fperez@colorado.edu> |
|
1402 | 1414 | |
|
1403 | 1415 | * IPython/iplib.py (InteractiveShell.init_readline): Add support |
|
1404 | 1416 | for reading readline's init file. I follow the normal chain: |
|
1405 | 1417 | $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a |
|
1406 | 1418 | report by Mike Heeter. This closes |
|
1407 | 1419 | http://www.scipy.net/roundup/ipython/issue16. |
|
1408 | 1420 | |
|
1409 | 1421 | 2004-07-18 Fernando Perez <fperez@colorado.edu> |
|
1410 | 1422 | |
|
1411 | 1423 | * IPython/iplib.py (__init__): Add better handling of '\' under |
|
1412 | 1424 | Win32 for filenames. After a patch by Ville. |
|
1413 | 1425 | |
|
1414 | 1426 | 2004-07-17 Fernando Perez <fperez@colorado.edu> |
|
1415 | 1427 | |
|
1416 | 1428 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1417 | 1429 | autocalling would be triggered for 'foo is bar' if foo is |
|
1418 | 1430 | callable. I also cleaned up the autocall detection code to use a |
|
1419 | 1431 | regexp, which is faster. Bug reported by Alexander Schmolck. |
|
1420 | 1432 | |
|
1421 | 1433 | * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with |
|
1422 | 1434 | '?' in them would confuse the help system. Reported by Alex |
|
1423 | 1435 | Schmolck. |
|
1424 | 1436 | |
|
1425 | 1437 | 2004-07-16 Fernando Perez <fperez@colorado.edu> |
|
1426 | 1438 | |
|
1427 | 1439 | * IPython/GnuplotInteractive.py (__all__): added plot2. |
|
1428 | 1440 | |
|
1429 | 1441 | * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for |
|
1430 | 1442 | plotting dictionaries, lists or tuples of 1d arrays. |
|
1431 | 1443 | |
|
1432 | 1444 | * IPython/Magic.py (Magic.magic_hist): small clenaups and |
|
1433 | 1445 | optimizations. |
|
1434 | 1446 | |
|
1435 | 1447 | * IPython/iplib.py:Remove old Changelog info for cleanup. This is |
|
1436 | 1448 | the information which was there from Janko's original IPP code: |
|
1437 | 1449 | |
|
1438 | 1450 | 03.05.99 20:53 porto.ifm.uni-kiel.de |
|
1439 | 1451 | --Started changelog. |
|
1440 | 1452 | --make clear do what it say it does |
|
1441 | 1453 | --added pretty output of lines from inputcache |
|
1442 | 1454 | --Made Logger a mixin class, simplifies handling of switches |
|
1443 | 1455 | --Added own completer class. .string<TAB> expands to last history |
|
1444 | 1456 | line which starts with string. The new expansion is also present |
|
1445 | 1457 | with Ctrl-r from the readline library. But this shows, who this |
|
1446 | 1458 | can be done for other cases. |
|
1447 | 1459 | --Added convention that all shell functions should accept a |
|
1448 | 1460 | parameter_string This opens the door for different behaviour for |
|
1449 | 1461 | each function. @cd is a good example of this. |
|
1450 | 1462 | |
|
1451 | 1463 | 04.05.99 12:12 porto.ifm.uni-kiel.de |
|
1452 | 1464 | --added logfile rotation |
|
1453 | 1465 | --added new mainloop method which freezes first the namespace |
|
1454 | 1466 | |
|
1455 | 1467 | 07.05.99 21:24 porto.ifm.uni-kiel.de |
|
1456 | 1468 | --added the docreader classes. Now there is a help system. |
|
1457 | 1469 | -This is only a first try. Currently it's not easy to put new |
|
1458 | 1470 | stuff in the indices. But this is the way to go. Info would be |
|
1459 | 1471 | better, but HTML is every where and not everybody has an info |
|
1460 | 1472 | system installed and it's not so easy to change html-docs to info. |
|
1461 | 1473 | --added global logfile option |
|
1462 | 1474 | --there is now a hook for object inspection method pinfo needs to |
|
1463 | 1475 | be provided for this. Can be reached by two '??'. |
|
1464 | 1476 | |
|
1465 | 1477 | 08.05.99 20:51 porto.ifm.uni-kiel.de |
|
1466 | 1478 | --added a README |
|
1467 | 1479 | --bug in rc file. Something has changed so functions in the rc |
|
1468 | 1480 | file need to reference the shell and not self. Not clear if it's a |
|
1469 | 1481 | bug or feature. |
|
1470 | 1482 | --changed rc file for new behavior |
|
1471 | 1483 | |
|
1472 | 1484 | 2004-07-15 Fernando Perez <fperez@colorado.edu> |
|
1473 | 1485 | |
|
1474 | 1486 | * IPython/Logger.py (Logger.log): fixed recent bug where the input |
|
1475 | 1487 | cache was falling out of sync in bizarre manners when multi-line |
|
1476 | 1488 | input was present. Minor optimizations and cleanup. |
|
1477 | 1489 | |
|
1478 | 1490 | (Logger): Remove old Changelog info for cleanup. This is the |
|
1479 | 1491 | information which was there from Janko's original code: |
|
1480 | 1492 | |
|
1481 | 1493 | Changes to Logger: - made the default log filename a parameter |
|
1482 | 1494 | |
|
1483 | 1495 | - put a check for lines beginning with !@? in log(). Needed |
|
1484 | 1496 | (even if the handlers properly log their lines) for mid-session |
|
1485 | 1497 | logging activation to work properly. Without this, lines logged |
|
1486 | 1498 | in mid session, which get read from the cache, would end up |
|
1487 | 1499 | 'bare' (with !@? in the open) in the log. Now they are caught |
|
1488 | 1500 | and prepended with a #. |
|
1489 | 1501 | |
|
1490 | 1502 | * IPython/iplib.py (InteractiveShell.init_readline): added check |
|
1491 | 1503 | in case MagicCompleter fails to be defined, so we don't crash. |
|
1492 | 1504 | |
|
1493 | 1505 | 2004-07-13 Fernando Perez <fperez@colorado.edu> |
|
1494 | 1506 | |
|
1495 | 1507 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation |
|
1496 | 1508 | of EPS if the requested filename ends in '.eps'. |
|
1497 | 1509 | |
|
1498 | 1510 | 2004-07-04 Fernando Perez <fperez@colorado.edu> |
|
1499 | 1511 | |
|
1500 | 1512 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix |
|
1501 | 1513 | escaping of quotes when calling the shell. |
|
1502 | 1514 | |
|
1503 | 1515 | 2004-07-02 Fernando Perez <fperez@colorado.edu> |
|
1504 | 1516 | |
|
1505 | 1517 | * IPython/Prompts.py (CachedOutput.update): Fix problem with |
|
1506 | 1518 | gettext not working because we were clobbering '_'. Fixes |
|
1507 | 1519 | http://www.scipy.net/roundup/ipython/issue6. |
|
1508 | 1520 | |
|
1509 | 1521 | 2004-07-01 Fernando Perez <fperez@colorado.edu> |
|
1510 | 1522 | |
|
1511 | 1523 | * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling |
|
1512 | 1524 | into @cd. Patch by Ville. |
|
1513 | 1525 | |
|
1514 | 1526 | * IPython/iplib.py (InteractiveShell.post_config_initialization): |
|
1515 | 1527 | new function to store things after ipmaker runs. Patch by Ville. |
|
1516 | 1528 | Eventually this will go away once ipmaker is removed and the class |
|
1517 | 1529 | gets cleaned up, but for now it's ok. Key functionality here is |
|
1518 | 1530 | the addition of the persistent storage mechanism, a dict for |
|
1519 | 1531 | keeping data across sessions (for now just bookmarks, but more can |
|
1520 | 1532 | be implemented later). |
|
1521 | 1533 | |
|
1522 | 1534 | * IPython/Magic.py (Magic.magic_bookmark): New bookmark system, |
|
1523 | 1535 | persistent across sections. Patch by Ville, I modified it |
|
1524 | 1536 | soemwhat to allow bookmarking arbitrary dirs other than CWD. Also |
|
1525 | 1537 | added a '-l' option to list all bookmarks. |
|
1526 | 1538 | |
|
1527 | 1539 | * IPython/iplib.py (InteractiveShell.atexit_operations): new |
|
1528 | 1540 | center for cleanup. Registered with atexit.register(). I moved |
|
1529 | 1541 | here the old exit_cleanup(). After a patch by Ville. |
|
1530 | 1542 | |
|
1531 | 1543 | * IPython/Magic.py (get_py_filename): added '~' to the accepted |
|
1532 | 1544 | characters in the hacked shlex_split for python 2.2. |
|
1533 | 1545 | |
|
1534 | 1546 | * IPython/iplib.py (file_matches): more fixes to filenames with |
|
1535 | 1547 | whitespace in them. It's not perfect, but limitations in python's |
|
1536 | 1548 | readline make it impossible to go further. |
|
1537 | 1549 | |
|
1538 | 1550 | 2004-06-29 Fernando Perez <fperez@colorado.edu> |
|
1539 | 1551 | |
|
1540 | 1552 | * IPython/iplib.py (file_matches): escape whitespace correctly in |
|
1541 | 1553 | filename completions. Bug reported by Ville. |
|
1542 | 1554 | |
|
1543 | 1555 | 2004-06-28 Fernando Perez <fperez@colorado.edu> |
|
1544 | 1556 | |
|
1545 | 1557 | * IPython/ipmaker.py (__call__): Added per-profile histories. Now |
|
1546 | 1558 | the history file will be called 'history-PROFNAME' (or just |
|
1547 | 1559 | 'history' if no profile is loaded). I was getting annoyed at |
|
1548 | 1560 | getting my Numerical work history clobbered by pysh sessions. |
|
1549 | 1561 | |
|
1550 | 1562 | * IPython/iplib.py (InteractiveShell.__init__): Internal |
|
1551 | 1563 | getoutputerror() function so that we can honor the system_verbose |
|
1552 | 1564 | flag for _all_ system calls. I also added escaping of # |
|
1553 | 1565 | characters here to avoid confusing Itpl. |
|
1554 | 1566 | |
|
1555 | 1567 | * IPython/Magic.py (shlex_split): removed call to shell in |
|
1556 | 1568 | parse_options and replaced it with shlex.split(). The annoying |
|
1557 | 1569 | part was that in Python 2.2, shlex.split() doesn't exist, so I had |
|
1558 | 1570 | to backport it from 2.3, with several frail hacks (the shlex |
|
1559 | 1571 | module is rather limited in 2.2). Thanks to a suggestion by Ville |
|
1560 | 1572 | Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no |
|
1561 | 1573 | problem. |
|
1562 | 1574 | |
|
1563 | 1575 | (Magic.magic_system_verbose): new toggle to print the actual |
|
1564 | 1576 | system calls made by ipython. Mainly for debugging purposes. |
|
1565 | 1577 | |
|
1566 | 1578 | * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which |
|
1567 | 1579 | doesn't support persistence. Reported (and fix suggested) by |
|
1568 | 1580 | Travis Caldwell <travis_caldwell2000@yahoo.com>. |
|
1569 | 1581 | |
|
1570 | 1582 | 2004-06-26 Fernando Perez <fperez@colorado.edu> |
|
1571 | 1583 | |
|
1572 | 1584 | * IPython/Logger.py (Logger.log): fix to handle correctly empty |
|
1573 | 1585 | continue prompts. |
|
1574 | 1586 | |
|
1575 | 1587 | * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh() |
|
1576 | 1588 | function (basically a big docstring) and a few more things here to |
|
1577 | 1589 | speedup startup. pysh.py is now very lightweight. We want because |
|
1578 | 1590 | it gets execfile'd, while InterpreterExec gets imported, so |
|
1579 | 1591 | byte-compilation saves time. |
|
1580 | 1592 | |
|
1581 | 1593 | 2004-06-25 Fernando Perez <fperez@colorado.edu> |
|
1582 | 1594 | |
|
1583 | 1595 | * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd |
|
1584 | 1596 | -NUM', which was recently broken. |
|
1585 | 1597 | |
|
1586 | 1598 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow ! |
|
1587 | 1599 | in multi-line input (but not !!, which doesn't make sense there). |
|
1588 | 1600 | |
|
1589 | 1601 | * IPython/UserConfig/ipythonrc: made autoindent on by default. |
|
1590 | 1602 | It's just too useful, and people can turn it off in the less |
|
1591 | 1603 | common cases where it's a problem. |
|
1592 | 1604 | |
|
1593 | 1605 | 2004-06-24 Fernando Perez <fperez@colorado.edu> |
|
1594 | 1606 | |
|
1595 | 1607 | * IPython/iplib.py (InteractiveShell._prefilter): big change - |
|
1596 | 1608 | special syntaxes (like alias calling) is now allied in multi-line |
|
1597 | 1609 | input. This is still _very_ experimental, but it's necessary for |
|
1598 | 1610 | efficient shell usage combining python looping syntax with system |
|
1599 | 1611 | calls. For now it's restricted to aliases, I don't think it |
|
1600 | 1612 | really even makes sense to have this for magics. |
|
1601 | 1613 | |
|
1602 | 1614 | 2004-06-23 Fernando Perez <fperez@colorado.edu> |
|
1603 | 1615 | |
|
1604 | 1616 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added |
|
1605 | 1617 | $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd. |
|
1606 | 1618 | |
|
1607 | 1619 | * IPython/Magic.py (Magic.magic_rehashx): modified to handle |
|
1608 | 1620 | extensions under Windows (after code sent by Gary Bishop). The |
|
1609 | 1621 | extensions considered 'executable' are stored in IPython's rc |
|
1610 | 1622 | structure as win_exec_ext. |
|
1611 | 1623 | |
|
1612 | 1624 | * IPython/genutils.py (shell): new function, like system() but |
|
1613 | 1625 | without return value. Very useful for interactive shell work. |
|
1614 | 1626 | |
|
1615 | 1627 | * IPython/Magic.py (Magic.magic_unalias): New @unalias function to |
|
1616 | 1628 | delete aliases. |
|
1617 | 1629 | |
|
1618 | 1630 | * IPython/iplib.py (InteractiveShell.alias_table_update): make |
|
1619 | 1631 | sure that the alias table doesn't contain python keywords. |
|
1620 | 1632 | |
|
1621 | 1633 | 2004-06-21 Fernando Perez <fperez@colorado.edu> |
|
1622 | 1634 | |
|
1623 | 1635 | * IPython/Magic.py (Magic.magic_rehash): Fix crash when |
|
1624 | 1636 | non-existent items are found in $PATH. Reported by Thorsten. |
|
1625 | 1637 | |
|
1626 | 1638 | 2004-06-20 Fernando Perez <fperez@colorado.edu> |
|
1627 | 1639 | |
|
1628 | 1640 | * IPython/iplib.py (complete): modified the completer so that the |
|
1629 | 1641 | order of priorities can be easily changed at runtime. |
|
1630 | 1642 | |
|
1631 | 1643 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): |
|
1632 | 1644 | Modified to auto-execute all lines beginning with '~', '/' or '.'. |
|
1633 | 1645 | |
|
1634 | 1646 | * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to |
|
1635 | 1647 | expand Python variables prepended with $ in all system calls. The |
|
1636 | 1648 | same was done to InteractiveShell.handle_shell_escape. Now all |
|
1637 | 1649 | system access mechanisms (!, !!, @sc, @sx and aliases) allow the |
|
1638 | 1650 | expansion of python variables and expressions according to the |
|
1639 | 1651 | syntax of PEP-215 - http://www.python.org/peps/pep-0215.html. |
|
1640 | 1652 | |
|
1641 | 1653 | Though PEP-215 has been rejected, a similar (but simpler) one |
|
1642 | 1654 | seems like it will go into Python 2.4, PEP-292 - |
|
1643 | 1655 | http://www.python.org/peps/pep-0292.html. |
|
1644 | 1656 | |
|
1645 | 1657 | I'll keep the full syntax of PEP-215, since IPython has since the |
|
1646 | 1658 | start used Ka-Ping Yee's reference implementation discussed there |
|
1647 | 1659 | (Itpl), and I actually like the powerful semantics it offers. |
|
1648 | 1660 | |
|
1649 | 1661 | In order to access normal shell variables, the $ has to be escaped |
|
1650 | 1662 | via an extra $. For example: |
|
1651 | 1663 | |
|
1652 | 1664 | In [7]: PATH='a python variable' |
|
1653 | 1665 | |
|
1654 | 1666 | In [8]: !echo $PATH |
|
1655 | 1667 | a python variable |
|
1656 | 1668 | |
|
1657 | 1669 | In [9]: !echo $$PATH |
|
1658 | 1670 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1659 | 1671 | |
|
1660 | 1672 | (Magic.parse_options): escape $ so the shell doesn't evaluate |
|
1661 | 1673 | things prematurely. |
|
1662 | 1674 | |
|
1663 | 1675 | * IPython/iplib.py (InteractiveShell.call_alias): added the |
|
1664 | 1676 | ability for aliases to expand python variables via $. |
|
1665 | 1677 | |
|
1666 | 1678 | * IPython/Magic.py (Magic.magic_rehash): based on the new alias |
|
1667 | 1679 | system, now there's a @rehash/@rehashx pair of magics. These work |
|
1668 | 1680 | like the csh rehash command, and can be invoked at any time. They |
|
1669 | 1681 | build a table of aliases to everything in the user's $PATH |
|
1670 | 1682 | (@rehash uses everything, @rehashx is slower but only adds |
|
1671 | 1683 | executable files). With this, the pysh.py-based shell profile can |
|
1672 | 1684 | now simply call rehash upon startup, and full access to all |
|
1673 | 1685 | programs in the user's path is obtained. |
|
1674 | 1686 | |
|
1675 | 1687 | * IPython/iplib.py (InteractiveShell.call_alias): The new alias |
|
1676 | 1688 | functionality is now fully in place. I removed the old dynamic |
|
1677 | 1689 | code generation based approach, in favor of a much lighter one |
|
1678 | 1690 | based on a simple dict. The advantage is that this allows me to |
|
1679 | 1691 | now have thousands of aliases with negligible cost (unthinkable |
|
1680 | 1692 | with the old system). |
|
1681 | 1693 | |
|
1682 | 1694 | 2004-06-19 Fernando Perez <fperez@colorado.edu> |
|
1683 | 1695 | |
|
1684 | 1696 | * IPython/iplib.py (__init__): extended MagicCompleter class to |
|
1685 | 1697 | also complete (last in priority) on user aliases. |
|
1686 | 1698 | |
|
1687 | 1699 | * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in |
|
1688 | 1700 | call to eval. |
|
1689 | 1701 | (ItplNS.__init__): Added a new class which functions like Itpl, |
|
1690 | 1702 | but allows configuring the namespace for the evaluation to occur |
|
1691 | 1703 | in. |
|
1692 | 1704 | |
|
1693 | 1705 | 2004-06-18 Fernando Perez <fperez@colorado.edu> |
|
1694 | 1706 | |
|
1695 | 1707 | * IPython/iplib.py (InteractiveShell.runcode): modify to print a |
|
1696 | 1708 | better message when 'exit' or 'quit' are typed (a common newbie |
|
1697 | 1709 | confusion). |
|
1698 | 1710 | |
|
1699 | 1711 | * IPython/Magic.py (Magic.magic_colors): Added the runtime color |
|
1700 | 1712 | check for Windows users. |
|
1701 | 1713 | |
|
1702 | 1714 | * IPython/iplib.py (InteractiveShell.user_setup): removed |
|
1703 | 1715 | disabling of colors for Windows. I'll test at runtime and issue a |
|
1704 | 1716 | warning if Gary's readline isn't found, as to nudge users to |
|
1705 | 1717 | download it. |
|
1706 | 1718 | |
|
1707 | 1719 | 2004-06-16 Fernando Perez <fperez@colorado.edu> |
|
1708 | 1720 | |
|
1709 | 1721 | * IPython/genutils.py (Stream.__init__): changed to print errors |
|
1710 | 1722 | to sys.stderr. I had a circular dependency here. Now it's |
|
1711 | 1723 | possible to run ipython as IDLE's shell (consider this pre-alpha, |
|
1712 | 1724 | since true stdout things end up in the starting terminal instead |
|
1713 | 1725 | of IDLE's out). |
|
1714 | 1726 | |
|
1715 | 1727 | * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for |
|
1716 | 1728 | users who haven't # updated their prompt_in2 definitions. Remove |
|
1717 | 1729 | eventually. |
|
1718 | 1730 | (multiple_replace): added credit to original ASPN recipe. |
|
1719 | 1731 | |
|
1720 | 1732 | 2004-06-15 Fernando Perez <fperez@colorado.edu> |
|
1721 | 1733 | |
|
1722 | 1734 | * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the |
|
1723 | 1735 | list of auto-defined aliases. |
|
1724 | 1736 | |
|
1725 | 1737 | 2004-06-13 Fernando Perez <fperez@colorado.edu> |
|
1726 | 1738 | |
|
1727 | 1739 | * setup.py (scriptfiles): Don't trigger win_post_install unless an |
|
1728 | 1740 | install was really requested (so setup.py can be used for other |
|
1729 | 1741 | things under Windows). |
|
1730 | 1742 | |
|
1731 | 1743 | 2004-06-10 Fernando Perez <fperez@colorado.edu> |
|
1732 | 1744 | |
|
1733 | 1745 | * IPython/Logger.py (Logger.create_log): Manually remove any old |
|
1734 | 1746 | backup, since os.remove may fail under Windows. Fixes bug |
|
1735 | 1747 | reported by Thorsten. |
|
1736 | 1748 | |
|
1737 | 1749 | 2004-06-09 Fernando Perez <fperez@colorado.edu> |
|
1738 | 1750 | |
|
1739 | 1751 | * examples/example-embed.py: fixed all references to %n (replaced |
|
1740 | 1752 | with \\# for ps1/out prompts and with \\D for ps2 prompts). Done |
|
1741 | 1753 | for all examples and the manual as well. |
|
1742 | 1754 | |
|
1743 | 1755 | 2004-06-08 Fernando Perez <fperez@colorado.edu> |
|
1744 | 1756 | |
|
1745 | 1757 | * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt |
|
1746 | 1758 | alignment and color management. All 3 prompt subsystems now |
|
1747 | 1759 | inherit from BasePrompt. |
|
1748 | 1760 | |
|
1749 | 1761 | * tools/release: updates for windows installer build and tag rpms |
|
1750 | 1762 | with python version (since paths are fixed). |
|
1751 | 1763 | |
|
1752 | 1764 | * IPython/UserConfig/ipythonrc: modified to use \# instead of %n, |
|
1753 | 1765 | which will become eventually obsolete. Also fixed the default |
|
1754 | 1766 | prompt_in2 to use \D, so at least new users start with the correct |
|
1755 | 1767 | defaults. |
|
1756 | 1768 | WARNING: Users with existing ipythonrc files will need to apply |
|
1757 | 1769 | this fix manually! |
|
1758 | 1770 | |
|
1759 | 1771 | * setup.py: make windows installer (.exe). This is finally the |
|
1760 | 1772 | integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>, |
|
1761 | 1773 | which I hadn't included because it required Python 2.3 (or recent |
|
1762 | 1774 | distutils). |
|
1763 | 1775 | |
|
1764 | 1776 | * IPython/usage.py (__doc__): update docs (and manpage) to reflect |
|
1765 | 1777 | usage of new '\D' escape. |
|
1766 | 1778 | |
|
1767 | 1779 | * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which |
|
1768 | 1780 | lacks os.getuid()) |
|
1769 | 1781 | (CachedOutput.set_colors): Added the ability to turn coloring |
|
1770 | 1782 | on/off with @colors even for manually defined prompt colors. It |
|
1771 | 1783 | uses a nasty global, but it works safely and via the generic color |
|
1772 | 1784 | handling mechanism. |
|
1773 | 1785 | (Prompt2.__init__): Introduced new escape '\D' for continuation |
|
1774 | 1786 | prompts. It represents the counter ('\#') as dots. |
|
1775 | 1787 | *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will |
|
1776 | 1788 | need to update their ipythonrc files and replace '%n' with '\D' in |
|
1777 | 1789 | their prompt_in2 settings everywhere. Sorry, but there's |
|
1778 | 1790 | otherwise no clean way to get all prompts to properly align. The |
|
1779 | 1791 | ipythonrc shipped with IPython has been updated. |
|
1780 | 1792 | |
|
1781 | 1793 | 2004-06-07 Fernando Perez <fperez@colorado.edu> |
|
1782 | 1794 | |
|
1783 | 1795 | * setup.py (isfile): Pass local_icons option to latex2html, so the |
|
1784 | 1796 | resulting HTML file is self-contained. Thanks to |
|
1785 | 1797 | dryice-AT-liu.com.cn for the tip. |
|
1786 | 1798 | |
|
1787 | 1799 | * pysh.py: I created a new profile 'shell', which implements a |
|
1788 | 1800 | _rudimentary_ IPython-based shell. This is in NO WAY a realy |
|
1789 | 1801 | system shell, nor will it become one anytime soon. It's mainly |
|
1790 | 1802 | meant to illustrate the use of the new flexible bash-like prompts. |
|
1791 | 1803 | I guess it could be used by hardy souls for true shell management, |
|
1792 | 1804 | but it's no tcsh/bash... pysh.py is loaded by the 'shell' |
|
1793 | 1805 | profile. This uses the InterpreterExec extension provided by |
|
1794 | 1806 | W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl> |
|
1795 | 1807 | |
|
1796 | 1808 | * IPython/Prompts.py (PromptOut.__str__): now it will correctly |
|
1797 | 1809 | auto-align itself with the length of the previous input prompt |
|
1798 | 1810 | (taking into account the invisible color escapes). |
|
1799 | 1811 | (CachedOutput.__init__): Large restructuring of this class. Now |
|
1800 | 1812 | all three prompts (primary1, primary2, output) are proper objects, |
|
1801 | 1813 | managed by the 'parent' CachedOutput class. The code is still a |
|
1802 | 1814 | bit hackish (all prompts share state via a pointer to the cache), |
|
1803 | 1815 | but it's overall far cleaner than before. |
|
1804 | 1816 | |
|
1805 | 1817 | * IPython/genutils.py (getoutputerror): modified to add verbose, |
|
1806 | 1818 | debug and header options. This makes the interface of all getout* |
|
1807 | 1819 | functions uniform. |
|
1808 | 1820 | (SystemExec.getoutputerror): added getoutputerror to SystemExec. |
|
1809 | 1821 | |
|
1810 | 1822 | * IPython/Magic.py (Magic.default_option): added a function to |
|
1811 | 1823 | allow registering default options for any magic command. This |
|
1812 | 1824 | makes it easy to have profiles which customize the magics globally |
|
1813 | 1825 | for a certain use. The values set through this function are |
|
1814 | 1826 | picked up by the parse_options() method, which all magics should |
|
1815 | 1827 | use to parse their options. |
|
1816 | 1828 | |
|
1817 | 1829 | * IPython/genutils.py (warn): modified the warnings framework to |
|
1818 | 1830 | use the Term I/O class. I'm trying to slowly unify all of |
|
1819 | 1831 | IPython's I/O operations to pass through Term. |
|
1820 | 1832 | |
|
1821 | 1833 | * IPython/Prompts.py (Prompt2._str_other): Added functionality in |
|
1822 | 1834 | the secondary prompt to correctly match the length of the primary |
|
1823 | 1835 | one for any prompt. Now multi-line code will properly line up |
|
1824 | 1836 | even for path dependent prompts, such as the new ones available |
|
1825 | 1837 | via the prompt_specials. |
|
1826 | 1838 | |
|
1827 | 1839 | 2004-06-06 Fernando Perez <fperez@colorado.edu> |
|
1828 | 1840 | |
|
1829 | 1841 | * IPython/Prompts.py (prompt_specials): Added the ability to have |
|
1830 | 1842 | bash-like special sequences in the prompts, which get |
|
1831 | 1843 | automatically expanded. Things like hostname, current working |
|
1832 | 1844 | directory and username are implemented already, but it's easy to |
|
1833 | 1845 | add more in the future. Thanks to a patch by W.J. van der Laan |
|
1834 | 1846 | <gnufnork-AT-hetdigitalegat.nl> |
|
1835 | 1847 | (prompt_specials): Added color support for prompt strings, so |
|
1836 | 1848 | users can define arbitrary color setups for their prompts. |
|
1837 | 1849 | |
|
1838 | 1850 | 2004-06-05 Fernando Perez <fperez@colorado.edu> |
|
1839 | 1851 | |
|
1840 | 1852 | * IPython/genutils.py (Term.reopen_all): Added Windows-specific |
|
1841 | 1853 | code to load Gary Bishop's readline and configure it |
|
1842 | 1854 | automatically. Thanks to Gary for help on this. |
|
1843 | 1855 | |
|
1844 | 1856 | 2004-06-01 Fernando Perez <fperez@colorado.edu> |
|
1845 | 1857 | |
|
1846 | 1858 | * IPython/Logger.py (Logger.create_log): fix bug for logging |
|
1847 | 1859 | with no filename (previous fix was incomplete). |
|
1848 | 1860 | |
|
1849 | 1861 | 2004-05-25 Fernando Perez <fperez@colorado.edu> |
|
1850 | 1862 | |
|
1851 | 1863 | * IPython/Magic.py (Magic.parse_options): fix bug where naked |
|
1852 | 1864 | parens would get passed to the shell. |
|
1853 | 1865 | |
|
1854 | 1866 | 2004-05-20 Fernando Perez <fperez@colorado.edu> |
|
1855 | 1867 | |
|
1856 | 1868 | * IPython/Magic.py (Magic.magic_prun): changed default profile |
|
1857 | 1869 | sort order to 'time' (the more common profiling need). |
|
1858 | 1870 | |
|
1859 | 1871 | * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache |
|
1860 | 1872 | so that source code shown is guaranteed in sync with the file on |
|
1861 | 1873 | disk (also changed in psource). Similar fix to the one for |
|
1862 | 1874 | ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du |
|
1863 | 1875 | <yann.ledu-AT-noos.fr>. |
|
1864 | 1876 | |
|
1865 | 1877 | * IPython/Magic.py (Magic.parse_options): Fixed bug where commands |
|
1866 | 1878 | with a single option would not be correctly parsed. Closes |
|
1867 | 1879 | http://www.scipy.net/roundup/ipython/issue14. This bug had been |
|
1868 | 1880 | introduced in 0.6.0 (on 2004-05-06). |
|
1869 | 1881 | |
|
1870 | 1882 | 2004-05-13 *** Released version 0.6.0 |
|
1871 | 1883 | |
|
1872 | 1884 | 2004-05-13 Fernando Perez <fperez@colorado.edu> |
|
1873 | 1885 | |
|
1874 | 1886 | * debian/: Added debian/ directory to CVS, so that debian support |
|
1875 | 1887 | is publicly accessible. The debian package is maintained by Jack |
|
1876 | 1888 | Moffit <jack-AT-xiph.org>. |
|
1877 | 1889 | |
|
1878 | 1890 | * Documentation: included the notes about an ipython-based system |
|
1879 | 1891 | shell (the hypothetical 'pysh') into the new_design.pdf document, |
|
1880 | 1892 | so that these ideas get distributed to users along with the |
|
1881 | 1893 | official documentation. |
|
1882 | 1894 | |
|
1883 | 1895 | 2004-05-10 Fernando Perez <fperez@colorado.edu> |
|
1884 | 1896 | |
|
1885 | 1897 | * IPython/Logger.py (Logger.create_log): fix recently introduced |
|
1886 | 1898 | bug (misindented line) where logstart would fail when not given an |
|
1887 | 1899 | explicit filename. |
|
1888 | 1900 | |
|
1889 | 1901 | 2004-05-09 Fernando Perez <fperez@colorado.edu> |
|
1890 | 1902 | |
|
1891 | 1903 | * IPython/Magic.py (Magic.parse_options): skip system call when |
|
1892 | 1904 | there are no options to look for. Faster, cleaner for the common |
|
1893 | 1905 | case. |
|
1894 | 1906 | |
|
1895 | 1907 | * Documentation: many updates to the manual: describing Windows |
|
1896 | 1908 | support better, Gnuplot updates, credits, misc small stuff. Also |
|
1897 | 1909 | updated the new_design doc a bit. |
|
1898 | 1910 | |
|
1899 | 1911 | 2004-05-06 *** Released version 0.6.0.rc1 |
|
1900 | 1912 | |
|
1901 | 1913 | 2004-05-06 Fernando Perez <fperez@colorado.edu> |
|
1902 | 1914 | |
|
1903 | 1915 | * IPython/ultraTB.py (ListTB.text): modified a ton of string += |
|
1904 | 1916 | operations to use the vastly more efficient list/''.join() method. |
|
1905 | 1917 | (FormattedTB.text): Fix |
|
1906 | 1918 | http://www.scipy.net/roundup/ipython/issue12 - exception source |
|
1907 | 1919 | extract not updated after reload. Thanks to Mike Salib |
|
1908 | 1920 | <msalib-AT-mit.edu> for pinning the source of the problem. |
|
1909 | 1921 | Fortunately, the solution works inside ipython and doesn't require |
|
1910 | 1922 | any changes to python proper. |
|
1911 | 1923 | |
|
1912 | 1924 | * IPython/Magic.py (Magic.parse_options): Improved to process the |
|
1913 | 1925 | argument list as a true shell would (by actually using the |
|
1914 | 1926 | underlying system shell). This way, all @magics automatically get |
|
1915 | 1927 | shell expansion for variables. Thanks to a comment by Alex |
|
1916 | 1928 | Schmolck. |
|
1917 | 1929 | |
|
1918 | 1930 | 2004-04-04 Fernando Perez <fperez@colorado.edu> |
|
1919 | 1931 | |
|
1920 | 1932 | * IPython/iplib.py (InteractiveShell.interact): Added a special |
|
1921 | 1933 | trap for a debugger quit exception, which is basically impossible |
|
1922 | 1934 | to handle by normal mechanisms, given what pdb does to the stack. |
|
1923 | 1935 | This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>. |
|
1924 | 1936 | |
|
1925 | 1937 | 2004-04-03 Fernando Perez <fperez@colorado.edu> |
|
1926 | 1938 | |
|
1927 | 1939 | * IPython/genutils.py (Term): Standardized the names of the Term |
|
1928 | 1940 | class streams to cin/cout/cerr, following C++ naming conventions |
|
1929 | 1941 | (I can't use in/out/err because 'in' is not a valid attribute |
|
1930 | 1942 | name). |
|
1931 | 1943 | |
|
1932 | 1944 | * IPython/iplib.py (InteractiveShell.interact): don't increment |
|
1933 | 1945 | the prompt if there's no user input. By Daniel 'Dang' Griffith |
|
1934 | 1946 | <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from |
|
1935 | 1947 | Francois Pinard. |
|
1936 | 1948 | |
|
1937 | 1949 | 2004-04-02 Fernando Perez <fperez@colorado.edu> |
|
1938 | 1950 | |
|
1939 | 1951 | * IPython/genutils.py (Stream.__init__): Modified to survive at |
|
1940 | 1952 | least importing in contexts where stdin/out/err aren't true file |
|
1941 | 1953 | objects, such as PyCrust (they lack fileno() and mode). However, |
|
1942 | 1954 | the recovery facilities which rely on these things existing will |
|
1943 | 1955 | not work. |
|
1944 | 1956 | |
|
1945 | 1957 | 2004-04-01 Fernando Perez <fperez@colorado.edu> |
|
1946 | 1958 | |
|
1947 | 1959 | * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to |
|
1948 | 1960 | use the new getoutputerror() function, so it properly |
|
1949 | 1961 | distinguishes stdout/err. |
|
1950 | 1962 | |
|
1951 | 1963 | * IPython/genutils.py (getoutputerror): added a function to |
|
1952 | 1964 | capture separately the standard output and error of a command. |
|
1953 | 1965 | After a comment from dang on the mailing lists. This code is |
|
1954 | 1966 | basically a modified version of commands.getstatusoutput(), from |
|
1955 | 1967 | the standard library. |
|
1956 | 1968 | |
|
1957 | 1969 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): added |
|
1958 | 1970 | '!!' as a special syntax (shorthand) to access @sx. |
|
1959 | 1971 | |
|
1960 | 1972 | * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell |
|
1961 | 1973 | command and return its output as a list split on '\n'. |
|
1962 | 1974 | |
|
1963 | 1975 | 2004-03-31 Fernando Perez <fperez@colorado.edu> |
|
1964 | 1976 | |
|
1965 | 1977 | * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__ |
|
1966 | 1978 | method to dictionaries used as FakeModule instances if they lack |
|
1967 | 1979 | it. At least pydoc in python2.3 breaks for runtime-defined |
|
1968 | 1980 | functions without this hack. At some point I need to _really_ |
|
1969 | 1981 | understand what FakeModule is doing, because it's a gross hack. |
|
1970 | 1982 | But it solves Arnd's problem for now... |
|
1971 | 1983 | |
|
1972 | 1984 | 2004-02-27 Fernando Perez <fperez@colorado.edu> |
|
1973 | 1985 | |
|
1974 | 1986 | * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate' |
|
1975 | 1987 | mode would behave erratically. Also increased the number of |
|
1976 | 1988 | possible logs in rotate mod to 999. Thanks to Rod Holland |
|
1977 | 1989 | <rhh@StructureLABS.com> for the report and fixes. |
|
1978 | 1990 | |
|
1979 | 1991 | 2004-02-26 Fernando Perez <fperez@colorado.edu> |
|
1980 | 1992 | |
|
1981 | 1993 | * IPython/genutils.py (page): Check that the curses module really |
|
1982 | 1994 | has the initscr attribute before trying to use it. For some |
|
1983 | 1995 | reason, the Solaris curses module is missing this. I think this |
|
1984 | 1996 | should be considered a Solaris python bug, but I'm not sure. |
|
1985 | 1997 | |
|
1986 | 1998 | 2004-01-17 Fernando Perez <fperez@colorado.edu> |
|
1987 | 1999 | |
|
1988 | 2000 | * IPython/genutils.py (Stream.__init__): Changes to try to make |
|
1989 | 2001 | ipython robust against stdin/out/err being closed by the user. |
|
1990 | 2002 | This is 'user error' (and blocks a normal python session, at least |
|
1991 | 2003 | the stdout case). However, Ipython should be able to survive such |
|
1992 | 2004 | instances of abuse as gracefully as possible. To simplify the |
|
1993 | 2005 | coding and maintain compatibility with Gary Bishop's Term |
|
1994 | 2006 | contributions, I've made use of classmethods for this. I think |
|
1995 | 2007 | this introduces a dependency on python 2.2. |
|
1996 | 2008 | |
|
1997 | 2009 | 2004-01-13 Fernando Perez <fperez@colorado.edu> |
|
1998 | 2010 | |
|
1999 | 2011 | * IPython/numutils.py (exp_safe): simplified the code a bit and |
|
2000 | 2012 | removed the need for importing the kinds module altogether. |
|
2001 | 2013 | |
|
2002 | 2014 | 2004-01-06 Fernando Perez <fperez@colorado.edu> |
|
2003 | 2015 | |
|
2004 | 2016 | * IPython/Magic.py (Magic.magic_sc): Made the shell capture system |
|
2005 | 2017 | a magic function instead, after some community feedback. No |
|
2006 | 2018 | special syntax will exist for it, but its name is deliberately |
|
2007 | 2019 | very short. |
|
2008 | 2020 | |
|
2009 | 2021 | 2003-12-20 Fernando Perez <fperez@colorado.edu> |
|
2010 | 2022 | |
|
2011 | 2023 | * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added |
|
2012 | 2024 | new functionality, to automagically assign the result of a shell |
|
2013 | 2025 | command to a variable. I'll solicit some community feedback on |
|
2014 | 2026 | this before making it permanent. |
|
2015 | 2027 | |
|
2016 | 2028 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was |
|
2017 | 2029 | requested about callables for which inspect couldn't obtain a |
|
2018 | 2030 | proper argspec. Thanks to a crash report sent by Etienne |
|
2019 | 2031 | Posthumus <etienne-AT-apple01.cs.vu.nl>. |
|
2020 | 2032 | |
|
2021 | 2033 | 2003-12-09 Fernando Perez <fperez@colorado.edu> |
|
2022 | 2034 | |
|
2023 | 2035 | * IPython/genutils.py (page): patch for the pager to work across |
|
2024 | 2036 | various versions of Windows. By Gary Bishop. |
|
2025 | 2037 | |
|
2026 | 2038 | 2003-12-04 Fernando Perez <fperez@colorado.edu> |
|
2027 | 2039 | |
|
2028 | 2040 | * IPython/Gnuplot2.py (PlotItems): Fixes for working with |
|
2029 | 2041 | Gnuplot.py version 1.7, whose internal names changed quite a bit. |
|
2030 | 2042 | While I tested this and it looks ok, there may still be corner |
|
2031 | 2043 | cases I've missed. |
|
2032 | 2044 | |
|
2033 | 2045 | 2003-12-01 Fernando Perez <fperez@colorado.edu> |
|
2034 | 2046 | |
|
2035 | 2047 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug |
|
2036 | 2048 | where a line like 'p,q=1,2' would fail because the automagic |
|
2037 | 2049 | system would be triggered for @p. |
|
2038 | 2050 | |
|
2039 | 2051 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related |
|
2040 | 2052 | cleanups, code unmodified. |
|
2041 | 2053 | |
|
2042 | 2054 | * IPython/genutils.py (Term): added a class for IPython to handle |
|
2043 | 2055 | output. In most cases it will just be a proxy for stdout/err, but |
|
2044 | 2056 | having this allows modifications to be made for some platforms, |
|
2045 | 2057 | such as handling color escapes under Windows. All of this code |
|
2046 | 2058 | was contributed by Gary Bishop, with minor modifications by me. |
|
2047 | 2059 | The actual changes affect many files. |
|
2048 | 2060 | |
|
2049 | 2061 | 2003-11-30 Fernando Perez <fperez@colorado.edu> |
|
2050 | 2062 | |
|
2051 | 2063 | * IPython/iplib.py (file_matches): new completion code, courtesy |
|
2052 | 2064 | of Jeff Collins. This enables filename completion again under |
|
2053 | 2065 | python 2.3, which disabled it at the C level. |
|
2054 | 2066 | |
|
2055 | 2067 | 2003-11-11 Fernando Perez <fperez@colorado.edu> |
|
2056 | 2068 | |
|
2057 | 2069 | * IPython/numutils.py (amap): Added amap() fn. Simple shorthand |
|
2058 | 2070 | for Numeric.array(map(...)), but often convenient. |
|
2059 | 2071 | |
|
2060 | 2072 | 2003-11-05 Fernando Perez <fperez@colorado.edu> |
|
2061 | 2073 | |
|
2062 | 2074 | * IPython/numutils.py (frange): Changed a call from int() to |
|
2063 | 2075 | int(round()) to prevent a problem reported with arange() in the |
|
2064 | 2076 | numpy list. |
|
2065 | 2077 | |
|
2066 | 2078 | 2003-10-06 Fernando Perez <fperez@colorado.edu> |
|
2067 | 2079 | |
|
2068 | 2080 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to |
|
2069 | 2081 | prevent crashes if sys lacks an argv attribute (it happens with |
|
2070 | 2082 | embedded interpreters which build a bare-bones sys module). |
|
2071 | 2083 | Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>. |
|
2072 | 2084 | |
|
2073 | 2085 | 2003-09-24 Fernando Perez <fperez@colorado.edu> |
|
2074 | 2086 | |
|
2075 | 2087 | * IPython/Magic.py (Magic._ofind): blanket except around getattr() |
|
2076 | 2088 | to protect against poorly written user objects where __getattr__ |
|
2077 | 2089 | raises exceptions other than AttributeError. Thanks to a bug |
|
2078 | 2090 | report by Oliver Sander <osander-AT-gmx.de>. |
|
2079 | 2091 | |
|
2080 | 2092 | * IPython/FakeModule.py (FakeModule.__repr__): this method was |
|
2081 | 2093 | missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>. |
|
2082 | 2094 | |
|
2083 | 2095 | 2003-09-09 Fernando Perez <fperez@colorado.edu> |
|
2084 | 2096 | |
|
2085 | 2097 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
2086 | 2098 | unpacking a list whith a callable as first element would |
|
2087 | 2099 | mistakenly trigger autocalling. Thanks to a bug report by Jeffery |
|
2088 | 2100 | Collins. |
|
2089 | 2101 | |
|
2090 | 2102 | 2003-08-25 *** Released version 0.5.0 |
|
2091 | 2103 | |
|
2092 | 2104 | 2003-08-22 Fernando Perez <fperez@colorado.edu> |
|
2093 | 2105 | |
|
2094 | 2106 | * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of |
|
2095 | 2107 | improperly defined user exceptions. Thanks to feedback from Mark |
|
2096 | 2108 | Russell <mrussell-AT-verio.net>. |
|
2097 | 2109 | |
|
2098 | 2110 | 2003-08-20 Fernando Perez <fperez@colorado.edu> |
|
2099 | 2111 | |
|
2100 | 2112 | * IPython/OInspect.py (Inspector.pinfo): changed String Form |
|
2101 | 2113 | printing so that it would print multi-line string forms starting |
|
2102 | 2114 | with a new line. This way the formatting is better respected for |
|
2103 | 2115 | objects which work hard to make nice string forms. |
|
2104 | 2116 | |
|
2105 | 2117 | * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where |
|
2106 | 2118 | autocall would overtake data access for objects with both |
|
2107 | 2119 | __getitem__ and __call__. |
|
2108 | 2120 | |
|
2109 | 2121 | 2003-08-19 *** Released version 0.5.0-rc1 |
|
2110 | 2122 | |
|
2111 | 2123 | 2003-08-19 Fernando Perez <fperez@colorado.edu> |
|
2112 | 2124 | |
|
2113 | 2125 | * IPython/deep_reload.py (load_tail): single tiny change here |
|
2114 | 2126 | seems to fix the long-standing bug of dreload() failing to work |
|
2115 | 2127 | for dotted names. But this module is pretty tricky, so I may have |
|
2116 | 2128 | missed some subtlety. Needs more testing!. |
|
2117 | 2129 | |
|
2118 | 2130 | * IPython/ultraTB.py (VerboseTB.linereader): harden against user |
|
2119 | 2131 | exceptions which have badly implemented __str__ methods. |
|
2120 | 2132 | (VerboseTB.text): harden against inspect.getinnerframes crashing, |
|
2121 | 2133 | which I've been getting reports about from Python 2.3 users. I |
|
2122 | 2134 | wish I had a simple test case to reproduce the problem, so I could |
|
2123 | 2135 | either write a cleaner workaround or file a bug report if |
|
2124 | 2136 | necessary. |
|
2125 | 2137 | |
|
2126 | 2138 | * IPython/Magic.py (Magic.magic_edit): fixed bug where after |
|
2127 | 2139 | making a class 'foo', file 'foo.py' couldn't be edited. Thanks to |
|
2128 | 2140 | a bug report by Tjabo Kloppenburg. |
|
2129 | 2141 | |
|
2130 | 2142 | * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb |
|
2131 | 2143 | crashes. Wrapped the pdb call in a blanket try/except, since pdb |
|
2132 | 2144 | seems rather unstable. Thanks to a bug report by Tjabo |
|
2133 | 2145 | Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>. |
|
2134 | 2146 | |
|
2135 | 2147 | * IPython/Release.py (version): release 0.5.0-rc1. I want to put |
|
2136 | 2148 | this out soon because of the critical fixes in the inner loop for |
|
2137 | 2149 | generators. |
|
2138 | 2150 | |
|
2139 | 2151 | * IPython/Magic.py (Magic.getargspec): removed. This (and |
|
2140 | 2152 | _get_def) have been obsoleted by OInspect for a long time, I |
|
2141 | 2153 | hadn't noticed that they were dead code. |
|
2142 | 2154 | (Magic._ofind): restored _ofind functionality for a few literals |
|
2143 | 2155 | (those in ["''",'""','[]','{}','()']). But it won't work anymore |
|
2144 | 2156 | for things like "hello".capitalize?, since that would require a |
|
2145 | 2157 | potentially dangerous eval() again. |
|
2146 | 2158 | |
|
2147 | 2159 | * IPython/iplib.py (InteractiveShell._prefilter): reorganized the |
|
2148 | 2160 | logic a bit more to clean up the escapes handling and minimize the |
|
2149 | 2161 | use of _ofind to only necessary cases. The interactive 'feel' of |
|
2150 | 2162 | IPython should have improved quite a bit with the changes in |
|
2151 | 2163 | _prefilter and _ofind (besides being far safer than before). |
|
2152 | 2164 | |
|
2153 | 2165 | * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather |
|
2154 | 2166 | obscure, never reported). Edit would fail to find the object to |
|
2155 | 2167 | edit under some circumstances. |
|
2156 | 2168 | (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls |
|
2157 | 2169 | which were causing double-calling of generators. Those eval calls |
|
2158 | 2170 | were _very_ dangerous, since code with side effects could be |
|
2159 | 2171 | triggered. As they say, 'eval is evil'... These were the |
|
2160 | 2172 | nastiest evals in IPython. Besides, _ofind is now far simpler, |
|
2161 | 2173 | and it should also be quite a bit faster. Its use of inspect is |
|
2162 | 2174 | also safer, so perhaps some of the inspect-related crashes I've |
|
2163 | 2175 | seen lately with Python 2.3 might be taken care of. That will |
|
2164 | 2176 | need more testing. |
|
2165 | 2177 | |
|
2166 | 2178 | 2003-08-17 Fernando Perez <fperez@colorado.edu> |
|
2167 | 2179 | |
|
2168 | 2180 | * IPython/iplib.py (InteractiveShell._prefilter): significant |
|
2169 | 2181 | simplifications to the logic for handling user escapes. Faster |
|
2170 | 2182 | and simpler code. |
|
2171 | 2183 | |
|
2172 | 2184 | 2003-08-14 Fernando Perez <fperez@colorado.edu> |
|
2173 | 2185 | |
|
2174 | 2186 | * IPython/numutils.py (sum_flat): rewrote to be non-recursive. |
|
2175 | 2187 | Now it requires O(N) storage (N=size(a)) for non-contiguous input, |
|
2176 | 2188 | but it should be quite a bit faster. And the recursive version |
|
2177 | 2189 | generated O(log N) intermediate storage for all rank>1 arrays, |
|
2178 | 2190 | even if they were contiguous. |
|
2179 | 2191 | (l1norm): Added this function. |
|
2180 | 2192 | (norm): Added this function for arbitrary norms (including |
|
2181 | 2193 | l-infinity). l1 and l2 are still special cases for convenience |
|
2182 | 2194 | and speed. |
|
2183 | 2195 | |
|
2184 | 2196 | 2003-08-03 Fernando Perez <fperez@colorado.edu> |
|
2185 | 2197 | |
|
2186 | 2198 | * IPython/Magic.py (Magic.magic_edit): Removed all remaining string |
|
2187 | 2199 | exceptions, which now raise PendingDeprecationWarnings in Python |
|
2188 | 2200 | 2.3. There were some in Magic and some in Gnuplot2. |
|
2189 | 2201 | |
|
2190 | 2202 | 2003-06-30 Fernando Perez <fperez@colorado.edu> |
|
2191 | 2203 | |
|
2192 | 2204 | * IPython/genutils.py (page): modified to call curses only for |
|
2193 | 2205 | terminals where TERM=='xterm'. After problems under many other |
|
2194 | 2206 | terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>. |
|
2195 | 2207 | |
|
2196 | 2208 | * IPython/iplib.py (complete): removed spurious 'print "IE"' which |
|
2197 | 2209 | would be triggered when readline was absent. This was just an old |
|
2198 | 2210 | debugging statement I'd forgotten to take out. |
|
2199 | 2211 | |
|
2200 | 2212 | 2003-06-20 Fernando Perez <fperez@colorado.edu> |
|
2201 | 2213 | |
|
2202 | 2214 | * IPython/genutils.py (clock): modified to return only user time |
|
2203 | 2215 | (not counting system time), after a discussion on scipy. While |
|
2204 | 2216 | system time may be a useful quantity occasionally, it may much |
|
2205 | 2217 | more easily be skewed by occasional swapping or other similar |
|
2206 | 2218 | activity. |
|
2207 | 2219 | |
|
2208 | 2220 | 2003-06-05 Fernando Perez <fperez@colorado.edu> |
|
2209 | 2221 | |
|
2210 | 2222 | * IPython/numutils.py (identity): new function, for building |
|
2211 | 2223 | arbitrary rank Kronecker deltas (mostly backwards compatible with |
|
2212 | 2224 | Numeric.identity) |
|
2213 | 2225 | |
|
2214 | 2226 | 2003-06-03 Fernando Perez <fperez@colorado.edu> |
|
2215 | 2227 | |
|
2216 | 2228 | * IPython/iplib.py (InteractiveShell.handle_magic): protect |
|
2217 | 2229 | arguments passed to magics with spaces, to allow trailing '\' to |
|
2218 | 2230 | work normally (mainly for Windows users). |
|
2219 | 2231 | |
|
2220 | 2232 | 2003-05-29 Fernando Perez <fperez@colorado.edu> |
|
2221 | 2233 | |
|
2222 | 2234 | * IPython/ipmaker.py (make_IPython): Load site._Helper() as help |
|
2223 | 2235 | instead of pydoc.help. This fixes a bizarre behavior where |
|
2224 | 2236 | printing '%s' % locals() would trigger the help system. Now |
|
2225 | 2237 | ipython behaves like normal python does. |
|
2226 | 2238 | |
|
2227 | 2239 | Note that if one does 'from pydoc import help', the bizarre |
|
2228 | 2240 | behavior returns, but this will also happen in normal python, so |
|
2229 | 2241 | it's not an ipython bug anymore (it has to do with how pydoc.help |
|
2230 | 2242 | is implemented). |
|
2231 | 2243 | |
|
2232 | 2244 | 2003-05-22 Fernando Perez <fperez@colorado.edu> |
|
2233 | 2245 | |
|
2234 | 2246 | * IPython/FlexCompleter.py (Completer.attr_matches): fixed to |
|
2235 | 2247 | return [] instead of None when nothing matches, also match to end |
|
2236 | 2248 | of line. Patch by Gary Bishop. |
|
2237 | 2249 | |
|
2238 | 2250 | * IPython/ipmaker.py (make_IPython): Added same sys.excepthook |
|
2239 | 2251 | protection as before, for files passed on the command line. This |
|
2240 | 2252 | prevents the CrashHandler from kicking in if user files call into |
|
2241 | 2253 | sys.excepthook (such as PyQt and WxWindows have a nasty habit of |
|
2242 | 2254 | doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr> |
|
2243 | 2255 | |
|
2244 | 2256 | 2003-05-20 *** Released version 0.4.0 |
|
2245 | 2257 | |
|
2246 | 2258 | 2003-05-20 Fernando Perez <fperez@colorado.edu> |
|
2247 | 2259 | |
|
2248 | 2260 | * setup.py: added support for manpages. It's a bit hackish b/c of |
|
2249 | 2261 | a bug in the way the bdist_rpm distutils target handles gzipped |
|
2250 | 2262 | manpages, but it works. After a patch by Jack. |
|
2251 | 2263 | |
|
2252 | 2264 | 2003-05-19 Fernando Perez <fperez@colorado.edu> |
|
2253 | 2265 | |
|
2254 | 2266 | * IPython/numutils.py: added a mockup of the kinds module, since |
|
2255 | 2267 | it was recently removed from Numeric. This way, numutils will |
|
2256 | 2268 | work for all users even if they are missing kinds. |
|
2257 | 2269 | |
|
2258 | 2270 | * IPython/Magic.py (Magic._ofind): Harden against an inspect |
|
2259 | 2271 | failure, which can occur with SWIG-wrapped extensions. After a |
|
2260 | 2272 | crash report from Prabhu. |
|
2261 | 2273 | |
|
2262 | 2274 | 2003-05-16 Fernando Perez <fperez@colorado.edu> |
|
2263 | 2275 | |
|
2264 | 2276 | * IPython/iplib.py (InteractiveShell.excepthook): New method to |
|
2265 | 2277 | protect ipython from user code which may call directly |
|
2266 | 2278 | sys.excepthook (this looks like an ipython crash to the user, even |
|
2267 | 2279 | when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
2268 | 2280 | This is especially important to help users of WxWindows, but may |
|
2269 | 2281 | also be useful in other cases. |
|
2270 | 2282 | |
|
2271 | 2283 | * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow |
|
2272 | 2284 | an optional tb_offset to be specified, and to preserve exception |
|
2273 | 2285 | info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
2274 | 2286 | |
|
2275 | 2287 | * ipython.1 (Default): Thanks to Jack's work, we now have manpages! |
|
2276 | 2288 | |
|
2277 | 2289 | 2003-05-15 Fernando Perez <fperez@colorado.edu> |
|
2278 | 2290 | |
|
2279 | 2291 | * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when |
|
2280 | 2292 | installing for a new user under Windows. |
|
2281 | 2293 | |
|
2282 | 2294 | 2003-05-12 Fernando Perez <fperez@colorado.edu> |
|
2283 | 2295 | |
|
2284 | 2296 | * IPython/iplib.py (InteractiveShell.handle_emacs): New line |
|
2285 | 2297 | handler for Emacs comint-based lines. Currently it doesn't do |
|
2286 | 2298 | much (but importantly, it doesn't update the history cache). In |
|
2287 | 2299 | the future it may be expanded if Alex needs more functionality |
|
2288 | 2300 | there. |
|
2289 | 2301 | |
|
2290 | 2302 | * IPython/CrashHandler.py (CrashHandler.__call__): Added platform |
|
2291 | 2303 | info to crash reports. |
|
2292 | 2304 | |
|
2293 | 2305 | * IPython/iplib.py (InteractiveShell.mainloop): Added -c option, |
|
2294 | 2306 | just like Python's -c. Also fixed crash with invalid -color |
|
2295 | 2307 | option value at startup. Thanks to Will French |
|
2296 | 2308 | <wfrench-AT-bestweb.net> for the bug report. |
|
2297 | 2309 | |
|
2298 | 2310 | 2003-05-09 Fernando Perez <fperez@colorado.edu> |
|
2299 | 2311 | |
|
2300 | 2312 | * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString |
|
2301 | 2313 | to EvalDict (it's a mapping, after all) and simplified its code |
|
2302 | 2314 | quite a bit, after a nice discussion on c.l.py where Gustavo |
|
2303 | 2315 | CΓ³rdova <gcordova-AT-sismex.com> suggested the new version. |
|
2304 | 2316 | |
|
2305 | 2317 | 2003-04-30 Fernando Perez <fperez@colorado.edu> |
|
2306 | 2318 | |
|
2307 | 2319 | * IPython/genutils.py (timings_out): modified it to reduce its |
|
2308 | 2320 | overhead in the common reps==1 case. |
|
2309 | 2321 | |
|
2310 | 2322 | 2003-04-29 Fernando Perez <fperez@colorado.edu> |
|
2311 | 2323 | |
|
2312 | 2324 | * IPython/genutils.py (timings_out): Modified to use the resource |
|
2313 | 2325 | module, which avoids the wraparound problems of time.clock(). |
|
2314 | 2326 | |
|
2315 | 2327 | 2003-04-17 *** Released version 0.2.15pre4 |
|
2316 | 2328 | |
|
2317 | 2329 | 2003-04-17 Fernando Perez <fperez@colorado.edu> |
|
2318 | 2330 | |
|
2319 | 2331 | * setup.py (scriptfiles): Split windows-specific stuff over to a |
|
2320 | 2332 | separate file, in an attempt to have a Windows GUI installer. |
|
2321 | 2333 | That didn't work, but part of the groundwork is done. |
|
2322 | 2334 | |
|
2323 | 2335 | * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for |
|
2324 | 2336 | indent/unindent with 4 spaces. Particularly useful in combination |
|
2325 | 2337 | with the new auto-indent option. |
|
2326 | 2338 | |
|
2327 | 2339 | 2003-04-16 Fernando Perez <fperez@colorado.edu> |
|
2328 | 2340 | |
|
2329 | 2341 | * IPython/Magic.py: various replacements of self.rc for |
|
2330 | 2342 | self.shell.rc. A lot more remains to be done to fully disentangle |
|
2331 | 2343 | this class from the main Shell class. |
|
2332 | 2344 | |
|
2333 | 2345 | * IPython/GnuplotRuntime.py: added checks for mouse support so |
|
2334 | 2346 | that we don't try to enable it if the current gnuplot doesn't |
|
2335 | 2347 | really support it. Also added checks so that we don't try to |
|
2336 | 2348 | enable persist under Windows (where Gnuplot doesn't recognize the |
|
2337 | 2349 | option). |
|
2338 | 2350 | |
|
2339 | 2351 | * IPython/iplib.py (InteractiveShell.interact): Added optional |
|
2340 | 2352 | auto-indenting code, after a patch by King C. Shu |
|
2341 | 2353 | <kingshu-AT-myrealbox.com>. It's off by default because it doesn't |
|
2342 | 2354 | get along well with pasting indented code. If I ever figure out |
|
2343 | 2355 | how to make that part go well, it will become on by default. |
|
2344 | 2356 | |
|
2345 | 2357 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would |
|
2346 | 2358 | crash ipython if there was an unmatched '%' in the user's prompt |
|
2347 | 2359 | string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2348 | 2360 | |
|
2349 | 2361 | * IPython/iplib.py (InteractiveShell.interact): removed the |
|
2350 | 2362 | ability to ask the user whether he wants to crash or not at the |
|
2351 | 2363 | 'last line' exception handler. Calling functions at that point |
|
2352 | 2364 | changes the stack, and the error reports would have incorrect |
|
2353 | 2365 | tracebacks. |
|
2354 | 2366 | |
|
2355 | 2367 | * IPython/Magic.py (Magic.magic_page): Added new @page magic, to |
|
2356 | 2368 | pass through a peger a pretty-printed form of any object. After a |
|
2357 | 2369 | contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr> |
|
2358 | 2370 | |
|
2359 | 2371 | 2003-04-14 Fernando Perez <fperez@colorado.edu> |
|
2360 | 2372 | |
|
2361 | 2373 | * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where |
|
2362 | 2374 | all files in ~ would be modified at first install (instead of |
|
2363 | 2375 | ~/.ipython). This could be potentially disastrous, as the |
|
2364 | 2376 | modification (make line-endings native) could damage binary files. |
|
2365 | 2377 | |
|
2366 | 2378 | 2003-04-10 Fernando Perez <fperez@colorado.edu> |
|
2367 | 2379 | |
|
2368 | 2380 | * IPython/iplib.py (InteractiveShell.handle_help): Modified to |
|
2369 | 2381 | handle only lines which are invalid python. This now means that |
|
2370 | 2382 | lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins |
|
2371 | 2383 | for the bug report. |
|
2372 | 2384 | |
|
2373 | 2385 | 2003-04-01 Fernando Perez <fperez@colorado.edu> |
|
2374 | 2386 | |
|
2375 | 2387 | * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug |
|
2376 | 2388 | where failing to set sys.last_traceback would crash pdb.pm(). |
|
2377 | 2389 | Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug |
|
2378 | 2390 | report. |
|
2379 | 2391 | |
|
2380 | 2392 | 2003-03-25 Fernando Perez <fperez@colorado.edu> |
|
2381 | 2393 | |
|
2382 | 2394 | * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler |
|
2383 | 2395 | before printing it (it had a lot of spurious blank lines at the |
|
2384 | 2396 | end). |
|
2385 | 2397 | |
|
2386 | 2398 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr |
|
2387 | 2399 | output would be sent 21 times! Obviously people don't use this |
|
2388 | 2400 | too often, or I would have heard about it. |
|
2389 | 2401 | |
|
2390 | 2402 | 2003-03-24 Fernando Perez <fperez@colorado.edu> |
|
2391 | 2403 | |
|
2392 | 2404 | * setup.py (scriptfiles): renamed the data_files parameter from |
|
2393 | 2405 | 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink |
|
2394 | 2406 | for the patch. |
|
2395 | 2407 | |
|
2396 | 2408 | 2003-03-20 Fernando Perez <fperez@colorado.edu> |
|
2397 | 2409 | |
|
2398 | 2410 | * IPython/genutils.py (error): added error() and fatal() |
|
2399 | 2411 | functions. |
|
2400 | 2412 | |
|
2401 | 2413 | 2003-03-18 *** Released version 0.2.15pre3 |
|
2402 | 2414 | |
|
2403 | 2415 | 2003-03-18 Fernando Perez <fperez@colorado.edu> |
|
2404 | 2416 | |
|
2405 | 2417 | * setupext/install_data_ext.py |
|
2406 | 2418 | (install_data_ext.initialize_options): Class contributed by Jack |
|
2407 | 2419 | Moffit for fixing the old distutils hack. He is sending this to |
|
2408 | 2420 | the distutils folks so in the future we may not need it as a |
|
2409 | 2421 | private fix. |
|
2410 | 2422 | |
|
2411 | 2423 | * MANIFEST.in: Extensive reorganization, based on Jack Moffit's |
|
2412 | 2424 | changes for Debian packaging. See his patch for full details. |
|
2413 | 2425 | The old distutils hack of making the ipythonrc* files carry a |
|
2414 | 2426 | bogus .py extension is gone, at last. Examples were moved to a |
|
2415 | 2427 | separate subdir under doc/, and the separate executable scripts |
|
2416 | 2428 | now live in their own directory. Overall a great cleanup. The |
|
2417 | 2429 | manual was updated to use the new files, and setup.py has been |
|
2418 | 2430 | fixed for this setup. |
|
2419 | 2431 | |
|
2420 | 2432 | * IPython/PyColorize.py (Parser.usage): made non-executable and |
|
2421 | 2433 | created a pycolor wrapper around it to be included as a script. |
|
2422 | 2434 | |
|
2423 | 2435 | 2003-03-12 *** Released version 0.2.15pre2 |
|
2424 | 2436 | |
|
2425 | 2437 | 2003-03-12 Fernando Perez <fperez@colorado.edu> |
|
2426 | 2438 | |
|
2427 | 2439 | * IPython/ColorANSI.py (make_color_table): Finally fixed the |
|
2428 | 2440 | long-standing problem with garbage characters in some terminals. |
|
2429 | 2441 | The issue was really that the \001 and \002 escapes must _only_ be |
|
2430 | 2442 | passed to input prompts (which call readline), but _never_ to |
|
2431 | 2443 | normal text to be printed on screen. I changed ColorANSI to have |
|
2432 | 2444 | two classes: TermColors and InputTermColors, each with the |
|
2433 | 2445 | appropriate escapes for input prompts or normal text. The code in |
|
2434 | 2446 | Prompts.py got slightly more complicated, but this very old and |
|
2435 | 2447 | annoying bug is finally fixed. |
|
2436 | 2448 | |
|
2437 | 2449 | All the credit for nailing down the real origin of this problem |
|
2438 | 2450 | and the correct solution goes to Jack Moffit <jack-AT-xiph.org>. |
|
2439 | 2451 | *Many* thanks to him for spending quite a bit of effort on this. |
|
2440 | 2452 | |
|
2441 | 2453 | 2003-03-05 *** Released version 0.2.15pre1 |
|
2442 | 2454 | |
|
2443 | 2455 | 2003-03-03 Fernando Perez <fperez@colorado.edu> |
|
2444 | 2456 | |
|
2445 | 2457 | * IPython/FakeModule.py: Moved the former _FakeModule to a |
|
2446 | 2458 | separate file, because it's also needed by Magic (to fix a similar |
|
2447 | 2459 | pickle-related issue in @run). |
|
2448 | 2460 | |
|
2449 | 2461 | 2003-03-02 Fernando Perez <fperez@colorado.edu> |
|
2450 | 2462 | |
|
2451 | 2463 | * IPython/Magic.py (Magic.magic_autocall): new magic to control |
|
2452 | 2464 | the autocall option at runtime. |
|
2453 | 2465 | (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns |
|
2454 | 2466 | across Magic.py to start separating Magic from InteractiveShell. |
|
2455 | 2467 | (Magic._ofind): Fixed to return proper namespace for dotted |
|
2456 | 2468 | names. Before, a dotted name would always return 'not currently |
|
2457 | 2469 | defined', because it would find the 'parent'. s.x would be found, |
|
2458 | 2470 | but since 'x' isn't defined by itself, it would get confused. |
|
2459 | 2471 | (Magic.magic_run): Fixed pickling problems reported by Ralf |
|
2460 | 2472 | Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to |
|
2461 | 2473 | that I'd used when Mike Heeter reported similar issues at the |
|
2462 | 2474 | top-level, but now for @run. It boils down to injecting the |
|
2463 | 2475 | namespace where code is being executed with something that looks |
|
2464 | 2476 | enough like a module to fool pickle.dump(). Since a pickle stores |
|
2465 | 2477 | a named reference to the importing module, we need this for |
|
2466 | 2478 | pickles to save something sensible. |
|
2467 | 2479 | |
|
2468 | 2480 | * IPython/ipmaker.py (make_IPython): added an autocall option. |
|
2469 | 2481 | |
|
2470 | 2482 | * IPython/iplib.py (InteractiveShell._prefilter): reordered all of |
|
2471 | 2483 | the auto-eval code. Now autocalling is an option, and the code is |
|
2472 | 2484 | also vastly safer. There is no more eval() involved at all. |
|
2473 | 2485 | |
|
2474 | 2486 | 2003-03-01 Fernando Perez <fperez@colorado.edu> |
|
2475 | 2487 | |
|
2476 | 2488 | * IPython/Magic.py (Magic._ofind): Changed interface to return a |
|
2477 | 2489 | dict with named keys instead of a tuple. |
|
2478 | 2490 | |
|
2479 | 2491 | * IPython: Started using CVS for IPython as of 0.2.15pre1. |
|
2480 | 2492 | |
|
2481 | 2493 | * setup.py (make_shortcut): Fixed message about directories |
|
2482 | 2494 | created during Windows installation (the directories were ok, just |
|
2483 | 2495 | the printed message was misleading). Thanks to Chris Liechti |
|
2484 | 2496 | <cliechti-AT-gmx.net> for the heads up. |
|
2485 | 2497 | |
|
2486 | 2498 | 2003-02-21 Fernando Perez <fperez@colorado.edu> |
|
2487 | 2499 | |
|
2488 | 2500 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching |
|
2489 | 2501 | of ValueError exception when checking for auto-execution. This |
|
2490 | 2502 | one is raised by things like Numeric arrays arr.flat when the |
|
2491 | 2503 | array is non-contiguous. |
|
2492 | 2504 | |
|
2493 | 2505 | 2003-01-31 Fernando Perez <fperez@colorado.edu> |
|
2494 | 2506 | |
|
2495 | 2507 | * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would |
|
2496 | 2508 | not return any value at all (even though the command would get |
|
2497 | 2509 | executed). |
|
2498 | 2510 | (xsys): Flush stdout right after printing the command to ensure |
|
2499 | 2511 | proper ordering of commands and command output in the total |
|
2500 | 2512 | output. |
|
2501 | 2513 | (SystemExec/xsys/bq): Switched the names of xsys/bq and |
|
2502 | 2514 | system/getoutput as defaults. The old ones are kept for |
|
2503 | 2515 | compatibility reasons, so no code which uses this library needs |
|
2504 | 2516 | changing. |
|
2505 | 2517 | |
|
2506 | 2518 | 2003-01-27 *** Released version 0.2.14 |
|
2507 | 2519 | |
|
2508 | 2520 | 2003-01-25 Fernando Perez <fperez@colorado.edu> |
|
2509 | 2521 | |
|
2510 | 2522 | * IPython/Magic.py (Magic.magic_edit): Fixed problem where |
|
2511 | 2523 | functions defined in previous edit sessions could not be re-edited |
|
2512 | 2524 | (because the temp files were immediately removed). Now temp files |
|
2513 | 2525 | are removed only at IPython's exit. |
|
2514 | 2526 | (Magic.magic_run): Improved @run to perform shell-like expansions |
|
2515 | 2527 | on its arguments (~users and $VARS). With this, @run becomes more |
|
2516 | 2528 | like a normal command-line. |
|
2517 | 2529 | |
|
2518 | 2530 | * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small |
|
2519 | 2531 | bugs related to embedding and cleaned up that code. A fairly |
|
2520 | 2532 | important one was the impossibility to access the global namespace |
|
2521 | 2533 | through the embedded IPython (only local variables were visible). |
|
2522 | 2534 | |
|
2523 | 2535 | 2003-01-14 Fernando Perez <fperez@colorado.edu> |
|
2524 | 2536 | |
|
2525 | 2537 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed |
|
2526 | 2538 | auto-calling to be a bit more conservative. Now it doesn't get |
|
2527 | 2539 | triggered if any of '!=()<>' are in the rest of the input line, to |
|
2528 | 2540 | allow comparing callables. Thanks to Alex for the heads up. |
|
2529 | 2541 | |
|
2530 | 2542 | 2003-01-07 Fernando Perez <fperez@colorado.edu> |
|
2531 | 2543 | |
|
2532 | 2544 | * IPython/genutils.py (page): fixed estimation of the number of |
|
2533 | 2545 | lines in a string to be paged to simply count newlines. This |
|
2534 | 2546 | prevents over-guessing due to embedded escape sequences. A better |
|
2535 | 2547 | long-term solution would involve stripping out the control chars |
|
2536 | 2548 | for the count, but it's potentially so expensive I just don't |
|
2537 | 2549 | think it's worth doing. |
|
2538 | 2550 | |
|
2539 | 2551 | 2002-12-19 *** Released version 0.2.14pre50 |
|
2540 | 2552 | |
|
2541 | 2553 | 2002-12-19 Fernando Perez <fperez@colorado.edu> |
|
2542 | 2554 | |
|
2543 | 2555 | * tools/release (version): Changed release scripts to inform |
|
2544 | 2556 | Andrea and build a NEWS file with a list of recent changes. |
|
2545 | 2557 | |
|
2546 | 2558 | * IPython/ColorANSI.py (__all__): changed terminal detection |
|
2547 | 2559 | code. Seems to work better for xterms without breaking |
|
2548 | 2560 | konsole. Will need more testing to determine if WinXP and Mac OSX |
|
2549 | 2561 | also work ok. |
|
2550 | 2562 | |
|
2551 | 2563 | 2002-12-18 *** Released version 0.2.14pre49 |
|
2552 | 2564 | |
|
2553 | 2565 | 2002-12-18 Fernando Perez <fperez@colorado.edu> |
|
2554 | 2566 | |
|
2555 | 2567 | * Docs: added new info about Mac OSX, from Andrea. |
|
2556 | 2568 | |
|
2557 | 2569 | * IPython/Gnuplot2.py (String): Added a String PlotItem class to |
|
2558 | 2570 | allow direct plotting of python strings whose format is the same |
|
2559 | 2571 | of gnuplot data files. |
|
2560 | 2572 | |
|
2561 | 2573 | 2002-12-16 Fernando Perez <fperez@colorado.edu> |
|
2562 | 2574 | |
|
2563 | 2575 | * IPython/iplib.py (InteractiveShell.interact): fixed default (y) |
|
2564 | 2576 | value of exit question to be acknowledged. |
|
2565 | 2577 | |
|
2566 | 2578 | 2002-12-03 Fernando Perez <fperez@colorado.edu> |
|
2567 | 2579 | |
|
2568 | 2580 | * IPython/ipmaker.py: removed generators, which had been added |
|
2569 | 2581 | by mistake in an earlier debugging run. This was causing trouble |
|
2570 | 2582 | to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu> |
|
2571 | 2583 | for pointing this out. |
|
2572 | 2584 | |
|
2573 | 2585 | 2002-11-17 Fernando Perez <fperez@colorado.edu> |
|
2574 | 2586 | |
|
2575 | 2587 | * Manual: updated the Gnuplot section. |
|
2576 | 2588 | |
|
2577 | 2589 | * IPython/GnuplotRuntime.py: refactored a lot all this code, with |
|
2578 | 2590 | a much better split of what goes in Runtime and what goes in |
|
2579 | 2591 | Interactive. |
|
2580 | 2592 | |
|
2581 | 2593 | * IPython/ipmaker.py: fixed bug where import_fail_info wasn't |
|
2582 | 2594 | being imported from iplib. |
|
2583 | 2595 | |
|
2584 | 2596 | * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc |
|
2585 | 2597 | for command-passing. Now the global Gnuplot instance is called |
|
2586 | 2598 | 'gp' instead of 'g', which was really a far too fragile and |
|
2587 | 2599 | common name. |
|
2588 | 2600 | |
|
2589 | 2601 | * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken |
|
2590 | 2602 | bounding boxes generated by Gnuplot for square plots. |
|
2591 | 2603 | |
|
2592 | 2604 | * IPython/genutils.py (popkey): new function added. I should |
|
2593 | 2605 | suggest this on c.l.py as a dict method, it seems useful. |
|
2594 | 2606 | |
|
2595 | 2607 | * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot |
|
2596 | 2608 | to transparently handle PostScript generation. MUCH better than |
|
2597 | 2609 | the previous plot_eps/replot_eps (which I removed now). The code |
|
2598 | 2610 | is also fairly clean and well documented now (including |
|
2599 | 2611 | docstrings). |
|
2600 | 2612 | |
|
2601 | 2613 | 2002-11-13 Fernando Perez <fperez@colorado.edu> |
|
2602 | 2614 | |
|
2603 | 2615 | * IPython/Magic.py (Magic.magic_edit): fixed docstring |
|
2604 | 2616 | (inconsistent with options). |
|
2605 | 2617 | |
|
2606 | 2618 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been |
|
2607 | 2619 | manually disabled, I don't know why. Fixed it. |
|
2608 | 2620 | (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly |
|
2609 | 2621 | eps output. |
|
2610 | 2622 | |
|
2611 | 2623 | 2002-11-12 Fernando Perez <fperez@colorado.edu> |
|
2612 | 2624 | |
|
2613 | 2625 | * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they |
|
2614 | 2626 | don't propagate up to caller. Fixes crash reported by François |
|
2615 | 2627 | Pinard. |
|
2616 | 2628 | |
|
2617 | 2629 | 2002-11-09 Fernando Perez <fperez@colorado.edu> |
|
2618 | 2630 | |
|
2619 | 2631 | * IPython/ipmaker.py (make_IPython): fixed problem with writing |
|
2620 | 2632 | history file for new users. |
|
2621 | 2633 | (make_IPython): fixed bug where initial install would leave the |
|
2622 | 2634 | user running in the .ipython dir. |
|
2623 | 2635 | (make_IPython): fixed bug where config dir .ipython would be |
|
2624 | 2636 | created regardless of the given -ipythondir option. Thanks to Cory |
|
2625 | 2637 | Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report. |
|
2626 | 2638 | |
|
2627 | 2639 | * IPython/genutils.py (ask_yes_no): new function for asking yes/no |
|
2628 | 2640 | type confirmations. Will need to use it in all of IPython's code |
|
2629 | 2641 | consistently. |
|
2630 | 2642 | |
|
2631 | 2643 | * IPython/CrashHandler.py (CrashHandler.__call__): changed the |
|
2632 | 2644 | context to print 31 lines instead of the default 5. This will make |
|
2633 | 2645 | the crash reports extremely detailed in case the problem is in |
|
2634 | 2646 | libraries I don't have access to. |
|
2635 | 2647 | |
|
2636 | 2648 | * IPython/iplib.py (InteractiveShell.interact): changed the 'last |
|
2637 | 2649 | line of defense' code to still crash, but giving users fair |
|
2638 | 2650 | warning. I don't want internal errors to go unreported: if there's |
|
2639 | 2651 | an internal problem, IPython should crash and generate a full |
|
2640 | 2652 | report. |
|
2641 | 2653 | |
|
2642 | 2654 | 2002-11-08 Fernando Perez <fperez@colorado.edu> |
|
2643 | 2655 | |
|
2644 | 2656 | * IPython/iplib.py (InteractiveShell.interact): added code to trap |
|
2645 | 2657 | otherwise uncaught exceptions which can appear if people set |
|
2646 | 2658 | sys.stdout to something badly broken. Thanks to a crash report |
|
2647 | 2659 | from henni-AT-mail.brainbot.com. |
|
2648 | 2660 | |
|
2649 | 2661 | 2002-11-04 Fernando Perez <fperez@colorado.edu> |
|
2650 | 2662 | |
|
2651 | 2663 | * IPython/iplib.py (InteractiveShell.interact): added |
|
2652 | 2664 | __IPYTHON__active to the builtins. It's a flag which goes on when |
|
2653 | 2665 | the interaction starts and goes off again when it stops. This |
|
2654 | 2666 | allows embedding code to detect being inside IPython. Before this |
|
2655 | 2667 | was done via __IPYTHON__, but that only shows that an IPython |
|
2656 | 2668 | instance has been created. |
|
2657 | 2669 | |
|
2658 | 2670 | * IPython/Magic.py (Magic.magic_env): I realized that in a |
|
2659 | 2671 | UserDict, instance.data holds the data as a normal dict. So I |
|
2660 | 2672 | modified @env to return os.environ.data instead of rebuilding a |
|
2661 | 2673 | dict by hand. |
|
2662 | 2674 | |
|
2663 | 2675 | 2002-11-02 Fernando Perez <fperez@colorado.edu> |
|
2664 | 2676 | |
|
2665 | 2677 | * IPython/genutils.py (warn): changed so that level 1 prints no |
|
2666 | 2678 | header. Level 2 is now the default (with 'WARNING' header, as |
|
2667 | 2679 | before). I think I tracked all places where changes were needed in |
|
2668 | 2680 | IPython, but outside code using the old level numbering may have |
|
2669 | 2681 | broken. |
|
2670 | 2682 | |
|
2671 | 2683 | * IPython/iplib.py (InteractiveShell.runcode): added this to |
|
2672 | 2684 | handle the tracebacks in SystemExit traps correctly. The previous |
|
2673 | 2685 | code (through interact) was printing more of the stack than |
|
2674 | 2686 | necessary, showing IPython internal code to the user. |
|
2675 | 2687 | |
|
2676 | 2688 | * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by |
|
2677 | 2689 | default. Now that the default at the confirmation prompt is yes, |
|
2678 | 2690 | it's not so intrusive. François' argument that ipython sessions |
|
2679 | 2691 | tend to be complex enough not to lose them from an accidental C-d, |
|
2680 | 2692 | is a valid one. |
|
2681 | 2693 | |
|
2682 | 2694 | * IPython/iplib.py (InteractiveShell.interact): added a |
|
2683 | 2695 | showtraceback() call to the SystemExit trap, and modified the exit |
|
2684 | 2696 | confirmation to have yes as the default. |
|
2685 | 2697 | |
|
2686 | 2698 | * IPython/UserConfig/ipythonrc.py: removed 'session' option from |
|
2687 | 2699 | this file. It's been gone from the code for a long time, this was |
|
2688 | 2700 | simply leftover junk. |
|
2689 | 2701 | |
|
2690 | 2702 | 2002-11-01 Fernando Perez <fperez@colorado.edu> |
|
2691 | 2703 | |
|
2692 | 2704 | * IPython/UserConfig/ipythonrc.py: new confirm_exit option |
|
2693 | 2705 | added. If set, IPython now traps EOF and asks for |
|
2694 | 2706 | confirmation. After a request by François Pinard. |
|
2695 | 2707 | |
|
2696 | 2708 | * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead |
|
2697 | 2709 | of @abort, and with a new (better) mechanism for handling the |
|
2698 | 2710 | exceptions. |
|
2699 | 2711 | |
|
2700 | 2712 | 2002-10-27 Fernando Perez <fperez@colorado.edu> |
|
2701 | 2713 | |
|
2702 | 2714 | * IPython/usage.py (__doc__): updated the --help information and |
|
2703 | 2715 | the ipythonrc file to indicate that -log generates |
|
2704 | 2716 | ./ipython.log. Also fixed the corresponding info in @logstart. |
|
2705 | 2717 | This and several other fixes in the manuals thanks to reports by |
|
2706 | 2718 | François Pinard <pinard-AT-iro.umontreal.ca>. |
|
2707 | 2719 | |
|
2708 | 2720 | * IPython/Logger.py (Logger.switch_log): Fixed error message to |
|
2709 | 2721 | refer to @logstart (instead of @log, which doesn't exist). |
|
2710 | 2722 | |
|
2711 | 2723 | * IPython/iplib.py (InteractiveShell._prefilter): fixed |
|
2712 | 2724 | AttributeError crash. Thanks to Christopher Armstrong |
|
2713 | 2725 | <radix-AT-twistedmatrix.com> for the report/fix. This bug had been |
|
2714 | 2726 | introduced recently (in 0.2.14pre37) with the fix to the eval |
|
2715 | 2727 | problem mentioned below. |
|
2716 | 2728 | |
|
2717 | 2729 | 2002-10-17 Fernando Perez <fperez@colorado.edu> |
|
2718 | 2730 | |
|
2719 | 2731 | * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows |
|
2720 | 2732 | installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>. |
|
2721 | 2733 | |
|
2722 | 2734 | * IPython/iplib.py (InteractiveShell._prefilter): Many changes to |
|
2723 | 2735 | this function to fix a problem reported by Alex Schmolck. He saw |
|
2724 | 2736 | it with list comprehensions and generators, which were getting |
|
2725 | 2737 | called twice. The real problem was an 'eval' call in testing for |
|
2726 | 2738 | automagic which was evaluating the input line silently. |
|
2727 | 2739 | |
|
2728 | 2740 | This is a potentially very nasty bug, if the input has side |
|
2729 | 2741 | effects which must not be repeated. The code is much cleaner now, |
|
2730 | 2742 | without any blanket 'except' left and with a regexp test for |
|
2731 | 2743 | actual function names. |
|
2732 | 2744 | |
|
2733 | 2745 | But an eval remains, which I'm not fully comfortable with. I just |
|
2734 | 2746 | don't know how to find out if an expression could be a callable in |
|
2735 | 2747 | the user's namespace without doing an eval on the string. However |
|
2736 | 2748 | that string is now much more strictly checked so that no code |
|
2737 | 2749 | slips by, so the eval should only happen for things that can |
|
2738 | 2750 | really be only function/method names. |
|
2739 | 2751 | |
|
2740 | 2752 | 2002-10-15 Fernando Perez <fperez@colorado.edu> |
|
2741 | 2753 | |
|
2742 | 2754 | * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac |
|
2743 | 2755 | OSX information to main manual, removed README_Mac_OSX file from |
|
2744 | 2756 | distribution. Also updated credits for recent additions. |
|
2745 | 2757 | |
|
2746 | 2758 | 2002-10-10 Fernando Perez <fperez@colorado.edu> |
|
2747 | 2759 | |
|
2748 | 2760 | * README_Mac_OSX: Added a README for Mac OSX users for fixing |
|
2749 | 2761 | terminal-related issues. Many thanks to Andrea Riciputi |
|
2750 | 2762 | <andrea.riciputi-AT-libero.it> for writing it. |
|
2751 | 2763 | |
|
2752 | 2764 | * IPython/UserConfig/ipythonrc.py: Fixes to various small issues, |
|
2753 | 2765 | thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2754 | 2766 | |
|
2755 | 2767 | * setup.py (make_shortcut): Fixes for Windows installation. Thanks |
|
2756 | 2768 | to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad |
|
2757 | 2769 | <syver-en-AT-online.no> who both submitted patches for this problem. |
|
2758 | 2770 | |
|
2759 | 2771 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for |
|
2760 | 2772 | global embedding to make sure that things don't overwrite user |
|
2761 | 2773 | globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com> |
|
2762 | 2774 | |
|
2763 | 2775 | * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6 |
|
2764 | 2776 | compatibility. Thanks to Hayden Callow |
|
2765 | 2777 | <h.callow-AT-elec.canterbury.ac.nz> |
|
2766 | 2778 | |
|
2767 | 2779 | 2002-10-04 Fernando Perez <fperez@colorado.edu> |
|
2768 | 2780 | |
|
2769 | 2781 | * IPython/Gnuplot2.py (PlotItem): Added 'index' option for |
|
2770 | 2782 | Gnuplot.File objects. |
|
2771 | 2783 | |
|
2772 | 2784 | 2002-07-23 Fernando Perez <fperez@colorado.edu> |
|
2773 | 2785 | |
|
2774 | 2786 | * IPython/genutils.py (timing): Added timings() and timing() for |
|
2775 | 2787 | quick access to the most commonly needed data, the execution |
|
2776 | 2788 | times. Old timing() renamed to timings_out(). |
|
2777 | 2789 | |
|
2778 | 2790 | 2002-07-18 Fernando Perez <fperez@colorado.edu> |
|
2779 | 2791 | |
|
2780 | 2792 | * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed |
|
2781 | 2793 | bug with nested instances disrupting the parent's tab completion. |
|
2782 | 2794 | |
|
2783 | 2795 | * IPython/iplib.py (all_completions): Added Alex Schmolck's |
|
2784 | 2796 | all_completions code to begin the emacs integration. |
|
2785 | 2797 | |
|
2786 | 2798 | * IPython/Gnuplot2.py (zip_items): Added optional 'titles' |
|
2787 | 2799 | argument to allow titling individual arrays when plotting. |
|
2788 | 2800 | |
|
2789 | 2801 | 2002-07-15 Fernando Perez <fperez@colorado.edu> |
|
2790 | 2802 | |
|
2791 | 2803 | * setup.py (make_shortcut): changed to retrieve the value of |
|
2792 | 2804 | 'Program Files' directory from the registry (this value changes in |
|
2793 | 2805 | non-english versions of Windows). Thanks to Thomas Fanslau |
|
2794 | 2806 | <tfanslau-AT-gmx.de> for the report. |
|
2795 | 2807 | |
|
2796 | 2808 | 2002-07-10 Fernando Perez <fperez@colorado.edu> |
|
2797 | 2809 | |
|
2798 | 2810 | * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for |
|
2799 | 2811 | a bug in pdb, which crashes if a line with only whitespace is |
|
2800 | 2812 | entered. Bug report submitted to sourceforge. |
|
2801 | 2813 | |
|
2802 | 2814 | 2002-07-09 Fernando Perez <fperez@colorado.edu> |
|
2803 | 2815 | |
|
2804 | 2816 | * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when |
|
2805 | 2817 | reporting exceptions (it's a bug in inspect.py, I just set a |
|
2806 | 2818 | workaround). |
|
2807 | 2819 | |
|
2808 | 2820 | 2002-07-08 Fernando Perez <fperez@colorado.edu> |
|
2809 | 2821 | |
|
2810 | 2822 | * IPython/iplib.py (InteractiveShell.__init__): fixed reference to |
|
2811 | 2823 | __IPYTHON__ in __builtins__ to show up in user_ns. |
|
2812 | 2824 | |
|
2813 | 2825 | 2002-07-03 Fernando Perez <fperez@colorado.edu> |
|
2814 | 2826 | |
|
2815 | 2827 | * IPython/GnuplotInteractive.py (magic_gp_set_default): changed |
|
2816 | 2828 | name from @gp_set_instance to @gp_set_default. |
|
2817 | 2829 | |
|
2818 | 2830 | * IPython/ipmaker.py (make_IPython): default editor value set to |
|
2819 | 2831 | '0' (a string), to match the rc file. Otherwise will crash when |
|
2820 | 2832 | .strip() is called on it. |
|
2821 | 2833 | |
|
2822 | 2834 | |
|
2823 | 2835 | 2002-06-28 Fernando Perez <fperez@colorado.edu> |
|
2824 | 2836 | |
|
2825 | 2837 | * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing |
|
2826 | 2838 | of files in current directory when a file is executed via |
|
2827 | 2839 | @run. Patch also by RA <ralf_ahlbrink-AT-web.de>. |
|
2828 | 2840 | |
|
2829 | 2841 | * setup.py (manfiles): fix for rpm builds, submitted by RA |
|
2830 | 2842 | <ralf_ahlbrink-AT-web.de>. Now we have RPMs! |
|
2831 | 2843 | |
|
2832 | 2844 | * IPython/ipmaker.py (make_IPython): fixed lookup of default |
|
2833 | 2845 | editor when set to '0'. Problem was, '0' evaluates to True (it's a |
|
2834 | 2846 | string!). A. Schmolck caught this one. |
|
2835 | 2847 | |
|
2836 | 2848 | 2002-06-27 Fernando Perez <fperez@colorado.edu> |
|
2837 | 2849 | |
|
2838 | 2850 | * IPython/ipmaker.py (make_IPython): fixed bug when running user |
|
2839 | 2851 | defined files at the cmd line. __name__ wasn't being set to |
|
2840 | 2852 | __main__. |
|
2841 | 2853 | |
|
2842 | 2854 | * IPython/Gnuplot2.py (zip_items): improved it so it can plot also |
|
2843 | 2855 | regular lists and tuples besides Numeric arrays. |
|
2844 | 2856 | |
|
2845 | 2857 | * IPython/Prompts.py (CachedOutput.__call__): Added output |
|
2846 | 2858 | supression for input ending with ';'. Similar to Mathematica and |
|
2847 | 2859 | Matlab. The _* vars and Out[] list are still updated, just like |
|
2848 | 2860 | Mathematica behaves. |
|
2849 | 2861 | |
|
2850 | 2862 | 2002-06-25 Fernando Perez <fperez@colorado.edu> |
|
2851 | 2863 | |
|
2852 | 2864 | * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of |
|
2853 | 2865 | .ini extensions for profiels under Windows. |
|
2854 | 2866 | |
|
2855 | 2867 | * IPython/OInspect.py (Inspector.pinfo): improved alignment of |
|
2856 | 2868 | string form. Fix contributed by Alexander Schmolck |
|
2857 | 2869 | <a.schmolck-AT-gmx.net> |
|
2858 | 2870 | |
|
2859 | 2871 | * IPython/GnuplotRuntime.py (gp_new): new function. Returns a |
|
2860 | 2872 | pre-configured Gnuplot instance. |
|
2861 | 2873 | |
|
2862 | 2874 | 2002-06-21 Fernando Perez <fperez@colorado.edu> |
|
2863 | 2875 | |
|
2864 | 2876 | * IPython/numutils.py (exp_safe): new function, works around the |
|
2865 | 2877 | underflow problems in Numeric. |
|
2866 | 2878 | (log2): New fn. Safe log in base 2: returns exact integer answer |
|
2867 | 2879 | for exact integer powers of 2. |
|
2868 | 2880 | |
|
2869 | 2881 | * IPython/Magic.py (get_py_filename): fixed it not expanding '~' |
|
2870 | 2882 | properly. |
|
2871 | 2883 | |
|
2872 | 2884 | 2002-06-20 Fernando Perez <fperez@colorado.edu> |
|
2873 | 2885 | |
|
2874 | 2886 | * IPython/genutils.py (timing): new function like |
|
2875 | 2887 | Mathematica's. Similar to time_test, but returns more info. |
|
2876 | 2888 | |
|
2877 | 2889 | 2002-06-18 Fernando Perez <fperez@colorado.edu> |
|
2878 | 2890 | |
|
2879 | 2891 | * IPython/Magic.py (Magic.magic_save): modified @save and @r |
|
2880 | 2892 | according to Mike Heeter's suggestions. |
|
2881 | 2893 | |
|
2882 | 2894 | 2002-06-16 Fernando Perez <fperez@colorado.edu> |
|
2883 | 2895 | |
|
2884 | 2896 | * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot |
|
2885 | 2897 | system. GnuplotMagic is gone as a user-directory option. New files |
|
2886 | 2898 | make it easier to use all the gnuplot stuff both from external |
|
2887 | 2899 | programs as well as from IPython. Had to rewrite part of |
|
2888 | 2900 | hardcopy() b/c of a strange bug: often the ps files simply don't |
|
2889 | 2901 | get created, and require a repeat of the command (often several |
|
2890 | 2902 | times). |
|
2891 | 2903 | |
|
2892 | 2904 | * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to |
|
2893 | 2905 | resolve output channel at call time, so that if sys.stderr has |
|
2894 | 2906 | been redirected by user this gets honored. |
|
2895 | 2907 | |
|
2896 | 2908 | 2002-06-13 Fernando Perez <fperez@colorado.edu> |
|
2897 | 2909 | |
|
2898 | 2910 | * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to |
|
2899 | 2911 | IPShell. Kept a copy with the old names to avoid breaking people's |
|
2900 | 2912 | embedded code. |
|
2901 | 2913 | |
|
2902 | 2914 | * IPython/ipython: simplified it to the bare minimum after |
|
2903 | 2915 | Holger's suggestions. Added info about how to use it in |
|
2904 | 2916 | PYTHONSTARTUP. |
|
2905 | 2917 | |
|
2906 | 2918 | * IPython/Shell.py (IPythonShell): changed the options passing |
|
2907 | 2919 | from a string with funky %s replacements to a straight list. Maybe |
|
2908 | 2920 | a bit more typing, but it follows sys.argv conventions, so there's |
|
2909 | 2921 | less special-casing to remember. |
|
2910 | 2922 | |
|
2911 | 2923 | 2002-06-12 Fernando Perez <fperez@colorado.edu> |
|
2912 | 2924 | |
|
2913 | 2925 | * IPython/Magic.py (Magic.magic_r): new magic auto-repeat |
|
2914 | 2926 | command. Thanks to a suggestion by Mike Heeter. |
|
2915 | 2927 | (Magic.magic_pfile): added behavior to look at filenames if given |
|
2916 | 2928 | arg is not a defined object. |
|
2917 | 2929 | (Magic.magic_save): New @save function to save code snippets. Also |
|
2918 | 2930 | a Mike Heeter idea. |
|
2919 | 2931 | |
|
2920 | 2932 | * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to |
|
2921 | 2933 | plot() and replot(). Much more convenient now, especially for |
|
2922 | 2934 | interactive use. |
|
2923 | 2935 | |
|
2924 | 2936 | * IPython/Magic.py (Magic.magic_run): Added .py automatically to |
|
2925 | 2937 | filenames. |
|
2926 | 2938 | |
|
2927 | 2939 | 2002-06-02 Fernando Perez <fperez@colorado.edu> |
|
2928 | 2940 | |
|
2929 | 2941 | * IPython/Struct.py (Struct.__init__): modified to admit |
|
2930 | 2942 | initialization via another struct. |
|
2931 | 2943 | |
|
2932 | 2944 | * IPython/genutils.py (SystemExec.__init__): New stateful |
|
2933 | 2945 | interface to xsys and bq. Useful for writing system scripts. |
|
2934 | 2946 | |
|
2935 | 2947 | 2002-05-30 Fernando Perez <fperez@colorado.edu> |
|
2936 | 2948 | |
|
2937 | 2949 | * MANIFEST.in: Changed docfile selection to exclude all the lyx |
|
2938 | 2950 | documents. This will make the user download smaller (it's getting |
|
2939 | 2951 | too big). |
|
2940 | 2952 | |
|
2941 | 2953 | 2002-05-29 Fernando Perez <fperez@colorado.edu> |
|
2942 | 2954 | |
|
2943 | 2955 | * IPython/iplib.py (_FakeModule.__init__): New class introduced to |
|
2944 | 2956 | fix problems with shelve and pickle. Seems to work, but I don't |
|
2945 | 2957 | know if corner cases break it. Thanks to Mike Heeter |
|
2946 | 2958 | <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases. |
|
2947 | 2959 | |
|
2948 | 2960 | 2002-05-24 Fernando Perez <fperez@colorado.edu> |
|
2949 | 2961 | |
|
2950 | 2962 | * IPython/Magic.py (Macro.__init__): fixed magics embedded in |
|
2951 | 2963 | macros having broken. |
|
2952 | 2964 | |
|
2953 | 2965 | 2002-05-21 Fernando Perez <fperez@colorado.edu> |
|
2954 | 2966 | |
|
2955 | 2967 | * IPython/Magic.py (Magic.magic_logstart): fixed recently |
|
2956 | 2968 | introduced logging bug: all history before logging started was |
|
2957 | 2969 | being written one character per line! This came from the redesign |
|
2958 | 2970 | of the input history as a special list which slices to strings, |
|
2959 | 2971 | not to lists. |
|
2960 | 2972 | |
|
2961 | 2973 | 2002-05-20 Fernando Perez <fperez@colorado.edu> |
|
2962 | 2974 | |
|
2963 | 2975 | * IPython/Prompts.py (CachedOutput.__init__): made the color table |
|
2964 | 2976 | be an attribute of all classes in this module. The design of these |
|
2965 | 2977 | classes needs some serious overhauling. |
|
2966 | 2978 | |
|
2967 | 2979 | * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug |
|
2968 | 2980 | which was ignoring '_' in option names. |
|
2969 | 2981 | |
|
2970 | 2982 | * IPython/ultraTB.py (FormattedTB.__init__): Changed |
|
2971 | 2983 | 'Verbose_novars' to 'Context' and made it the new default. It's a |
|
2972 | 2984 | bit more readable and also safer than verbose. |
|
2973 | 2985 | |
|
2974 | 2986 | * IPython/PyColorize.py (Parser.__call__): Fixed coloring of |
|
2975 | 2987 | triple-quoted strings. |
|
2976 | 2988 | |
|
2977 | 2989 | * IPython/OInspect.py (__all__): new module exposing the object |
|
2978 | 2990 | introspection facilities. Now the corresponding magics are dummy |
|
2979 | 2991 | wrappers around this. Having this module will make it much easier |
|
2980 | 2992 | to put these functions into our modified pdb. |
|
2981 | 2993 | This new object inspector system uses the new colorizing module, |
|
2982 | 2994 | so source code and other things are nicely syntax highlighted. |
|
2983 | 2995 | |
|
2984 | 2996 | 2002-05-18 Fernando Perez <fperez@colorado.edu> |
|
2985 | 2997 | |
|
2986 | 2998 | * IPython/ColorANSI.py: Split the coloring tools into a separate |
|
2987 | 2999 | module so I can use them in other code easier (they were part of |
|
2988 | 3000 | ultraTB). |
|
2989 | 3001 | |
|
2990 | 3002 | 2002-05-17 Fernando Perez <fperez@colorado.edu> |
|
2991 | 3003 | |
|
2992 | 3004 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2993 | 3005 | fixed it to set the global 'g' also to the called instance, as |
|
2994 | 3006 | long as 'g' was still a gnuplot instance (so it doesn't overwrite |
|
2995 | 3007 | user's 'g' variables). |
|
2996 | 3008 | |
|
2997 | 3009 | * IPython/iplib.py (InteractiveShell.__init__): Added In/Out |
|
2998 | 3010 | global variables (aliases to _ih,_oh) so that users which expect |
|
2999 | 3011 | In[5] or Out[7] to work aren't unpleasantly surprised. |
|
3000 | 3012 | (InputList.__getslice__): new class to allow executing slices of |
|
3001 | 3013 | input history directly. Very simple class, complements the use of |
|
3002 | 3014 | macros. |
|
3003 | 3015 | |
|
3004 | 3016 | 2002-05-16 Fernando Perez <fperez@colorado.edu> |
|
3005 | 3017 | |
|
3006 | 3018 | * setup.py (docdirbase): make doc directory be just doc/IPython |
|
3007 | 3019 | without version numbers, it will reduce clutter for users. |
|
3008 | 3020 | |
|
3009 | 3021 | * IPython/Magic.py (Magic.magic_run): Add explicit local dict to |
|
3010 | 3022 | execfile call to prevent possible memory leak. See for details: |
|
3011 | 3023 | http://mail.python.org/pipermail/python-list/2002-February/088476.html |
|
3012 | 3024 | |
|
3013 | 3025 | 2002-05-15 Fernando Perez <fperez@colorado.edu> |
|
3014 | 3026 | |
|
3015 | 3027 | * IPython/Magic.py (Magic.magic_psource): made the object |
|
3016 | 3028 | introspection names be more standard: pdoc, pdef, pfile and |
|
3017 | 3029 | psource. They all print/page their output, and it makes |
|
3018 | 3030 | remembering them easier. Kept old names for compatibility as |
|
3019 | 3031 | aliases. |
|
3020 | 3032 | |
|
3021 | 3033 | 2002-05-14 Fernando Perez <fperez@colorado.edu> |
|
3022 | 3034 | |
|
3023 | 3035 | * IPython/UserConfig/GnuplotMagic.py: I think I finally understood |
|
3024 | 3036 | what the mouse problem was. The trick is to use gnuplot with temp |
|
3025 | 3037 | files and NOT with pipes (for data communication), because having |
|
3026 | 3038 | both pipes and the mouse on is bad news. |
|
3027 | 3039 | |
|
3028 | 3040 | 2002-05-13 Fernando Perez <fperez@colorado.edu> |
|
3029 | 3041 | |
|
3030 | 3042 | * IPython/Magic.py (Magic._ofind): fixed namespace order search |
|
3031 | 3043 | bug. Information would be reported about builtins even when |
|
3032 | 3044 | user-defined functions overrode them. |
|
3033 | 3045 | |
|
3034 | 3046 | 2002-05-11 Fernando Perez <fperez@colorado.edu> |
|
3035 | 3047 | |
|
3036 | 3048 | * IPython/__init__.py (__all__): removed FlexCompleter from |
|
3037 | 3049 | __all__ so that things don't fail in platforms without readline. |
|
3038 | 3050 | |
|
3039 | 3051 | 2002-05-10 Fernando Perez <fperez@colorado.edu> |
|
3040 | 3052 | |
|
3041 | 3053 | * IPython/__init__.py (__all__): removed numutils from __all__ b/c |
|
3042 | 3054 | it requires Numeric, effectively making Numeric a dependency for |
|
3043 | 3055 | IPython. |
|
3044 | 3056 | |
|
3045 | 3057 | * Released 0.2.13 |
|
3046 | 3058 | |
|
3047 | 3059 | * IPython/Magic.py (Magic.magic_prun): big overhaul to the |
|
3048 | 3060 | profiler interface. Now all the major options from the profiler |
|
3049 | 3061 | module are directly supported in IPython, both for single |
|
3050 | 3062 | expressions (@prun) and for full programs (@run -p). |
|
3051 | 3063 | |
|
3052 | 3064 | 2002-05-09 Fernando Perez <fperez@colorado.edu> |
|
3053 | 3065 | |
|
3054 | 3066 | * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of |
|
3055 | 3067 | magic properly formatted for screen. |
|
3056 | 3068 | |
|
3057 | 3069 | * setup.py (make_shortcut): Changed things to put pdf version in |
|
3058 | 3070 | doc/ instead of doc/manual (had to change lyxport a bit). |
|
3059 | 3071 | |
|
3060 | 3072 | * IPython/Magic.py (Profile.string_stats): made profile runs go |
|
3061 | 3073 | through pager (they are long and a pager allows searching, saving, |
|
3062 | 3074 | etc.) |
|
3063 | 3075 | |
|
3064 | 3076 | 2002-05-08 Fernando Perez <fperez@colorado.edu> |
|
3065 | 3077 | |
|
3066 | 3078 | * Released 0.2.12 |
|
3067 | 3079 | |
|
3068 | 3080 | 2002-05-06 Fernando Perez <fperez@colorado.edu> |
|
3069 | 3081 | |
|
3070 | 3082 | * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently |
|
3071 | 3083 | introduced); 'hist n1 n2' was broken. |
|
3072 | 3084 | (Magic.magic_pdb): added optional on/off arguments to @pdb |
|
3073 | 3085 | (Magic.magic_run): added option -i to @run, which executes code in |
|
3074 | 3086 | the IPython namespace instead of a clean one. Also added @irun as |
|
3075 | 3087 | an alias to @run -i. |
|
3076 | 3088 | |
|
3077 | 3089 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
3078 | 3090 | fixed (it didn't really do anything, the namespaces were wrong). |
|
3079 | 3091 | |
|
3080 | 3092 | * IPython/Debugger.py (__init__): Added workaround for python 2.1 |
|
3081 | 3093 | |
|
3082 | 3094 | * IPython/__init__.py (__all__): Fixed package namespace, now |
|
3083 | 3095 | 'import IPython' does give access to IPython.<all> as |
|
3084 | 3096 | expected. Also renamed __release__ to Release. |
|
3085 | 3097 | |
|
3086 | 3098 | * IPython/Debugger.py (__license__): created new Pdb class which |
|
3087 | 3099 | functions like a drop-in for the normal pdb.Pdb but does NOT |
|
3088 | 3100 | import readline by default. This way it doesn't muck up IPython's |
|
3089 | 3101 | readline handling, and now tab-completion finally works in the |
|
3090 | 3102 | debugger -- sort of. It completes things globally visible, but the |
|
3091 | 3103 | completer doesn't track the stack as pdb walks it. That's a bit |
|
3092 | 3104 | tricky, and I'll have to implement it later. |
|
3093 | 3105 | |
|
3094 | 3106 | 2002-05-05 Fernando Perez <fperez@colorado.edu> |
|
3095 | 3107 | |
|
3096 | 3108 | * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for |
|
3097 | 3109 | magic docstrings when printed via ? (explicit \'s were being |
|
3098 | 3110 | printed). |
|
3099 | 3111 | |
|
3100 | 3112 | * IPython/ipmaker.py (make_IPython): fixed namespace |
|
3101 | 3113 | identification bug. Now variables loaded via logs or command-line |
|
3102 | 3114 | files are recognized in the interactive namespace by @who. |
|
3103 | 3115 | |
|
3104 | 3116 | * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in |
|
3105 | 3117 | log replay system stemming from the string form of Structs. |
|
3106 | 3118 | |
|
3107 | 3119 | * IPython/Magic.py (Macro.__init__): improved macros to properly |
|
3108 | 3120 | handle magic commands in them. |
|
3109 | 3121 | (Magic.magic_logstart): usernames are now expanded so 'logstart |
|
3110 | 3122 | ~/mylog' now works. |
|
3111 | 3123 | |
|
3112 | 3124 | * IPython/iplib.py (complete): fixed bug where paths starting with |
|
3113 | 3125 | '/' would be completed as magic names. |
|
3114 | 3126 | |
|
3115 | 3127 | 2002-05-04 Fernando Perez <fperez@colorado.edu> |
|
3116 | 3128 | |
|
3117 | 3129 | * IPython/Magic.py (Magic.magic_run): added options -p and -f to |
|
3118 | 3130 | allow running full programs under the profiler's control. |
|
3119 | 3131 | |
|
3120 | 3132 | * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars |
|
3121 | 3133 | mode to report exceptions verbosely but without formatting |
|
3122 | 3134 | variables. This addresses the issue of ipython 'freezing' (it's |
|
3123 | 3135 | not frozen, but caught in an expensive formatting loop) when huge |
|
3124 | 3136 | variables are in the context of an exception. |
|
3125 | 3137 | (VerboseTB.text): Added '--->' markers at line where exception was |
|
3126 | 3138 | triggered. Much clearer to read, especially in NoColor modes. |
|
3127 | 3139 | |
|
3128 | 3140 | * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been |
|
3129 | 3141 | implemented in reverse when changing to the new parse_options(). |
|
3130 | 3142 | |
|
3131 | 3143 | 2002-05-03 Fernando Perez <fperez@colorado.edu> |
|
3132 | 3144 | |
|
3133 | 3145 | * IPython/Magic.py (Magic.parse_options): new function so that |
|
3134 | 3146 | magics can parse options easier. |
|
3135 | 3147 | (Magic.magic_prun): new function similar to profile.run(), |
|
3136 | 3148 | suggested by Chris Hart. |
|
3137 | 3149 | (Magic.magic_cd): fixed behavior so that it only changes if |
|
3138 | 3150 | directory actually is in history. |
|
3139 | 3151 | |
|
3140 | 3152 | * IPython/usage.py (__doc__): added information about potential |
|
3141 | 3153 | slowness of Verbose exception mode when there are huge data |
|
3142 | 3154 | structures to be formatted (thanks to Archie Paulson). |
|
3143 | 3155 | |
|
3144 | 3156 | * IPython/ipmaker.py (make_IPython): Changed default logging |
|
3145 | 3157 | (when simply called with -log) to use curr_dir/ipython.log in |
|
3146 | 3158 | rotate mode. Fixed crash which was occuring with -log before |
|
3147 | 3159 | (thanks to Jim Boyle). |
|
3148 | 3160 | |
|
3149 | 3161 | 2002-05-01 Fernando Perez <fperez@colorado.edu> |
|
3150 | 3162 | |
|
3151 | 3163 | * Released 0.2.11 for these fixes (mainly the ultraTB one which |
|
3152 | 3164 | was nasty -- though somewhat of a corner case). |
|
3153 | 3165 | |
|
3154 | 3166 | * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to |
|
3155 | 3167 | text (was a bug). |
|
3156 | 3168 | |
|
3157 | 3169 | 2002-04-30 Fernando Perez <fperez@colorado.edu> |
|
3158 | 3170 | |
|
3159 | 3171 | * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add |
|
3160 | 3172 | a print after ^D or ^C from the user so that the In[] prompt |
|
3161 | 3173 | doesn't over-run the gnuplot one. |
|
3162 | 3174 | |
|
3163 | 3175 | 2002-04-29 Fernando Perez <fperez@colorado.edu> |
|
3164 | 3176 | |
|
3165 | 3177 | * Released 0.2.10 |
|
3166 | 3178 | |
|
3167 | 3179 | * IPython/__release__.py (version): get date dynamically. |
|
3168 | 3180 | |
|
3169 | 3181 | * Misc. documentation updates thanks to Arnd's comments. Also ran |
|
3170 | 3182 | a full spellcheck on the manual (hadn't been done in a while). |
|
3171 | 3183 | |
|
3172 | 3184 | 2002-04-27 Fernando Perez <fperez@colorado.edu> |
|
3173 | 3185 | |
|
3174 | 3186 | * IPython/Magic.py (Magic.magic_logstart): Fixed bug where |
|
3175 | 3187 | starting a log in mid-session would reset the input history list. |
|
3176 | 3188 | |
|
3177 | 3189 | 2002-04-26 Fernando Perez <fperez@colorado.edu> |
|
3178 | 3190 | |
|
3179 | 3191 | * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not |
|
3180 | 3192 | all files were being included in an update. Now anything in |
|
3181 | 3193 | UserConfig that matches [A-Za-z]*.py will go (this excludes |
|
3182 | 3194 | __init__.py) |
|
3183 | 3195 | |
|
3184 | 3196 | 2002-04-25 Fernando Perez <fperez@colorado.edu> |
|
3185 | 3197 | |
|
3186 | 3198 | * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__ |
|
3187 | 3199 | to __builtins__ so that any form of embedded or imported code can |
|
3188 | 3200 | test for being inside IPython. |
|
3189 | 3201 | |
|
3190 | 3202 | * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance): |
|
3191 | 3203 | changed to GnuplotMagic because it's now an importable module, |
|
3192 | 3204 | this makes the name follow that of the standard Gnuplot module. |
|
3193 | 3205 | GnuplotMagic can now be loaded at any time in mid-session. |
|
3194 | 3206 | |
|
3195 | 3207 | 2002-04-24 Fernando Perez <fperez@colorado.edu> |
|
3196 | 3208 | |
|
3197 | 3209 | * IPython/numutils.py: removed SIUnits. It doesn't properly set |
|
3198 | 3210 | the globals (IPython has its own namespace) and the |
|
3199 | 3211 | PhysicalQuantity stuff is much better anyway. |
|
3200 | 3212 | |
|
3201 | 3213 | * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot |
|
3202 | 3214 | embedding example to standard user directory for |
|
3203 | 3215 | distribution. Also put it in the manual. |
|
3204 | 3216 | |
|
3205 | 3217 | * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot |
|
3206 | 3218 | instance as first argument (so it doesn't rely on some obscure |
|
3207 | 3219 | hidden global). |
|
3208 | 3220 | |
|
3209 | 3221 | * IPython/UserConfig/ipythonrc.py: put () back in accepted |
|
3210 | 3222 | delimiters. While it prevents ().TAB from working, it allows |
|
3211 | 3223 | completions in open (... expressions. This is by far a more common |
|
3212 | 3224 | case. |
|
3213 | 3225 | |
|
3214 | 3226 | 2002-04-23 Fernando Perez <fperez@colorado.edu> |
|
3215 | 3227 | |
|
3216 | 3228 | * IPython/Extensions/InterpreterPasteInput.py: new |
|
3217 | 3229 | syntax-processing module for pasting lines with >>> or ... at the |
|
3218 | 3230 | start. |
|
3219 | 3231 | |
|
3220 | 3232 | * IPython/Extensions/PhysicalQ_Interactive.py |
|
3221 | 3233 | (PhysicalQuantityInteractive.__int__): fixed to work with either |
|
3222 | 3234 | Numeric or math. |
|
3223 | 3235 | |
|
3224 | 3236 | * IPython/UserConfig/ipythonrc-numeric.py: reorganized the |
|
3225 | 3237 | provided profiles. Now we have: |
|
3226 | 3238 | -math -> math module as * and cmath with its own namespace. |
|
3227 | 3239 | -numeric -> Numeric as *, plus gnuplot & grace |
|
3228 | 3240 | -physics -> same as before |
|
3229 | 3241 | |
|
3230 | 3242 | * IPython/Magic.py (Magic.magic_magic): Fixed bug where |
|
3231 | 3243 | user-defined magics wouldn't be found by @magic if they were |
|
3232 | 3244 | defined as class methods. Also cleaned up the namespace search |
|
3233 | 3245 | logic and the string building (to use %s instead of many repeated |
|
3234 | 3246 | string adds). |
|
3235 | 3247 | |
|
3236 | 3248 | * IPython/UserConfig/example-magic.py (magic_foo): updated example |
|
3237 | 3249 | of user-defined magics to operate with class methods (cleaner, in |
|
3238 | 3250 | line with the gnuplot code). |
|
3239 | 3251 | |
|
3240 | 3252 | 2002-04-22 Fernando Perez <fperez@colorado.edu> |
|
3241 | 3253 | |
|
3242 | 3254 | * setup.py: updated dependency list so that manual is updated when |
|
3243 | 3255 | all included files change. |
|
3244 | 3256 | |
|
3245 | 3257 | * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring |
|
3246 | 3258 | the delimiter removal option (the fix is ugly right now). |
|
3247 | 3259 | |
|
3248 | 3260 | * IPython/UserConfig/ipythonrc-physics.py: simplified not to load |
|
3249 | 3261 | all of the math profile (quicker loading, no conflict between |
|
3250 | 3262 | g-9.8 and g-gnuplot). |
|
3251 | 3263 | |
|
3252 | 3264 | * IPython/CrashHandler.py (CrashHandler.__call__): changed default |
|
3253 | 3265 | name of post-mortem files to IPython_crash_report.txt. |
|
3254 | 3266 | |
|
3255 | 3267 | * Cleanup/update of the docs. Added all the new readline info and |
|
3256 | 3268 | formatted all lists as 'real lists'. |
|
3257 | 3269 | |
|
3258 | 3270 | * IPython/ipmaker.py (make_IPython): removed now-obsolete |
|
3259 | 3271 | tab-completion options, since the full readline parse_and_bind is |
|
3260 | 3272 | now accessible. |
|
3261 | 3273 | |
|
3262 | 3274 | * IPython/iplib.py (InteractiveShell.init_readline): Changed |
|
3263 | 3275 | handling of readline options. Now users can specify any string to |
|
3264 | 3276 | be passed to parse_and_bind(), as well as the delimiters to be |
|
3265 | 3277 | removed. |
|
3266 | 3278 | (InteractiveShell.__init__): Added __name__ to the global |
|
3267 | 3279 | namespace so that things like Itpl which rely on its existence |
|
3268 | 3280 | don't crash. |
|
3269 | 3281 | (InteractiveShell._prefilter): Defined the default with a _ so |
|
3270 | 3282 | that prefilter() is easier to override, while the default one |
|
3271 | 3283 | remains available. |
|
3272 | 3284 | |
|
3273 | 3285 | 2002-04-18 Fernando Perez <fperez@colorado.edu> |
|
3274 | 3286 | |
|
3275 | 3287 | * Added information about pdb in the docs. |
|
3276 | 3288 | |
|
3277 | 3289 | 2002-04-17 Fernando Perez <fperez@colorado.edu> |
|
3278 | 3290 | |
|
3279 | 3291 | * IPython/ipmaker.py (make_IPython): added rc_override option to |
|
3280 | 3292 | allow passing config options at creation time which may override |
|
3281 | 3293 | anything set in the config files or command line. This is |
|
3282 | 3294 | particularly useful for configuring embedded instances. |
|
3283 | 3295 | |
|
3284 | 3296 | 2002-04-15 Fernando Perez <fperez@colorado.edu> |
|
3285 | 3297 | |
|
3286 | 3298 | * IPython/Logger.py (Logger.log): Fixed a nasty bug which could |
|
3287 | 3299 | crash embedded instances because of the input cache falling out of |
|
3288 | 3300 | sync with the output counter. |
|
3289 | 3301 | |
|
3290 | 3302 | * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug |
|
3291 | 3303 | mode which calls pdb after an uncaught exception in IPython itself. |
|
3292 | 3304 | |
|
3293 | 3305 | 2002-04-14 Fernando Perez <fperez@colorado.edu> |
|
3294 | 3306 | |
|
3295 | 3307 | * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up |
|
3296 | 3308 | readline, fix it back after each call. |
|
3297 | 3309 | |
|
3298 | 3310 | * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private |
|
3299 | 3311 | method to force all access via __call__(), which guarantees that |
|
3300 | 3312 | traceback references are properly deleted. |
|
3301 | 3313 | |
|
3302 | 3314 | * IPython/Prompts.py (CachedOutput._display): minor fixes to |
|
3303 | 3315 | improve printing when pprint is in use. |
|
3304 | 3316 | |
|
3305 | 3317 | 2002-04-13 Fernando Perez <fperez@colorado.edu> |
|
3306 | 3318 | |
|
3307 | 3319 | * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit |
|
3308 | 3320 | exceptions aren't caught anymore. If the user triggers one, he |
|
3309 | 3321 | should know why he's doing it and it should go all the way up, |
|
3310 | 3322 | just like any other exception. So now @abort will fully kill the |
|
3311 | 3323 | embedded interpreter and the embedding code (unless that happens |
|
3312 | 3324 | to catch SystemExit). |
|
3313 | 3325 | |
|
3314 | 3326 | * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag |
|
3315 | 3327 | and a debugger() method to invoke the interactive pdb debugger |
|
3316 | 3328 | after printing exception information. Also added the corresponding |
|
3317 | 3329 | -pdb option and @pdb magic to control this feature, and updated |
|
3318 | 3330 | the docs. After a suggestion from Christopher Hart |
|
3319 | 3331 | (hart-AT-caltech.edu). |
|
3320 | 3332 | |
|
3321 | 3333 | 2002-04-12 Fernando Perez <fperez@colorado.edu> |
|
3322 | 3334 | |
|
3323 | 3335 | * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use |
|
3324 | 3336 | the exception handlers defined by the user (not the CrashHandler) |
|
3325 | 3337 | so that user exceptions don't trigger an ipython bug report. |
|
3326 | 3338 | |
|
3327 | 3339 | * IPython/ultraTB.py (ColorTB.__init__): made the color scheme |
|
3328 | 3340 | configurable (it should have always been so). |
|
3329 | 3341 | |
|
3330 | 3342 | 2002-03-26 Fernando Perez <fperez@colorado.edu> |
|
3331 | 3343 | |
|
3332 | 3344 | * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here |
|
3333 | 3345 | and there to fix embedding namespace issues. This should all be |
|
3334 | 3346 | done in a more elegant way. |
|
3335 | 3347 | |
|
3336 | 3348 | 2002-03-25 Fernando Perez <fperez@colorado.edu> |
|
3337 | 3349 | |
|
3338 | 3350 | * IPython/genutils.py (get_home_dir): Try to make it work under |
|
3339 | 3351 | win9x also. |
|
3340 | 3352 | |
|
3341 | 3353 | 2002-03-20 Fernando Perez <fperez@colorado.edu> |
|
3342 | 3354 | |
|
3343 | 3355 | * IPython/Shell.py (IPythonShellEmbed.__init__): leave |
|
3344 | 3356 | sys.displayhook untouched upon __init__. |
|
3345 | 3357 | |
|
3346 | 3358 | 2002-03-19 Fernando Perez <fperez@colorado.edu> |
|
3347 | 3359 | |
|
3348 | 3360 | * Released 0.2.9 (for embedding bug, basically). |
|
3349 | 3361 | |
|
3350 | 3362 | * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit |
|
3351 | 3363 | exceptions so that enclosing shell's state can be restored. |
|
3352 | 3364 | |
|
3353 | 3365 | * Changed magic_gnuplot.py to magic-gnuplot.py to standardize |
|
3354 | 3366 | naming conventions in the .ipython/ dir. |
|
3355 | 3367 | |
|
3356 | 3368 | * IPython/iplib.py (InteractiveShell.init_readline): removed '-' |
|
3357 | 3369 | from delimiters list so filenames with - in them get expanded. |
|
3358 | 3370 | |
|
3359 | 3371 | * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with |
|
3360 | 3372 | sys.displayhook not being properly restored after an embedded call. |
|
3361 | 3373 | |
|
3362 | 3374 | 2002-03-18 Fernando Perez <fperez@colorado.edu> |
|
3363 | 3375 | |
|
3364 | 3376 | * Released 0.2.8 |
|
3365 | 3377 | |
|
3366 | 3378 | * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where |
|
3367 | 3379 | some files weren't being included in a -upgrade. |
|
3368 | 3380 | (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous |
|
3369 | 3381 | on' so that the first tab completes. |
|
3370 | 3382 | (InteractiveShell.handle_magic): fixed bug with spaces around |
|
3371 | 3383 | quotes breaking many magic commands. |
|
3372 | 3384 | |
|
3373 | 3385 | * setup.py: added note about ignoring the syntax error messages at |
|
3374 | 3386 | installation. |
|
3375 | 3387 | |
|
3376 | 3388 | * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished |
|
3377 | 3389 | streamlining the gnuplot interface, now there's only one magic @gp. |
|
3378 | 3390 | |
|
3379 | 3391 | 2002-03-17 Fernando Perez <fperez@colorado.edu> |
|
3380 | 3392 | |
|
3381 | 3393 | * IPython/UserConfig/magic_gnuplot.py: new name for the |
|
3382 | 3394 | example-magic_pm.py file. Much enhanced system, now with a shell |
|
3383 | 3395 | for communicating directly with gnuplot, one command at a time. |
|
3384 | 3396 | |
|
3385 | 3397 | * IPython/Magic.py (Magic.magic_run): added option -n to prevent |
|
3386 | 3398 | setting __name__=='__main__'. |
|
3387 | 3399 | |
|
3388 | 3400 | * IPython/UserConfig/example-magic_pm.py (magic_pm): Added |
|
3389 | 3401 | mini-shell for accessing gnuplot from inside ipython. Should |
|
3390 | 3402 | extend it later for grace access too. Inspired by Arnd's |
|
3391 | 3403 | suggestion. |
|
3392 | 3404 | |
|
3393 | 3405 | * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when |
|
3394 | 3406 | calling magic functions with () in their arguments. Thanks to Arnd |
|
3395 | 3407 | Baecker for pointing this to me. |
|
3396 | 3408 | |
|
3397 | 3409 | * IPython/numutils.py (sum_flat): fixed bug. Would recurse |
|
3398 | 3410 | infinitely for integer or complex arrays (only worked with floats). |
|
3399 | 3411 | |
|
3400 | 3412 | 2002-03-16 Fernando Perez <fperez@colorado.edu> |
|
3401 | 3413 | |
|
3402 | 3414 | * setup.py: Merged setup and setup_windows into a single script |
|
3403 | 3415 | which properly handles things for windows users. |
|
3404 | 3416 | |
|
3405 | 3417 | 2002-03-15 Fernando Perez <fperez@colorado.edu> |
|
3406 | 3418 | |
|
3407 | 3419 | * Big change to the manual: now the magics are all automatically |
|
3408 | 3420 | documented. This information is generated from their docstrings |
|
3409 | 3421 | and put in a latex file included by the manual lyx file. This way |
|
3410 | 3422 | we get always up to date information for the magics. The manual |
|
3411 | 3423 | now also has proper version information, also auto-synced. |
|
3412 | 3424 | |
|
3413 | 3425 | For this to work, an undocumented --magic_docstrings option was added. |
|
3414 | 3426 | |
|
3415 | 3427 | 2002-03-13 Fernando Perez <fperez@colorado.edu> |
|
3416 | 3428 | |
|
3417 | 3429 | * IPython/ultraTB.py (TermColors): fixed problem with dark colors |
|
3418 | 3430 | under CDE terminals. An explicit ;2 color reset is needed in the escapes. |
|
3419 | 3431 | |
|
3420 | 3432 | 2002-03-12 Fernando Perez <fperez@colorado.edu> |
|
3421 | 3433 | |
|
3422 | 3434 | * IPython/ultraTB.py (TermColors): changed color escapes again to |
|
3423 | 3435 | fix the (old, reintroduced) line-wrapping bug. Basically, if |
|
3424 | 3436 | \001..\002 aren't given in the color escapes, lines get wrapped |
|
3425 | 3437 | weirdly. But giving those screws up old xterms and emacs terms. So |
|
3426 | 3438 | I added some logic for emacs terms to be ok, but I can't identify old |
|
3427 | 3439 | xterms separately ($TERM=='xterm' for many terminals, like konsole). |
|
3428 | 3440 | |
|
3429 | 3441 | 2002-03-10 Fernando Perez <fperez@colorado.edu> |
|
3430 | 3442 | |
|
3431 | 3443 | * IPython/usage.py (__doc__): Various documentation cleanups and |
|
3432 | 3444 | updates, both in usage docstrings and in the manual. |
|
3433 | 3445 | |
|
3434 | 3446 | * IPython/Prompts.py (CachedOutput.set_colors): cleanups for |
|
3435 | 3447 | handling of caching. Set minimum acceptabe value for having a |
|
3436 | 3448 | cache at 20 values. |
|
3437 | 3449 | |
|
3438 | 3450 | * IPython/iplib.py (InteractiveShell.user_setup): moved the |
|
3439 | 3451 | install_first_time function to a method, renamed it and added an |
|
3440 | 3452 | 'upgrade' mode. Now people can update their config directory with |
|
3441 | 3453 | a simple command line switch (-upgrade, also new). |
|
3442 | 3454 | |
|
3443 | 3455 | * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to |
|
3444 | 3456 | @file (convenient for automagic users under Python >= 2.2). |
|
3445 | 3457 | Removed @files (it seemed more like a plural than an abbrev. of |
|
3446 | 3458 | 'file show'). |
|
3447 | 3459 | |
|
3448 | 3460 | * IPython/iplib.py (install_first_time): Fixed crash if there were |
|
3449 | 3461 | backup files ('~') in .ipython/ install directory. |
|
3450 | 3462 | |
|
3451 | 3463 | * IPython/ipmaker.py (make_IPython): fixes for new prompt |
|
3452 | 3464 | system. Things look fine, but these changes are fairly |
|
3453 | 3465 | intrusive. Test them for a few days. |
|
3454 | 3466 | |
|
3455 | 3467 | * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of |
|
3456 | 3468 | the prompts system. Now all in/out prompt strings are user |
|
3457 | 3469 | controllable. This is particularly useful for embedding, as one |
|
3458 | 3470 | can tag embedded instances with particular prompts. |
|
3459 | 3471 | |
|
3460 | 3472 | Also removed global use of sys.ps1/2, which now allows nested |
|
3461 | 3473 | embeddings without any problems. Added command-line options for |
|
3462 | 3474 | the prompt strings. |
|
3463 | 3475 | |
|
3464 | 3476 | 2002-03-08 Fernando Perez <fperez@colorado.edu> |
|
3465 | 3477 | |
|
3466 | 3478 | * IPython/UserConfig/example-embed-short.py (ipshell): added |
|
3467 | 3479 | example file with the bare minimum code for embedding. |
|
3468 | 3480 | |
|
3469 | 3481 | * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added |
|
3470 | 3482 | functionality for the embeddable shell to be activated/deactivated |
|
3471 | 3483 | either globally or at each call. |
|
3472 | 3484 | |
|
3473 | 3485 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of |
|
3474 | 3486 | rewriting the prompt with '--->' for auto-inputs with proper |
|
3475 | 3487 | coloring. Now the previous UGLY hack in handle_auto() is gone, and |
|
3476 | 3488 | this is handled by the prompts class itself, as it should. |
|
3477 | 3489 | |
|
3478 | 3490 | 2002-03-05 Fernando Perez <fperez@colorado.edu> |
|
3479 | 3491 | |
|
3480 | 3492 | * IPython/Magic.py (Magic.magic_logstart): Changed @log to |
|
3481 | 3493 | @logstart to avoid name clashes with the math log function. |
|
3482 | 3494 | |
|
3483 | 3495 | * Big updates to X/Emacs section of the manual. |
|
3484 | 3496 | |
|
3485 | 3497 | * Removed ipython_emacs. Milan explained to me how to pass |
|
3486 | 3498 | arguments to ipython through Emacs. Some day I'm going to end up |
|
3487 | 3499 | learning some lisp... |
|
3488 | 3500 | |
|
3489 | 3501 | 2002-03-04 Fernando Perez <fperez@colorado.edu> |
|
3490 | 3502 | |
|
3491 | 3503 | * IPython/ipython_emacs: Created script to be used as the |
|
3492 | 3504 | py-python-command Emacs variable so we can pass IPython |
|
3493 | 3505 | parameters. I can't figure out how to tell Emacs directly to pass |
|
3494 | 3506 | parameters to IPython, so a dummy shell script will do it. |
|
3495 | 3507 | |
|
3496 | 3508 | Other enhancements made for things to work better under Emacs' |
|
3497 | 3509 | various types of terminals. Many thanks to Milan Zamazal |
|
3498 | 3510 | <pdm-AT-zamazal.org> for all the suggestions and pointers. |
|
3499 | 3511 | |
|
3500 | 3512 | 2002-03-01 Fernando Perez <fperez@colorado.edu> |
|
3501 | 3513 | |
|
3502 | 3514 | * IPython/ipmaker.py (make_IPython): added a --readline! option so |
|
3503 | 3515 | that loading of readline is now optional. This gives better |
|
3504 | 3516 | control to emacs users. |
|
3505 | 3517 | |
|
3506 | 3518 | * IPython/ultraTB.py (__date__): Modified color escape sequences |
|
3507 | 3519 | and now things work fine under xterm and in Emacs' term buffers |
|
3508 | 3520 | (though not shell ones). Well, in emacs you get colors, but all |
|
3509 | 3521 | seem to be 'light' colors (no difference between dark and light |
|
3510 | 3522 | ones). But the garbage chars are gone, and also in xterms. It |
|
3511 | 3523 | seems that now I'm using 'cleaner' ansi sequences. |
|
3512 | 3524 | |
|
3513 | 3525 | 2002-02-21 Fernando Perez <fperez@colorado.edu> |
|
3514 | 3526 | |
|
3515 | 3527 | * Released 0.2.7 (mainly to publish the scoping fix). |
|
3516 | 3528 | |
|
3517 | 3529 | * IPython/Logger.py (Logger.logstate): added. A corresponding |
|
3518 | 3530 | @logstate magic was created. |
|
3519 | 3531 | |
|
3520 | 3532 | * IPython/Magic.py: fixed nested scoping problem under Python |
|
3521 | 3533 | 2.1.x (automagic wasn't working). |
|
3522 | 3534 | |
|
3523 | 3535 | 2002-02-20 Fernando Perez <fperez@colorado.edu> |
|
3524 | 3536 | |
|
3525 | 3537 | * Released 0.2.6. |
|
3526 | 3538 | |
|
3527 | 3539 | * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet' |
|
3528 | 3540 | option so that logs can come out without any headers at all. |
|
3529 | 3541 | |
|
3530 | 3542 | * IPython/UserConfig/ipythonrc-scipy.py: created a profile for |
|
3531 | 3543 | SciPy. |
|
3532 | 3544 | |
|
3533 | 3545 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so |
|
3534 | 3546 | that embedded IPython calls don't require vars() to be explicitly |
|
3535 | 3547 | passed. Now they are extracted from the caller's frame (code |
|
3536 | 3548 | snatched from Eric Jones' weave). Added better documentation to |
|
3537 | 3549 | the section on embedding and the example file. |
|
3538 | 3550 | |
|
3539 | 3551 | * IPython/genutils.py (page): Changed so that under emacs, it just |
|
3540 | 3552 | prints the string. You can then page up and down in the emacs |
|
3541 | 3553 | buffer itself. This is how the builtin help() works. |
|
3542 | 3554 | |
|
3543 | 3555 | * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with |
|
3544 | 3556 | macro scoping: macros need to be executed in the user's namespace |
|
3545 | 3557 | to work as if they had been typed by the user. |
|
3546 | 3558 | |
|
3547 | 3559 | * IPython/Magic.py (Magic.magic_macro): Changed macros so they |
|
3548 | 3560 | execute automatically (no need to type 'exec...'). They then |
|
3549 | 3561 | behave like 'true macros'. The printing system was also modified |
|
3550 | 3562 | for this to work. |
|
3551 | 3563 | |
|
3552 | 3564 | 2002-02-19 Fernando Perez <fperez@colorado.edu> |
|
3553 | 3565 | |
|
3554 | 3566 | * IPython/genutils.py (page_file): new function for paging files |
|
3555 | 3567 | in an OS-independent way. Also necessary for file viewing to work |
|
3556 | 3568 | well inside Emacs buffers. |
|
3557 | 3569 | (page): Added checks for being in an emacs buffer. |
|
3558 | 3570 | (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed |
|
3559 | 3571 | same bug in iplib. |
|
3560 | 3572 | |
|
3561 | 3573 | 2002-02-18 Fernando Perez <fperez@colorado.edu> |
|
3562 | 3574 | |
|
3563 | 3575 | * IPython/iplib.py (InteractiveShell.init_readline): modified use |
|
3564 | 3576 | of readline so that IPython can work inside an Emacs buffer. |
|
3565 | 3577 | |
|
3566 | 3578 | * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to |
|
3567 | 3579 | method signatures (they weren't really bugs, but it looks cleaner |
|
3568 | 3580 | and keeps PyChecker happy). |
|
3569 | 3581 | |
|
3570 | 3582 | * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP |
|
3571 | 3583 | for implementing various user-defined hooks. Currently only |
|
3572 | 3584 | display is done. |
|
3573 | 3585 | |
|
3574 | 3586 | * IPython/Prompts.py (CachedOutput._display): changed display |
|
3575 | 3587 | functions so that they can be dynamically changed by users easily. |
|
3576 | 3588 | |
|
3577 | 3589 | * IPython/Extensions/numeric_formats.py (num_display): added an |
|
3578 | 3590 | extension for printing NumPy arrays in flexible manners. It |
|
3579 | 3591 | doesn't do anything yet, but all the structure is in |
|
3580 | 3592 | place. Ultimately the plan is to implement output format control |
|
3581 | 3593 | like in Octave. |
|
3582 | 3594 | |
|
3583 | 3595 | * IPython/Magic.py (Magic.lsmagic): changed so that bound magic |
|
3584 | 3596 | methods are found at run-time by all the automatic machinery. |
|
3585 | 3597 | |
|
3586 | 3598 | 2002-02-17 Fernando Perez <fperez@colorado.edu> |
|
3587 | 3599 | |
|
3588 | 3600 | * setup_Windows.py (make_shortcut): documented. Cleaned up the |
|
3589 | 3601 | whole file a little. |
|
3590 | 3602 | |
|
3591 | 3603 | * ToDo: closed this document. Now there's a new_design.lyx |
|
3592 | 3604 | document for all new ideas. Added making a pdf of it for the |
|
3593 | 3605 | end-user distro. |
|
3594 | 3606 | |
|
3595 | 3607 | * IPython/Logger.py (Logger.switch_log): Created this to replace |
|
3596 | 3608 | logon() and logoff(). It also fixes a nasty crash reported by |
|
3597 | 3609 | Philip Hisley <compsys-AT-starpower.net>. Many thanks to him. |
|
3598 | 3610 | |
|
3599 | 3611 | * IPython/iplib.py (complete): got auto-completion to work with |
|
3600 | 3612 | automagic (I had wanted this for a long time). |
|
3601 | 3613 | |
|
3602 | 3614 | * IPython/Magic.py (Magic.magic_files): Added @files as an alias |
|
3603 | 3615 | to @file, since file() is now a builtin and clashes with automagic |
|
3604 | 3616 | for @file. |
|
3605 | 3617 | |
|
3606 | 3618 | * Made some new files: Prompts, CrashHandler, Magic, Logger. All |
|
3607 | 3619 | of this was previously in iplib, which had grown to more than 2000 |
|
3608 | 3620 | lines, way too long. No new functionality, but it makes managing |
|
3609 | 3621 | the code a bit easier. |
|
3610 | 3622 | |
|
3611 | 3623 | * IPython/iplib.py (IPythonCrashHandler.__call__): Added version |
|
3612 | 3624 | information to crash reports. |
|
3613 | 3625 | |
|
3614 | 3626 | 2002-02-12 Fernando Perez <fperez@colorado.edu> |
|
3615 | 3627 | |
|
3616 | 3628 | * Released 0.2.5. |
|
3617 | 3629 | |
|
3618 | 3630 | 2002-02-11 Fernando Perez <fperez@colorado.edu> |
|
3619 | 3631 | |
|
3620 | 3632 | * Wrote a relatively complete Windows installer. It puts |
|
3621 | 3633 | everything in place, creates Start Menu entries and fixes the |
|
3622 | 3634 | color issues. Nothing fancy, but it works. |
|
3623 | 3635 | |
|
3624 | 3636 | 2002-02-10 Fernando Perez <fperez@colorado.edu> |
|
3625 | 3637 | |
|
3626 | 3638 | * IPython/iplib.py (InteractiveShell.safe_execfile): added an |
|
3627 | 3639 | os.path.expanduser() call so that we can type @run ~/myfile.py and |
|
3628 | 3640 | have thigs work as expected. |
|
3629 | 3641 | |
|
3630 | 3642 | * IPython/genutils.py (page): fixed exception handling so things |
|
3631 | 3643 | work both in Unix and Windows correctly. Quitting a pager triggers |
|
3632 | 3644 | an IOError/broken pipe in Unix, and in windows not finding a pager |
|
3633 | 3645 | is also an IOError, so I had to actually look at the return value |
|
3634 | 3646 | of the exception, not just the exception itself. Should be ok now. |
|
3635 | 3647 | |
|
3636 | 3648 | * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme): |
|
3637 | 3649 | modified to allow case-insensitive color scheme changes. |
|
3638 | 3650 | |
|
3639 | 3651 | 2002-02-09 Fernando Perez <fperez@colorado.edu> |
|
3640 | 3652 | |
|
3641 | 3653 | * IPython/genutils.py (native_line_ends): new function to leave |
|
3642 | 3654 | user config files with os-native line-endings. |
|
3643 | 3655 | |
|
3644 | 3656 | * README and manual updates. |
|
3645 | 3657 | |
|
3646 | 3658 | * IPython/genutils.py: fixed unicode bug: use types.StringTypes |
|
3647 | 3659 | instead of StringType to catch Unicode strings. |
|
3648 | 3660 | |
|
3649 | 3661 | * IPython/genutils.py (filefind): fixed bug for paths with |
|
3650 | 3662 | embedded spaces (very common in Windows). |
|
3651 | 3663 | |
|
3652 | 3664 | * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc |
|
3653 | 3665 | files under Windows, so that they get automatically associated |
|
3654 | 3666 | with a text editor. Windows makes it a pain to handle |
|
3655 | 3667 | extension-less files. |
|
3656 | 3668 | |
|
3657 | 3669 | * IPython/iplib.py (InteractiveShell.init_readline): Made the |
|
3658 | 3670 | warning about readline only occur for Posix. In Windows there's no |
|
3659 | 3671 | way to get readline, so why bother with the warning. |
|
3660 | 3672 | |
|
3661 | 3673 | * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__ |
|
3662 | 3674 | for __str__ instead of dir(self), since dir() changed in 2.2. |
|
3663 | 3675 | |
|
3664 | 3676 | * Ported to Windows! Tested on XP, I suspect it should work fine |
|
3665 | 3677 | on NT/2000, but I don't think it will work on 98 et al. That |
|
3666 | 3678 | series of Windows is such a piece of junk anyway that I won't try |
|
3667 | 3679 | porting it there. The XP port was straightforward, showed a few |
|
3668 | 3680 | bugs here and there (fixed all), in particular some string |
|
3669 | 3681 | handling stuff which required considering Unicode strings (which |
|
3670 | 3682 | Windows uses). This is good, but hasn't been too tested :) No |
|
3671 | 3683 | fancy installer yet, I'll put a note in the manual so people at |
|
3672 | 3684 | least make manually a shortcut. |
|
3673 | 3685 | |
|
3674 | 3686 | * IPython/iplib.py (Magic.magic_colors): Unified the color options |
|
3675 | 3687 | into a single one, "colors". This now controls both prompt and |
|
3676 | 3688 | exception color schemes, and can be changed both at startup |
|
3677 | 3689 | (either via command-line switches or via ipythonrc files) and at |
|
3678 | 3690 | runtime, with @colors. |
|
3679 | 3691 | (Magic.magic_run): renamed @prun to @run and removed the old |
|
3680 | 3692 | @run. The two were too similar to warrant keeping both. |
|
3681 | 3693 | |
|
3682 | 3694 | 2002-02-03 Fernando Perez <fperez@colorado.edu> |
|
3683 | 3695 | |
|
3684 | 3696 | * IPython/iplib.py (install_first_time): Added comment on how to |
|
3685 | 3697 | configure the color options for first-time users. Put a <return> |
|
3686 | 3698 | request at the end so that small-terminal users get a chance to |
|
3687 | 3699 | read the startup info. |
|
3688 | 3700 | |
|
3689 | 3701 | 2002-01-23 Fernando Perez <fperez@colorado.edu> |
|
3690 | 3702 | |
|
3691 | 3703 | * IPython/iplib.py (CachedOutput.update): Changed output memory |
|
3692 | 3704 | variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For |
|
3693 | 3705 | input history we still use _i. Did this b/c these variable are |
|
3694 | 3706 | very commonly used in interactive work, so the less we need to |
|
3695 | 3707 | type the better off we are. |
|
3696 | 3708 | (Magic.magic_prun): updated @prun to better handle the namespaces |
|
3697 | 3709 | the file will run in, including a fix for __name__ not being set |
|
3698 | 3710 | before. |
|
3699 | 3711 | |
|
3700 | 3712 | 2002-01-20 Fernando Perez <fperez@colorado.edu> |
|
3701 | 3713 | |
|
3702 | 3714 | * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of |
|
3703 | 3715 | extra garbage for Python 2.2. Need to look more carefully into |
|
3704 | 3716 | this later. |
|
3705 | 3717 | |
|
3706 | 3718 | 2002-01-19 Fernando Perez <fperez@colorado.edu> |
|
3707 | 3719 | |
|
3708 | 3720 | * IPython/iplib.py (InteractiveShell.showtraceback): fixed to |
|
3709 | 3721 | display SyntaxError exceptions properly formatted when they occur |
|
3710 | 3722 | (they can be triggered by imported code). |
|
3711 | 3723 | |
|
3712 | 3724 | 2002-01-18 Fernando Perez <fperez@colorado.edu> |
|
3713 | 3725 | |
|
3714 | 3726 | * IPython/iplib.py (InteractiveShell.safe_execfile): now |
|
3715 | 3727 | SyntaxError exceptions are reported nicely formatted, instead of |
|
3716 | 3728 | spitting out only offset information as before. |
|
3717 | 3729 | (Magic.magic_prun): Added the @prun function for executing |
|
3718 | 3730 | programs with command line args inside IPython. |
|
3719 | 3731 | |
|
3720 | 3732 | 2002-01-16 Fernando Perez <fperez@colorado.edu> |
|
3721 | 3733 | |
|
3722 | 3734 | * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist |
|
3723 | 3735 | to *not* include the last item given in a range. This brings their |
|
3724 | 3736 | behavior in line with Python's slicing: |
|
3725 | 3737 | a[n1:n2] -> a[n1]...a[n2-1] |
|
3726 | 3738 | It may be a bit less convenient, but I prefer to stick to Python's |
|
3727 | 3739 | conventions *everywhere*, so users never have to wonder. |
|
3728 | 3740 | (Magic.magic_macro): Added @macro function to ease the creation of |
|
3729 | 3741 | macros. |
|
3730 | 3742 | |
|
3731 | 3743 | 2002-01-05 Fernando Perez <fperez@colorado.edu> |
|
3732 | 3744 | |
|
3733 | 3745 | * Released 0.2.4. |
|
3734 | 3746 | |
|
3735 | 3747 | * IPython/iplib.py (Magic.magic_pdef): |
|
3736 | 3748 | (InteractiveShell.safe_execfile): report magic lines and error |
|
3737 | 3749 | lines without line numbers so one can easily copy/paste them for |
|
3738 | 3750 | re-execution. |
|
3739 | 3751 | |
|
3740 | 3752 | * Updated manual with recent changes. |
|
3741 | 3753 | |
|
3742 | 3754 | * IPython/iplib.py (Magic.magic_oinfo): added constructor |
|
3743 | 3755 | docstring printing when class? is called. Very handy for knowing |
|
3744 | 3756 | how to create class instances (as long as __init__ is well |
|
3745 | 3757 | documented, of course :) |
|
3746 | 3758 | (Magic.magic_doc): print both class and constructor docstrings. |
|
3747 | 3759 | (Magic.magic_pdef): give constructor info if passed a class and |
|
3748 | 3760 | __call__ info for callable object instances. |
|
3749 | 3761 | |
|
3750 | 3762 | 2002-01-04 Fernando Perez <fperez@colorado.edu> |
|
3751 | 3763 | |
|
3752 | 3764 | * Made deep_reload() off by default. It doesn't always work |
|
3753 | 3765 | exactly as intended, so it's probably safer to have it off. It's |
|
3754 | 3766 | still available as dreload() anyway, so nothing is lost. |
|
3755 | 3767 | |
|
3756 | 3768 | 2002-01-02 Fernando Perez <fperez@colorado.edu> |
|
3757 | 3769 | |
|
3758 | 3770 | * Released 0.2.3 (contacted R.Singh at CU about biopython course, |
|
3759 | 3771 | so I wanted an updated release). |
|
3760 | 3772 | |
|
3761 | 3773 | 2001-12-27 Fernando Perez <fperez@colorado.edu> |
|
3762 | 3774 | |
|
3763 | 3775 | * IPython/iplib.py (InteractiveShell.interact): Added the original |
|
3764 | 3776 | code from 'code.py' for this module in order to change the |
|
3765 | 3777 | handling of a KeyboardInterrupt. This was necessary b/c otherwise |
|
3766 | 3778 | the history cache would break when the user hit Ctrl-C, and |
|
3767 | 3779 | interact() offers no way to add any hooks to it. |
|
3768 | 3780 | |
|
3769 | 3781 | 2001-12-23 Fernando Perez <fperez@colorado.edu> |
|
3770 | 3782 | |
|
3771 | 3783 | * setup.py: added check for 'MANIFEST' before trying to remove |
|
3772 | 3784 | it. Thanks to Sean Reifschneider. |
|
3773 | 3785 | |
|
3774 | 3786 | 2001-12-22 Fernando Perez <fperez@colorado.edu> |
|
3775 | 3787 | |
|
3776 | 3788 | * Released 0.2.2. |
|
3777 | 3789 | |
|
3778 | 3790 | * Finished (reasonably) writing the manual. Later will add the |
|
3779 | 3791 | python-standard navigation stylesheets, but for the time being |
|
3780 | 3792 | it's fairly complete. Distribution will include html and pdf |
|
3781 | 3793 | versions. |
|
3782 | 3794 | |
|
3783 | 3795 | * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu |
|
3784 | 3796 | (MayaVi author). |
|
3785 | 3797 | |
|
3786 | 3798 | 2001-12-21 Fernando Perez <fperez@colorado.edu> |
|
3787 | 3799 | |
|
3788 | 3800 | * Released 0.2.1. Barring any nasty bugs, this is it as far as a |
|
3789 | 3801 | good public release, I think (with the manual and the distutils |
|
3790 | 3802 | installer). The manual can use some work, but that can go |
|
3791 | 3803 | slowly. Otherwise I think it's quite nice for end users. Next |
|
3792 | 3804 | summer, rewrite the guts of it... |
|
3793 | 3805 | |
|
3794 | 3806 | * Changed format of ipythonrc files to use whitespace as the |
|
3795 | 3807 | separator instead of an explicit '='. Cleaner. |
|
3796 | 3808 | |
|
3797 | 3809 | 2001-12-20 Fernando Perez <fperez@colorado.edu> |
|
3798 | 3810 | |
|
3799 | 3811 | * Started a manual in LyX. For now it's just a quick merge of the |
|
3800 | 3812 | various internal docstrings and READMEs. Later it may grow into a |
|
3801 | 3813 | nice, full-blown manual. |
|
3802 | 3814 | |
|
3803 | 3815 | * Set up a distutils based installer. Installation should now be |
|
3804 | 3816 | trivially simple for end-users. |
|
3805 | 3817 | |
|
3806 | 3818 | 2001-12-11 Fernando Perez <fperez@colorado.edu> |
|
3807 | 3819 | |
|
3808 | 3820 | * Released 0.2.0. First public release, announced it at |
|
3809 | 3821 | comp.lang.python. From now on, just bugfixes... |
|
3810 | 3822 | |
|
3811 | 3823 | * Went through all the files, set copyright/license notices and |
|
3812 | 3824 | cleaned up things. Ready for release. |
|
3813 | 3825 | |
|
3814 | 3826 | 2001-12-10 Fernando Perez <fperez@colorado.edu> |
|
3815 | 3827 | |
|
3816 | 3828 | * Changed the first-time installer not to use tarfiles. It's more |
|
3817 | 3829 | robust now and less unix-dependent. Also makes it easier for |
|
3818 | 3830 | people to later upgrade versions. |
|
3819 | 3831 | |
|
3820 | 3832 | * Changed @exit to @abort to reflect the fact that it's pretty |
|
3821 | 3833 | brutal (a sys.exit()). The difference between @abort and Ctrl-D |
|
3822 | 3834 | becomes significant only when IPyhton is embedded: in that case, |
|
3823 | 3835 | C-D closes IPython only, but @abort kills the enclosing program |
|
3824 | 3836 | too (unless it had called IPython inside a try catching |
|
3825 | 3837 | SystemExit). |
|
3826 | 3838 | |
|
3827 | 3839 | * Created Shell module which exposes the actuall IPython Shell |
|
3828 | 3840 | classes, currently the normal and the embeddable one. This at |
|
3829 | 3841 | least offers a stable interface we won't need to change when |
|
3830 | 3842 | (later) the internals are rewritten. That rewrite will be confined |
|
3831 | 3843 | to iplib and ipmaker, but the Shell interface should remain as is. |
|
3832 | 3844 | |
|
3833 | 3845 | * Added embed module which offers an embeddable IPShell object, |
|
3834 | 3846 | useful to fire up IPython *inside* a running program. Great for |
|
3835 | 3847 | debugging or dynamical data analysis. |
|
3836 | 3848 | |
|
3837 | 3849 | 2001-12-08 Fernando Perez <fperez@colorado.edu> |
|
3838 | 3850 | |
|
3839 | 3851 | * Fixed small bug preventing seeing info from methods of defined |
|
3840 | 3852 | objects (incorrect namespace in _ofind()). |
|
3841 | 3853 | |
|
3842 | 3854 | * Documentation cleanup. Moved the main usage docstrings to a |
|
3843 | 3855 | separate file, usage.py (cleaner to maintain, and hopefully in the |
|
3844 | 3856 | future some perlpod-like way of producing interactive, man and |
|
3845 | 3857 | html docs out of it will be found). |
|
3846 | 3858 | |
|
3847 | 3859 | * Added @profile to see your profile at any time. |
|
3848 | 3860 | |
|
3849 | 3861 | * Added @p as an alias for 'print'. It's especially convenient if |
|
3850 | 3862 | using automagic ('p x' prints x). |
|
3851 | 3863 | |
|
3852 | 3864 | * Small cleanups and fixes after a pychecker run. |
|
3853 | 3865 | |
|
3854 | 3866 | * Changed the @cd command to handle @cd - and @cd -<n> for |
|
3855 | 3867 | visiting any directory in _dh. |
|
3856 | 3868 | |
|
3857 | 3869 | * Introduced _dh, a history of visited directories. @dhist prints |
|
3858 | 3870 | it out with numbers. |
|
3859 | 3871 | |
|
3860 | 3872 | 2001-12-07 Fernando Perez <fperez@colorado.edu> |
|
3861 | 3873 | |
|
3862 | 3874 | * Released 0.1.22 |
|
3863 | 3875 | |
|
3864 | 3876 | * Made initialization a bit more robust against invalid color |
|
3865 | 3877 | options in user input (exit, not traceback-crash). |
|
3866 | 3878 | |
|
3867 | 3879 | * Changed the bug crash reporter to write the report only in the |
|
3868 | 3880 | user's .ipython directory. That way IPython won't litter people's |
|
3869 | 3881 | hard disks with crash files all over the place. Also print on |
|
3870 | 3882 | screen the necessary mail command. |
|
3871 | 3883 | |
|
3872 | 3884 | * With the new ultraTB, implemented LightBG color scheme for light |
|
3873 | 3885 | background terminals. A lot of people like white backgrounds, so I |
|
3874 | 3886 | guess we should at least give them something readable. |
|
3875 | 3887 | |
|
3876 | 3888 | 2001-12-06 Fernando Perez <fperez@colorado.edu> |
|
3877 | 3889 | |
|
3878 | 3890 | * Modified the structure of ultraTB. Now there's a proper class |
|
3879 | 3891 | for tables of color schemes which allow adding schemes easily and |
|
3880 | 3892 | switching the active scheme without creating a new instance every |
|
3881 | 3893 | time (which was ridiculous). The syntax for creating new schemes |
|
3882 | 3894 | is also cleaner. I think ultraTB is finally done, with a clean |
|
3883 | 3895 | class structure. Names are also much cleaner (now there's proper |
|
3884 | 3896 | color tables, no need for every variable to also have 'color' in |
|
3885 | 3897 | its name). |
|
3886 | 3898 | |
|
3887 | 3899 | * Broke down genutils into separate files. Now genutils only |
|
3888 | 3900 | contains utility functions, and classes have been moved to their |
|
3889 | 3901 | own files (they had enough independent functionality to warrant |
|
3890 | 3902 | it): ConfigLoader, OutputTrap, Struct. |
|
3891 | 3903 | |
|
3892 | 3904 | 2001-12-05 Fernando Perez <fperez@colorado.edu> |
|
3893 | 3905 | |
|
3894 | 3906 | * IPython turns 21! Released version 0.1.21, as a candidate for |
|
3895 | 3907 | public consumption. If all goes well, release in a few days. |
|
3896 | 3908 | |
|
3897 | 3909 | * Fixed path bug (files in Extensions/ directory wouldn't be found |
|
3898 | 3910 | unless IPython/ was explicitly in sys.path). |
|
3899 | 3911 | |
|
3900 | 3912 | * Extended the FlexCompleter class as MagicCompleter to allow |
|
3901 | 3913 | completion of @-starting lines. |
|
3902 | 3914 | |
|
3903 | 3915 | * Created __release__.py file as a central repository for release |
|
3904 | 3916 | info that other files can read from. |
|
3905 | 3917 | |
|
3906 | 3918 | * Fixed small bug in logging: when logging was turned on in |
|
3907 | 3919 | mid-session, old lines with special meanings (!@?) were being |
|
3908 | 3920 | logged without the prepended comment, which is necessary since |
|
3909 | 3921 | they are not truly valid python syntax. This should make session |
|
3910 | 3922 | restores produce less errors. |
|
3911 | 3923 | |
|
3912 | 3924 | * The namespace cleanup forced me to make a FlexCompleter class |
|
3913 | 3925 | which is nothing but a ripoff of rlcompleter, but with selectable |
|
3914 | 3926 | namespace (rlcompleter only works in __main__.__dict__). I'll try |
|
3915 | 3927 | to submit a note to the authors to see if this change can be |
|
3916 | 3928 | incorporated in future rlcompleter releases (Dec.6: done) |
|
3917 | 3929 | |
|
3918 | 3930 | * More fixes to namespace handling. It was a mess! Now all |
|
3919 | 3931 | explicit references to __main__.__dict__ are gone (except when |
|
3920 | 3932 | really needed) and everything is handled through the namespace |
|
3921 | 3933 | dicts in the IPython instance. We seem to be getting somewhere |
|
3922 | 3934 | with this, finally... |
|
3923 | 3935 | |
|
3924 | 3936 | * Small documentation updates. |
|
3925 | 3937 | |
|
3926 | 3938 | * Created the Extensions directory under IPython (with an |
|
3927 | 3939 | __init__.py). Put the PhysicalQ stuff there. This directory should |
|
3928 | 3940 | be used for all special-purpose extensions. |
|
3929 | 3941 | |
|
3930 | 3942 | * File renaming: |
|
3931 | 3943 | ipythonlib --> ipmaker |
|
3932 | 3944 | ipplib --> iplib |
|
3933 | 3945 | This makes a bit more sense in terms of what these files actually do. |
|
3934 | 3946 | |
|
3935 | 3947 | * Moved all the classes and functions in ipythonlib to ipplib, so |
|
3936 | 3948 | now ipythonlib only has make_IPython(). This will ease up its |
|
3937 | 3949 | splitting in smaller functional chunks later. |
|
3938 | 3950 | |
|
3939 | 3951 | * Cleaned up (done, I think) output of @whos. Better column |
|
3940 | 3952 | formatting, and now shows str(var) for as much as it can, which is |
|
3941 | 3953 | typically what one gets with a 'print var'. |
|
3942 | 3954 | |
|
3943 | 3955 | 2001-12-04 Fernando Perez <fperez@colorado.edu> |
|
3944 | 3956 | |
|
3945 | 3957 | * Fixed namespace problems. Now builtin/IPyhton/user names get |
|
3946 | 3958 | properly reported in their namespace. Internal namespace handling |
|
3947 | 3959 | is finally getting decent (not perfect yet, but much better than |
|
3948 | 3960 | the ad-hoc mess we had). |
|
3949 | 3961 | |
|
3950 | 3962 | * Removed -exit option. If people just want to run a python |
|
3951 | 3963 | script, that's what the normal interpreter is for. Less |
|
3952 | 3964 | unnecessary options, less chances for bugs. |
|
3953 | 3965 | |
|
3954 | 3966 | * Added a crash handler which generates a complete post-mortem if |
|
3955 | 3967 | IPython crashes. This will help a lot in tracking bugs down the |
|
3956 | 3968 | road. |
|
3957 | 3969 | |
|
3958 | 3970 | * Fixed nasty bug in auto-evaluation part of prefilter(). Names |
|
3959 | 3971 | which were boud to functions being reassigned would bypass the |
|
3960 | 3972 | logger, breaking the sync of _il with the prompt counter. This |
|
3961 | 3973 | would then crash IPython later when a new line was logged. |
|
3962 | 3974 | |
|
3963 | 3975 | 2001-12-02 Fernando Perez <fperez@colorado.edu> |
|
3964 | 3976 | |
|
3965 | 3977 | * Made IPython a package. This means people don't have to clutter |
|
3966 | 3978 | their sys.path with yet another directory. Changed the INSTALL |
|
3967 | 3979 | file accordingly. |
|
3968 | 3980 | |
|
3969 | 3981 | * Cleaned up the output of @who_ls, @who and @whos. @who_ls now |
|
3970 | 3982 | sorts its output (so @who shows it sorted) and @whos formats the |
|
3971 | 3983 | table according to the width of the first column. Nicer, easier to |
|
3972 | 3984 | read. Todo: write a generic table_format() which takes a list of |
|
3973 | 3985 | lists and prints it nicely formatted, with optional row/column |
|
3974 | 3986 | separators and proper padding and justification. |
|
3975 | 3987 | |
|
3976 | 3988 | * Released 0.1.20 |
|
3977 | 3989 | |
|
3978 | 3990 | * Fixed bug in @log which would reverse the inputcache list (a |
|
3979 | 3991 | copy operation was missing). |
|
3980 | 3992 | |
|
3981 | 3993 | * Code cleanup. @config was changed to use page(). Better, since |
|
3982 | 3994 | its output is always quite long. |
|
3983 | 3995 | |
|
3984 | 3996 | * Itpl is back as a dependency. I was having too many problems |
|
3985 | 3997 | getting the parametric aliases to work reliably, and it's just |
|
3986 | 3998 | easier to code weird string operations with it than playing %()s |
|
3987 | 3999 | games. It's only ~6k, so I don't think it's too big a deal. |
|
3988 | 4000 | |
|
3989 | 4001 | * Found (and fixed) a very nasty bug with history. !lines weren't |
|
3990 | 4002 | getting cached, and the out of sync caches would crash |
|
3991 | 4003 | IPython. Fixed it by reorganizing the prefilter/handlers/logger |
|
3992 | 4004 | division of labor a bit better. Bug fixed, cleaner structure. |
|
3993 | 4005 | |
|
3994 | 4006 | 2001-12-01 Fernando Perez <fperez@colorado.edu> |
|
3995 | 4007 | |
|
3996 | 4008 | * Released 0.1.19 |
|
3997 | 4009 | |
|
3998 | 4010 | * Added option -n to @hist to prevent line number printing. Much |
|
3999 | 4011 | easier to copy/paste code this way. |
|
4000 | 4012 | |
|
4001 | 4013 | * Created global _il to hold the input list. Allows easy |
|
4002 | 4014 | re-execution of blocks of code by slicing it (inspired by Janko's |
|
4003 | 4015 | comment on 'macros'). |
|
4004 | 4016 | |
|
4005 | 4017 | * Small fixes and doc updates. |
|
4006 | 4018 | |
|
4007 | 4019 | * Rewrote @history function (was @h). Renamed it to @hist, @h is |
|
4008 | 4020 | much too fragile with automagic. Handles properly multi-line |
|
4009 | 4021 | statements and takes parameters. |
|
4010 | 4022 | |
|
4011 | 4023 | 2001-11-30 Fernando Perez <fperez@colorado.edu> |
|
4012 | 4024 | |
|
4013 | 4025 | * Version 0.1.18 released. |
|
4014 | 4026 | |
|
4015 | 4027 | * Fixed nasty namespace bug in initial module imports. |
|
4016 | 4028 | |
|
4017 | 4029 | * Added copyright/license notes to all code files (except |
|
4018 | 4030 | DPyGetOpt). For the time being, LGPL. That could change. |
|
4019 | 4031 | |
|
4020 | 4032 | * Rewrote a much nicer README, updated INSTALL, cleaned up |
|
4021 | 4033 | ipythonrc-* samples. |
|
4022 | 4034 | |
|
4023 | 4035 | * Overall code/documentation cleanup. Basically ready for |
|
4024 | 4036 | release. Only remaining thing: licence decision (LGPL?). |
|
4025 | 4037 | |
|
4026 | 4038 | * Converted load_config to a class, ConfigLoader. Now recursion |
|
4027 | 4039 | control is better organized. Doesn't include the same file twice. |
|
4028 | 4040 | |
|
4029 | 4041 | 2001-11-29 Fernando Perez <fperez@colorado.edu> |
|
4030 | 4042 | |
|
4031 | 4043 | * Got input history working. Changed output history variables from |
|
4032 | 4044 | _p to _o so that _i is for input and _o for output. Just cleaner |
|
4033 | 4045 | convention. |
|
4034 | 4046 | |
|
4035 | 4047 | * Implemented parametric aliases. This pretty much allows the |
|
4036 | 4048 | alias system to offer full-blown shell convenience, I think. |
|
4037 | 4049 | |
|
4038 | 4050 | * Version 0.1.17 released, 0.1.18 opened. |
|
4039 | 4051 | |
|
4040 | 4052 | * dot_ipython/ipythonrc (alias): added documentation. |
|
4041 | 4053 | (xcolor): Fixed small bug (xcolors -> xcolor) |
|
4042 | 4054 | |
|
4043 | 4055 | * Changed the alias system. Now alias is a magic command to define |
|
4044 | 4056 | aliases just like the shell. Rationale: the builtin magics should |
|
4045 | 4057 | be there for things deeply connected to IPython's |
|
4046 | 4058 | architecture. And this is a much lighter system for what I think |
|
4047 | 4059 | is the really important feature: allowing users to define quickly |
|
4048 | 4060 | magics that will do shell things for them, so they can customize |
|
4049 | 4061 | IPython easily to match their work habits. If someone is really |
|
4050 | 4062 | desperate to have another name for a builtin alias, they can |
|
4051 | 4063 | always use __IP.magic_newname = __IP.magic_oldname. Hackish but |
|
4052 | 4064 | works. |
|
4053 | 4065 | |
|
4054 | 4066 | 2001-11-28 Fernando Perez <fperez@colorado.edu> |
|
4055 | 4067 | |
|
4056 | 4068 | * Changed @file so that it opens the source file at the proper |
|
4057 | 4069 | line. Since it uses less, if your EDITOR environment is |
|
4058 | 4070 | configured, typing v will immediately open your editor of choice |
|
4059 | 4071 | right at the line where the object is defined. Not as quick as |
|
4060 | 4072 | having a direct @edit command, but for all intents and purposes it |
|
4061 | 4073 | works. And I don't have to worry about writing @edit to deal with |
|
4062 | 4074 | all the editors, less does that. |
|
4063 | 4075 | |
|
4064 | 4076 | * Version 0.1.16 released, 0.1.17 opened. |
|
4065 | 4077 | |
|
4066 | 4078 | * Fixed some nasty bugs in the page/page_dumb combo that could |
|
4067 | 4079 | crash IPython. |
|
4068 | 4080 | |
|
4069 | 4081 | 2001-11-27 Fernando Perez <fperez@colorado.edu> |
|
4070 | 4082 | |
|
4071 | 4083 | * Version 0.1.15 released, 0.1.16 opened. |
|
4072 | 4084 | |
|
4073 | 4085 | * Finally got ? and ?? to work for undefined things: now it's |
|
4074 | 4086 | possible to type {}.get? and get information about the get method |
|
4075 | 4087 | of dicts, or os.path? even if only os is defined (so technically |
|
4076 | 4088 | os.path isn't). Works at any level. For example, after import os, |
|
4077 | 4089 | os?, os.path?, os.path.abspath? all work. This is great, took some |
|
4078 | 4090 | work in _ofind. |
|
4079 | 4091 | |
|
4080 | 4092 | * Fixed more bugs with logging. The sanest way to do it was to add |
|
4081 | 4093 | to @log a 'mode' parameter. Killed two in one shot (this mode |
|
4082 | 4094 | option was a request of Janko's). I think it's finally clean |
|
4083 | 4095 | (famous last words). |
|
4084 | 4096 | |
|
4085 | 4097 | * Added a page_dumb() pager which does a decent job of paging on |
|
4086 | 4098 | screen, if better things (like less) aren't available. One less |
|
4087 | 4099 | unix dependency (someday maybe somebody will port this to |
|
4088 | 4100 | windows). |
|
4089 | 4101 | |
|
4090 | 4102 | * Fixed problem in magic_log: would lock of logging out if log |
|
4091 | 4103 | creation failed (because it would still think it had succeeded). |
|
4092 | 4104 | |
|
4093 | 4105 | * Improved the page() function using curses to auto-detect screen |
|
4094 | 4106 | size. Now it can make a much better decision on whether to print |
|
4095 | 4107 | or page a string. Option screen_length was modified: a value 0 |
|
4096 | 4108 | means auto-detect, and that's the default now. |
|
4097 | 4109 | |
|
4098 | 4110 | * Version 0.1.14 released, 0.1.15 opened. I think this is ready to |
|
4099 | 4111 | go out. I'll test it for a few days, then talk to Janko about |
|
4100 | 4112 | licences and announce it. |
|
4101 | 4113 | |
|
4102 | 4114 | * Fixed the length of the auto-generated ---> prompt which appears |
|
4103 | 4115 | for auto-parens and auto-quotes. Getting this right isn't trivial, |
|
4104 | 4116 | with all the color escapes, different prompt types and optional |
|
4105 | 4117 | separators. But it seems to be working in all the combinations. |
|
4106 | 4118 | |
|
4107 | 4119 | 2001-11-26 Fernando Perez <fperez@colorado.edu> |
|
4108 | 4120 | |
|
4109 | 4121 | * Wrote a regexp filter to get option types from the option names |
|
4110 | 4122 | string. This eliminates the need to manually keep two duplicate |
|
4111 | 4123 | lists. |
|
4112 | 4124 | |
|
4113 | 4125 | * Removed the unneeded check_option_names. Now options are handled |
|
4114 | 4126 | in a much saner manner and it's easy to visually check that things |
|
4115 | 4127 | are ok. |
|
4116 | 4128 | |
|
4117 | 4129 | * Updated version numbers on all files I modified to carry a |
|
4118 | 4130 | notice so Janko and Nathan have clear version markers. |
|
4119 | 4131 | |
|
4120 | 4132 | * Updated docstring for ultraTB with my changes. I should send |
|
4121 | 4133 | this to Nathan. |
|
4122 | 4134 | |
|
4123 | 4135 | * Lots of small fixes. Ran everything through pychecker again. |
|
4124 | 4136 | |
|
4125 | 4137 | * Made loading of deep_reload an cmd line option. If it's not too |
|
4126 | 4138 | kosher, now people can just disable it. With -nodeep_reload it's |
|
4127 | 4139 | still available as dreload(), it just won't overwrite reload(). |
|
4128 | 4140 | |
|
4129 | 4141 | * Moved many options to the no| form (-opt and -noopt |
|
4130 | 4142 | accepted). Cleaner. |
|
4131 | 4143 | |
|
4132 | 4144 | * Changed magic_log so that if called with no parameters, it uses |
|
4133 | 4145 | 'rotate' mode. That way auto-generated logs aren't automatically |
|
4134 | 4146 | over-written. For normal logs, now a backup is made if it exists |
|
4135 | 4147 | (only 1 level of backups). A new 'backup' mode was added to the |
|
4136 | 4148 | Logger class to support this. This was a request by Janko. |
|
4137 | 4149 | |
|
4138 | 4150 | * Added @logoff/@logon to stop/restart an active log. |
|
4139 | 4151 | |
|
4140 | 4152 | * Fixed a lot of bugs in log saving/replay. It was pretty |
|
4141 | 4153 | broken. Now special lines (!@,/) appear properly in the command |
|
4142 | 4154 | history after a log replay. |
|
4143 | 4155 | |
|
4144 | 4156 | * Tried and failed to implement full session saving via pickle. My |
|
4145 | 4157 | idea was to pickle __main__.__dict__, but modules can't be |
|
4146 | 4158 | pickled. This would be a better alternative to replaying logs, but |
|
4147 | 4159 | seems quite tricky to get to work. Changed -session to be called |
|
4148 | 4160 | -logplay, which more accurately reflects what it does. And if we |
|
4149 | 4161 | ever get real session saving working, -session is now available. |
|
4150 | 4162 | |
|
4151 | 4163 | * Implemented color schemes for prompts also. As for tracebacks, |
|
4152 | 4164 | currently only NoColor and Linux are supported. But now the |
|
4153 | 4165 | infrastructure is in place, based on a generic ColorScheme |
|
4154 | 4166 | class. So writing and activating new schemes both for the prompts |
|
4155 | 4167 | and the tracebacks should be straightforward. |
|
4156 | 4168 | |
|
4157 | 4169 | * Version 0.1.13 released, 0.1.14 opened. |
|
4158 | 4170 | |
|
4159 | 4171 | * Changed handling of options for output cache. Now counter is |
|
4160 | 4172 | hardwired starting at 1 and one specifies the maximum number of |
|
4161 | 4173 | entries *in the outcache* (not the max prompt counter). This is |
|
4162 | 4174 | much better, since many statements won't increase the cache |
|
4163 | 4175 | count. It also eliminated some confusing options, now there's only |
|
4164 | 4176 | one: cache_size. |
|
4165 | 4177 | |
|
4166 | 4178 | * Added 'alias' magic function and magic_alias option in the |
|
4167 | 4179 | ipythonrc file. Now the user can easily define whatever names he |
|
4168 | 4180 | wants for the magic functions without having to play weird |
|
4169 | 4181 | namespace games. This gives IPython a real shell-like feel. |
|
4170 | 4182 | |
|
4171 | 4183 | * Fixed doc/?/?? for magics. Now all work, in all forms (explicit |
|
4172 | 4184 | @ or not). |
|
4173 | 4185 | |
|
4174 | 4186 | This was one of the last remaining 'visible' bugs (that I know |
|
4175 | 4187 | of). I think if I can clean up the session loading so it works |
|
4176 | 4188 | 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first |
|
4177 | 4189 | about licensing). |
|
4178 | 4190 | |
|
4179 | 4191 | 2001-11-25 Fernando Perez <fperez@colorado.edu> |
|
4180 | 4192 | |
|
4181 | 4193 | * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and |
|
4182 | 4194 | there's a cleaner distinction between what ? and ?? show. |
|
4183 | 4195 | |
|
4184 | 4196 | * Added screen_length option. Now the user can define his own |
|
4185 | 4197 | screen size for page() operations. |
|
4186 | 4198 | |
|
4187 | 4199 | * Implemented magic shell-like functions with automatic code |
|
4188 | 4200 | generation. Now adding another function is just a matter of adding |
|
4189 | 4201 | an entry to a dict, and the function is dynamically generated at |
|
4190 | 4202 | run-time. Python has some really cool features! |
|
4191 | 4203 | |
|
4192 | 4204 | * Renamed many options to cleanup conventions a little. Now all |
|
4193 | 4205 | are lowercase, and only underscores where needed. Also in the code |
|
4194 | 4206 | option name tables are clearer. |
|
4195 | 4207 | |
|
4196 | 4208 | * Changed prompts a little. Now input is 'In [n]:' instead of |
|
4197 | 4209 | 'In[n]:='. This allows it the numbers to be aligned with the |
|
4198 | 4210 | Out[n] numbers, and removes usage of ':=' which doesn't exist in |
|
4199 | 4211 | Python (it was a Mathematica thing). The '...' continuation prompt |
|
4200 | 4212 | was also changed a little to align better. |
|
4201 | 4213 | |
|
4202 | 4214 | * Fixed bug when flushing output cache. Not all _p<n> variables |
|
4203 | 4215 | exist, so their deletion needs to be wrapped in a try: |
|
4204 | 4216 | |
|
4205 | 4217 | * Figured out how to properly use inspect.formatargspec() (it |
|
4206 | 4218 | requires the args preceded by *). So I removed all the code from |
|
4207 | 4219 | _get_pdef in Magic, which was just replicating that. |
|
4208 | 4220 | |
|
4209 | 4221 | * Added test to prefilter to allow redefining magic function names |
|
4210 | 4222 | as variables. This is ok, since the @ form is always available, |
|
4211 | 4223 | but whe should allow the user to define a variable called 'ls' if |
|
4212 | 4224 | he needs it. |
|
4213 | 4225 | |
|
4214 | 4226 | * Moved the ToDo information from README into a separate ToDo. |
|
4215 | 4227 | |
|
4216 | 4228 | * General code cleanup and small bugfixes. I think it's close to a |
|
4217 | 4229 | state where it can be released, obviously with a big 'beta' |
|
4218 | 4230 | warning on it. |
|
4219 | 4231 | |
|
4220 | 4232 | * Got the magic function split to work. Now all magics are defined |
|
4221 | 4233 | in a separate class. It just organizes things a bit, and now |
|
4222 | 4234 | Xemacs behaves nicer (it was choking on InteractiveShell b/c it |
|
4223 | 4235 | was too long). |
|
4224 | 4236 | |
|
4225 | 4237 | * Changed @clear to @reset to avoid potential confusions with |
|
4226 | 4238 | the shell command clear. Also renamed @cl to @clear, which does |
|
4227 | 4239 | exactly what people expect it to from their shell experience. |
|
4228 | 4240 | |
|
4229 | 4241 | Added a check to the @reset command (since it's so |
|
4230 | 4242 | destructive, it's probably a good idea to ask for confirmation). |
|
4231 | 4243 | But now reset only works for full namespace resetting. Since the |
|
4232 | 4244 | del keyword is already there for deleting a few specific |
|
4233 | 4245 | variables, I don't see the point of having a redundant magic |
|
4234 | 4246 | function for the same task. |
|
4235 | 4247 | |
|
4236 | 4248 | 2001-11-24 Fernando Perez <fperez@colorado.edu> |
|
4237 | 4249 | |
|
4238 | 4250 | * Updated the builtin docs (esp. the ? ones). |
|
4239 | 4251 | |
|
4240 | 4252 | * Ran all the code through pychecker. Not terribly impressed with |
|
4241 | 4253 | it: lots of spurious warnings and didn't really find anything of |
|
4242 | 4254 | substance (just a few modules being imported and not used). |
|
4243 | 4255 | |
|
4244 | 4256 | * Implemented the new ultraTB functionality into IPython. New |
|
4245 | 4257 | option: xcolors. This chooses color scheme. xmode now only selects |
|
4246 | 4258 | between Plain and Verbose. Better orthogonality. |
|
4247 | 4259 | |
|
4248 | 4260 | * Large rewrite of ultraTB. Much cleaner now, with a separation of |
|
4249 | 4261 | mode and color scheme for the exception handlers. Now it's |
|
4250 | 4262 | possible to have the verbose traceback with no coloring. |
|
4251 | 4263 | |
|
4252 | 4264 | 2001-11-23 Fernando Perez <fperez@colorado.edu> |
|
4253 | 4265 | |
|
4254 | 4266 | * Version 0.1.12 released, 0.1.13 opened. |
|
4255 | 4267 | |
|
4256 | 4268 | * Removed option to set auto-quote and auto-paren escapes by |
|
4257 | 4269 | user. The chances of breaking valid syntax are just too high. If |
|
4258 | 4270 | someone *really* wants, they can always dig into the code. |
|
4259 | 4271 | |
|
4260 | 4272 | * Made prompt separators configurable. |
|
4261 | 4273 | |
|
4262 | 4274 | 2001-11-22 Fernando Perez <fperez@colorado.edu> |
|
4263 | 4275 | |
|
4264 | 4276 | * Small bugfixes in many places. |
|
4265 | 4277 | |
|
4266 | 4278 | * Removed the MyCompleter class from ipplib. It seemed redundant |
|
4267 | 4279 | with the C-p,C-n history search functionality. Less code to |
|
4268 | 4280 | maintain. |
|
4269 | 4281 | |
|
4270 | 4282 | * Moved all the original ipython.py code into ipythonlib.py. Right |
|
4271 | 4283 | now it's just one big dump into a function called make_IPython, so |
|
4272 | 4284 | no real modularity has been gained. But at least it makes the |
|
4273 | 4285 | wrapper script tiny, and since ipythonlib is a module, it gets |
|
4274 | 4286 | compiled and startup is much faster. |
|
4275 | 4287 | |
|
4276 | 4288 | This is a reasobably 'deep' change, so we should test it for a |
|
4277 | 4289 | while without messing too much more with the code. |
|
4278 | 4290 | |
|
4279 | 4291 | 2001-11-21 Fernando Perez <fperez@colorado.edu> |
|
4280 | 4292 | |
|
4281 | 4293 | * Version 0.1.11 released, 0.1.12 opened for further work. |
|
4282 | 4294 | |
|
4283 | 4295 | * Removed dependency on Itpl. It was only needed in one place. It |
|
4284 | 4296 | would be nice if this became part of python, though. It makes life |
|
4285 | 4297 | *a lot* easier in some cases. |
|
4286 | 4298 | |
|
4287 | 4299 | * Simplified the prefilter code a bit. Now all handlers are |
|
4288 | 4300 | expected to explicitly return a value (at least a blank string). |
|
4289 | 4301 | |
|
4290 | 4302 | * Heavy edits in ipplib. Removed the help system altogether. Now |
|
4291 | 4303 | obj?/?? is used for inspecting objects, a magic @doc prints |
|
4292 | 4304 | docstrings, and full-blown Python help is accessed via the 'help' |
|
4293 | 4305 | keyword. This cleans up a lot of code (less to maintain) and does |
|
4294 | 4306 | the job. Since 'help' is now a standard Python component, might as |
|
4295 | 4307 | well use it and remove duplicate functionality. |
|
4296 | 4308 | |
|
4297 | 4309 | Also removed the option to use ipplib as a standalone program. By |
|
4298 | 4310 | now it's too dependent on other parts of IPython to function alone. |
|
4299 | 4311 | |
|
4300 | 4312 | * Fixed bug in genutils.pager. It would crash if the pager was |
|
4301 | 4313 | exited immediately after opening (broken pipe). |
|
4302 | 4314 | |
|
4303 | 4315 | * Trimmed down the VerboseTB reporting a little. The header is |
|
4304 | 4316 | much shorter now and the repeated exception arguments at the end |
|
4305 | 4317 | have been removed. For interactive use the old header seemed a bit |
|
4306 | 4318 | excessive. |
|
4307 | 4319 | |
|
4308 | 4320 | * Fixed small bug in output of @whos for variables with multi-word |
|
4309 | 4321 | types (only first word was displayed). |
|
4310 | 4322 | |
|
4311 | 4323 | 2001-11-17 Fernando Perez <fperez@colorado.edu> |
|
4312 | 4324 | |
|
4313 | 4325 | * Version 0.1.10 released, 0.1.11 opened for further work. |
|
4314 | 4326 | |
|
4315 | 4327 | * Modified dirs and friends. dirs now *returns* the stack (not |
|
4316 | 4328 | prints), so one can manipulate it as a variable. Convenient to |
|
4317 | 4329 | travel along many directories. |
|
4318 | 4330 | |
|
4319 | 4331 | * Fixed bug in magic_pdef: would only work with functions with |
|
4320 | 4332 | arguments with default values. |
|
4321 | 4333 | |
|
4322 | 4334 | 2001-11-14 Fernando Perez <fperez@colorado.edu> |
|
4323 | 4335 | |
|
4324 | 4336 | * Added the PhysicsInput stuff to dot_ipython so it ships as an |
|
4325 | 4337 | example with IPython. Various other minor fixes and cleanups. |
|
4326 | 4338 | |
|
4327 | 4339 | * Version 0.1.9 released, 0.1.10 opened for further work. |
|
4328 | 4340 | |
|
4329 | 4341 | * Added sys.path to the list of directories searched in the |
|
4330 | 4342 | execfile= option. It used to be the current directory and the |
|
4331 | 4343 | user's IPYTHONDIR only. |
|
4332 | 4344 | |
|
4333 | 4345 | 2001-11-13 Fernando Perez <fperez@colorado.edu> |
|
4334 | 4346 | |
|
4335 | 4347 | * Reinstated the raw_input/prefilter separation that Janko had |
|
4336 | 4348 | initially. This gives a more convenient setup for extending the |
|
4337 | 4349 | pre-processor from the outside: raw_input always gets a string, |
|
4338 | 4350 | and prefilter has to process it. We can then redefine prefilter |
|
4339 | 4351 | from the outside and implement extensions for special |
|
4340 | 4352 | purposes. |
|
4341 | 4353 | |
|
4342 | 4354 | Today I got one for inputting PhysicalQuantity objects |
|
4343 | 4355 | (from Scientific) without needing any function calls at |
|
4344 | 4356 | all. Extremely convenient, and it's all done as a user-level |
|
4345 | 4357 | extension (no IPython code was touched). Now instead of: |
|
4346 | 4358 | a = PhysicalQuantity(4.2,'m/s**2') |
|
4347 | 4359 | one can simply say |
|
4348 | 4360 | a = 4.2 m/s**2 |
|
4349 | 4361 | or even |
|
4350 | 4362 | a = 4.2 m/s^2 |
|
4351 | 4363 | |
|
4352 | 4364 | I use this, but it's also a proof of concept: IPython really is |
|
4353 | 4365 | fully user-extensible, even at the level of the parsing of the |
|
4354 | 4366 | command line. It's not trivial, but it's perfectly doable. |
|
4355 | 4367 | |
|
4356 | 4368 | * Added 'add_flip' method to inclusion conflict resolver. Fixes |
|
4357 | 4369 | the problem of modules being loaded in the inverse order in which |
|
4358 | 4370 | they were defined in |
|
4359 | 4371 | |
|
4360 | 4372 | * Version 0.1.8 released, 0.1.9 opened for further work. |
|
4361 | 4373 | |
|
4362 | 4374 | * Added magics pdef, source and file. They respectively show the |
|
4363 | 4375 | definition line ('prototype' in C), source code and full python |
|
4364 | 4376 | file for any callable object. The object inspector oinfo uses |
|
4365 | 4377 | these to show the same information. |
|
4366 | 4378 | |
|
4367 | 4379 | * Version 0.1.7 released, 0.1.8 opened for further work. |
|
4368 | 4380 | |
|
4369 | 4381 | * Separated all the magic functions into a class called Magic. The |
|
4370 | 4382 | InteractiveShell class was becoming too big for Xemacs to handle |
|
4371 | 4383 | (de-indenting a line would lock it up for 10 seconds while it |
|
4372 | 4384 | backtracked on the whole class!) |
|
4373 | 4385 | |
|
4374 | 4386 | FIXME: didn't work. It can be done, but right now namespaces are |
|
4375 | 4387 | all messed up. Do it later (reverted it for now, so at least |
|
4376 | 4388 | everything works as before). |
|
4377 | 4389 | |
|
4378 | 4390 | * Got the object introspection system (magic_oinfo) working! I |
|
4379 | 4391 | think this is pretty much ready for release to Janko, so he can |
|
4380 | 4392 | test it for a while and then announce it. Pretty much 100% of what |
|
4381 | 4393 | I wanted for the 'phase 1' release is ready. Happy, tired. |
|
4382 | 4394 | |
|
4383 | 4395 | 2001-11-12 Fernando Perez <fperez@colorado.edu> |
|
4384 | 4396 | |
|
4385 | 4397 | * Version 0.1.6 released, 0.1.7 opened for further work. |
|
4386 | 4398 | |
|
4387 | 4399 | * Fixed bug in printing: it used to test for truth before |
|
4388 | 4400 | printing, so 0 wouldn't print. Now checks for None. |
|
4389 | 4401 | |
|
4390 | 4402 | * Fixed bug where auto-execs increase the prompt counter by 2 (b/c |
|
4391 | 4403 | they have to call len(str(sys.ps1)) ). But the fix is ugly, it |
|
4392 | 4404 | reaches by hand into the outputcache. Think of a better way to do |
|
4393 | 4405 | this later. |
|
4394 | 4406 | |
|
4395 | 4407 | * Various small fixes thanks to Nathan's comments. |
|
4396 | 4408 | |
|
4397 | 4409 | * Changed magic_pprint to magic_Pprint. This way it doesn't |
|
4398 | 4410 | collide with pprint() and the name is consistent with the command |
|
4399 | 4411 | line option. |
|
4400 | 4412 | |
|
4401 | 4413 | * Changed prompt counter behavior to be fully like |
|
4402 | 4414 | Mathematica's. That is, even input that doesn't return a result |
|
4403 | 4415 | raises the prompt counter. The old behavior was kind of confusing |
|
4404 | 4416 | (getting the same prompt number several times if the operation |
|
4405 | 4417 | didn't return a result). |
|
4406 | 4418 | |
|
4407 | 4419 | * Fixed Nathan's last name in a couple of places (Gray, not Graham). |
|
4408 | 4420 | |
|
4409 | 4421 | * Fixed -Classic mode (wasn't working anymore). |
|
4410 | 4422 | |
|
4411 | 4423 | * Added colored prompts using Nathan's new code. Colors are |
|
4412 | 4424 | currently hardwired, they can be user-configurable. For |
|
4413 | 4425 | developers, they can be chosen in file ipythonlib.py, at the |
|
4414 | 4426 | beginning of the CachedOutput class def. |
|
4415 | 4427 | |
|
4416 | 4428 | 2001-11-11 Fernando Perez <fperez@colorado.edu> |
|
4417 | 4429 | |
|
4418 | 4430 | * Version 0.1.5 released, 0.1.6 opened for further work. |
|
4419 | 4431 | |
|
4420 | 4432 | * Changed magic_env to *return* the environment as a dict (not to |
|
4421 | 4433 | print it). This way it prints, but it can also be processed. |
|
4422 | 4434 | |
|
4423 | 4435 | * Added Verbose exception reporting to interactive |
|
4424 | 4436 | exceptions. Very nice, now even 1/0 at the prompt gives a verbose |
|
4425 | 4437 | traceback. Had to make some changes to the ultraTB file. This is |
|
4426 | 4438 | probably the last 'big' thing in my mental todo list. This ties |
|
4427 | 4439 | in with the next entry: |
|
4428 | 4440 | |
|
4429 | 4441 | * Changed -Xi and -Xf to a single -xmode option. Now all the user |
|
4430 | 4442 | has to specify is Plain, Color or Verbose for all exception |
|
4431 | 4443 | handling. |
|
4432 | 4444 | |
|
4433 | 4445 | * Removed ShellServices option. All this can really be done via |
|
4434 | 4446 | the magic system. It's easier to extend, cleaner and has automatic |
|
4435 | 4447 | namespace protection and documentation. |
|
4436 | 4448 | |
|
4437 | 4449 | 2001-11-09 Fernando Perez <fperez@colorado.edu> |
|
4438 | 4450 | |
|
4439 | 4451 | * Fixed bug in output cache flushing (missing parameter to |
|
4440 | 4452 | __init__). Other small bugs fixed (found using pychecker). |
|
4441 | 4453 | |
|
4442 | 4454 | * Version 0.1.4 opened for bugfixing. |
|
4443 | 4455 | |
|
4444 | 4456 | 2001-11-07 Fernando Perez <fperez@colorado.edu> |
|
4445 | 4457 | |
|
4446 | 4458 | * Version 0.1.3 released, mainly because of the raw_input bug. |
|
4447 | 4459 | |
|
4448 | 4460 | * Fixed NASTY bug in raw_input: input line wasn't properly parsed |
|
4449 | 4461 | and when testing for whether things were callable, a call could |
|
4450 | 4462 | actually be made to certain functions. They would get called again |
|
4451 | 4463 | once 'really' executed, with a resulting double call. A disaster |
|
4452 | 4464 | in many cases (list.reverse() would never work!). |
|
4453 | 4465 | |
|
4454 | 4466 | * Removed prefilter() function, moved its code to raw_input (which |
|
4455 | 4467 | after all was just a near-empty caller for prefilter). This saves |
|
4456 | 4468 | a function call on every prompt, and simplifies the class a tiny bit. |
|
4457 | 4469 | |
|
4458 | 4470 | * Fix _ip to __ip name in magic example file. |
|
4459 | 4471 | |
|
4460 | 4472 | * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should |
|
4461 | 4473 | work with non-gnu versions of tar. |
|
4462 | 4474 | |
|
4463 | 4475 | 2001-11-06 Fernando Perez <fperez@colorado.edu> |
|
4464 | 4476 | |
|
4465 | 4477 | * Version 0.1.2. Just to keep track of the recent changes. |
|
4466 | 4478 | |
|
4467 | 4479 | * Fixed nasty bug in output prompt routine. It used to check 'if |
|
4468 | 4480 | arg != None...'. Problem is, this fails if arg implements a |
|
4469 | 4481 | special comparison (__cmp__) which disallows comparing to |
|
4470 | 4482 | None. Found it when trying to use the PhysicalQuantity module from |
|
4471 | 4483 | ScientificPython. |
|
4472 | 4484 | |
|
4473 | 4485 | 2001-11-05 Fernando Perez <fperez@colorado.edu> |
|
4474 | 4486 | |
|
4475 | 4487 | * Also added dirs. Now the pushd/popd/dirs family functions |
|
4476 | 4488 | basically like the shell, with the added convenience of going home |
|
4477 | 4489 | when called with no args. |
|
4478 | 4490 | |
|
4479 | 4491 | * pushd/popd slightly modified to mimic shell behavior more |
|
4480 | 4492 | closely. |
|
4481 | 4493 | |
|
4482 | 4494 | * Added env,pushd,popd from ShellServices as magic functions. I |
|
4483 | 4495 | think the cleanest will be to port all desired functions from |
|
4484 | 4496 | ShellServices as magics and remove ShellServices altogether. This |
|
4485 | 4497 | will provide a single, clean way of adding functionality |
|
4486 | 4498 | (shell-type or otherwise) to IP. |
|
4487 | 4499 | |
|
4488 | 4500 | 2001-11-04 Fernando Perez <fperez@colorado.edu> |
|
4489 | 4501 | |
|
4490 | 4502 | * Added .ipython/ directory to sys.path. This way users can keep |
|
4491 | 4503 | customizations there and access them via import. |
|
4492 | 4504 | |
|
4493 | 4505 | 2001-11-03 Fernando Perez <fperez@colorado.edu> |
|
4494 | 4506 | |
|
4495 | 4507 | * Opened version 0.1.1 for new changes. |
|
4496 | 4508 | |
|
4497 | 4509 | * Changed version number to 0.1.0: first 'public' release, sent to |
|
4498 | 4510 | Nathan and Janko. |
|
4499 | 4511 | |
|
4500 | 4512 | * Lots of small fixes and tweaks. |
|
4501 | 4513 | |
|
4502 | 4514 | * Minor changes to whos format. Now strings are shown, snipped if |
|
4503 | 4515 | too long. |
|
4504 | 4516 | |
|
4505 | 4517 | * Changed ShellServices to work on __main__ so they show up in @who |
|
4506 | 4518 | |
|
4507 | 4519 | * Help also works with ? at the end of a line: |
|
4508 | 4520 | ?sin and sin? |
|
4509 | 4521 | both produce the same effect. This is nice, as often I use the |
|
4510 | 4522 | tab-complete to find the name of a method, but I used to then have |
|
4511 | 4523 | to go to the beginning of the line to put a ? if I wanted more |
|
4512 | 4524 | info. Now I can just add the ? and hit return. Convenient. |
|
4513 | 4525 | |
|
4514 | 4526 | 2001-11-02 Fernando Perez <fperez@colorado.edu> |
|
4515 | 4527 | |
|
4516 | 4528 | * Python version check (>=2.1) added. |
|
4517 | 4529 | |
|
4518 | 4530 | * Added LazyPython documentation. At this point the docs are quite |
|
4519 | 4531 | a mess. A cleanup is in order. |
|
4520 | 4532 | |
|
4521 | 4533 | * Auto-installer created. For some bizarre reason, the zipfiles |
|
4522 | 4534 | module isn't working on my system. So I made a tar version |
|
4523 | 4535 | (hopefully the command line options in various systems won't kill |
|
4524 | 4536 | me). |
|
4525 | 4537 | |
|
4526 | 4538 | * Fixes to Struct in genutils. Now all dictionary-like methods are |
|
4527 | 4539 | protected (reasonably). |
|
4528 | 4540 | |
|
4529 | 4541 | * Added pager function to genutils and changed ? to print usage |
|
4530 | 4542 | note through it (it was too long). |
|
4531 | 4543 | |
|
4532 | 4544 | * Added the LazyPython functionality. Works great! I changed the |
|
4533 | 4545 | auto-quote escape to ';', it's on home row and next to '. But |
|
4534 | 4546 | both auto-quote and auto-paren (still /) escapes are command-line |
|
4535 | 4547 | parameters. |
|
4536 | 4548 | |
|
4537 | 4549 | |
|
4538 | 4550 | 2001-11-01 Fernando Perez <fperez@colorado.edu> |
|
4539 | 4551 | |
|
4540 | 4552 | * Version changed to 0.0.7. Fairly large change: configuration now |
|
4541 | 4553 | is all stored in a directory, by default .ipython. There, all |
|
4542 | 4554 | config files have normal looking names (not .names) |
|
4543 | 4555 | |
|
4544 | 4556 | * Version 0.0.6 Released first to Lucas and Archie as a test |
|
4545 | 4557 | run. Since it's the first 'semi-public' release, change version to |
|
4546 | 4558 | > 0.0.6 for any changes now. |
|
4547 | 4559 | |
|
4548 | 4560 | * Stuff I had put in the ipplib.py changelog: |
|
4549 | 4561 | |
|
4550 | 4562 | Changes to InteractiveShell: |
|
4551 | 4563 | |
|
4552 | 4564 | - Made the usage message a parameter. |
|
4553 | 4565 | |
|
4554 | 4566 | - Require the name of the shell variable to be given. It's a bit |
|
4555 | 4567 | of a hack, but allows the name 'shell' not to be hardwire in the |
|
4556 | 4568 | magic (@) handler, which is problematic b/c it requires |
|
4557 | 4569 | polluting the global namespace with 'shell'. This in turn is |
|
4558 | 4570 | fragile: if a user redefines a variable called shell, things |
|
4559 | 4571 | break. |
|
4560 | 4572 | |
|
4561 | 4573 | - magic @: all functions available through @ need to be defined |
|
4562 | 4574 | as magic_<name>, even though they can be called simply as |
|
4563 | 4575 | @<name>. This allows the special command @magic to gather |
|
4564 | 4576 | information automatically about all existing magic functions, |
|
4565 | 4577 | even if they are run-time user extensions, by parsing the shell |
|
4566 | 4578 | instance __dict__ looking for special magic_ names. |
|
4567 | 4579 | |
|
4568 | 4580 | - mainloop: added *two* local namespace parameters. This allows |
|
4569 | 4581 | the class to differentiate between parameters which were there |
|
4570 | 4582 | before and after command line initialization was processed. This |
|
4571 | 4583 | way, later @who can show things loaded at startup by the |
|
4572 | 4584 | user. This trick was necessary to make session saving/reloading |
|
4573 | 4585 | really work: ideally after saving/exiting/reloading a session, |
|
4574 | 4586 | *everythin* should look the same, including the output of @who. I |
|
4575 | 4587 | was only able to make this work with this double namespace |
|
4576 | 4588 | trick. |
|
4577 | 4589 | |
|
4578 | 4590 | - added a header to the logfile which allows (almost) full |
|
4579 | 4591 | session restoring. |
|
4580 | 4592 | |
|
4581 | 4593 | - prepend lines beginning with @ or !, with a and log |
|
4582 | 4594 | them. Why? !lines: may be useful to know what you did @lines: |
|
4583 | 4595 | they may affect session state. So when restoring a session, at |
|
4584 | 4596 | least inform the user of their presence. I couldn't quite get |
|
4585 | 4597 | them to properly re-execute, but at least the user is warned. |
|
4586 | 4598 | |
|
4587 | 4599 | * Started ChangeLog. |
General Comments 0
You need to be logged in to leave comments.
Login now