Show More
The requested changes are too big and content was truncated. Show full diff
@@ -1,2474 +1,2452 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Magic functions for InteractiveShell. |
|
3 | 3 | |
|
4 |
$Id: Magic.py 90 |
|
|
4 | $Id: Magic.py 908 2005-09-26 16:05:48Z 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 os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time |
|
25 | 25 | try: |
|
26 | 26 | import profile,pstats |
|
27 | 27 | except ImportError: |
|
28 | 28 | profile = pstats = None |
|
29 | 29 | from getopt import getopt |
|
30 | 30 | from pprint import pprint, pformat |
|
31 | 31 | from cStringIO import StringIO |
|
32 | 32 | |
|
33 | 33 | # Homebrewed |
|
34 | 34 | from IPython.Struct import Struct |
|
35 | 35 | from IPython.Itpl import Itpl, itpl, printpl,itplns |
|
36 | 36 | from IPython.FakeModule import FakeModule |
|
37 | 37 | from IPython import OInspect |
|
38 | 38 | from IPython.PyColorize import Parser |
|
39 | 39 | from IPython.genutils import * |
|
40 | 40 | |
|
41 | 41 | # Globals to be set later by Magic constructor |
|
42 | 42 | MAGIC_PREFIX = '' |
|
43 | 43 | MAGIC_ESCAPE = '' |
|
44 | 44 | |
|
45 | 45 | #*************************************************************************** |
|
46 | 46 | # Utility functions |
|
47 | 47 | def magic2python(cmd): |
|
48 | 48 | """Convert a command string of magic syntax to valid Python code.""" |
|
49 | 49 | |
|
50 | 50 | if cmd.startswith('#'+MAGIC_ESCAPE) or \ |
|
51 | 51 | cmd.startswith(MAGIC_ESCAPE): |
|
52 | 52 | if cmd[0]=='#': |
|
53 | 53 | cmd = cmd[1:] |
|
54 | 54 | # we need to return the proper line end later |
|
55 | 55 | if cmd[-1] == '\n': |
|
56 | 56 | endl = '\n' |
|
57 | 57 | else: |
|
58 | 58 | endl = '' |
|
59 | 59 | try: |
|
60 | 60 | func,args = cmd[1:].split(' ',1) |
|
61 | 61 | except: |
|
62 | 62 | func,args = cmd[1:].rstrip(),'' |
|
63 | 63 | args = args.replace('"','\\"').replace("'","\\'").rstrip() |
|
64 | 64 | return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl) |
|
65 | 65 | else: |
|
66 | 66 | return cmd |
|
67 | 67 | |
|
68 | 68 | def on_off(tag): |
|
69 | 69 | """Return an ON/OFF string for a 1/0 input. Simple utility function.""" |
|
70 | 70 | return ['OFF','ON'][tag] |
|
71 | 71 | |
|
72 | def get_py_filename(name): | |
|
73 | """Return a valid python filename in the current directory. | |
|
74 | ||
|
75 | If the given name is not a file, it adds '.py' and searches again. | |
|
76 | Raises IOError with an informative message if the file isn't found.""" | |
|
77 | ||
|
78 | name = os.path.expanduser(name) | |
|
79 | if not os.path.isfile(name) and not name.endswith('.py'): | |
|
80 | name += '.py' | |
|
81 | if os.path.isfile(name): | |
|
82 | return name | |
|
83 | else: | |
|
84 | raise IOError,'File `%s` not found.' % name | |
|
85 | ||
|
86 | 72 | |
|
87 | 73 | #**************************************************************************** |
|
88 | 74 | # Utility classes |
|
89 | 75 | class Macro: |
|
90 | 76 | """Simple class to store the value of macros as strings. |
|
91 | 77 | |
|
92 | 78 | This allows us to later exec them by checking when something is an |
|
93 | 79 | instance of this class.""" |
|
94 | 80 | |
|
95 | 81 | def __init__(self,cmds): |
|
96 | 82 | """Build a macro from a list of commands.""" |
|
97 | 83 | |
|
98 | 84 | # Since the list may include multi-line entries, first make sure that |
|
99 | 85 | # they've been all broken up before passing it to magic2python |
|
100 | 86 | cmdlist = map(magic2python,''.join(cmds).split('\n')) |
|
101 | 87 | self.value = '\n'.join(cmdlist) |
|
102 | 88 | |
|
103 | 89 | def __str__(self): |
|
104 | 90 | return self.value |
|
105 | 91 | |
|
106 | 92 | #*************************************************************************** |
|
107 | 93 | # Main class implementing Magic functionality |
|
108 | 94 | class Magic: |
|
109 | 95 | """Magic functions for InteractiveShell. |
|
110 | 96 | |
|
111 | 97 | Shell functions which can be reached as %function_name. All magic |
|
112 | 98 | functions should accept a string, which they can parse for their own |
|
113 | 99 | needs. This can make some functions easier to type, eg `%cd ../` |
|
114 | 100 | vs. `%cd("../")` |
|
115 | 101 | |
|
116 | 102 | ALL definitions MUST begin with the prefix magic_. The user won't need it |
|
117 | 103 | at the command line, but it is is needed in the definition. """ |
|
118 | 104 | |
|
119 | 105 | # class globals |
|
120 | 106 | auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.', |
|
121 | 107 | 'Automagic is ON, % prefix NOT needed for magic functions.'] |
|
122 | 108 | |
|
123 | 109 | #...................................................................... |
|
124 | 110 | # some utility functions |
|
125 | 111 | |
|
126 | 112 | def __init__(self,shell): |
|
127 | 113 | # XXX This is hackish, clean up later to avoid these messy globals |
|
128 | 114 | global MAGIC_PREFIX, MAGIC_ESCAPE |
|
129 | 115 | |
|
130 | 116 | self.options_table = {} |
|
131 | 117 | MAGIC_PREFIX = shell.name+'.magic_' |
|
132 | 118 | MAGIC_ESCAPE = shell.ESC_MAGIC |
|
133 | 119 | if profile is None: |
|
134 | 120 | self.magic_prun = self.profile_missing_notice |
|
135 | 121 | |
|
136 | 122 | def profile_missing_notice(self, *args, **kwargs): |
|
137 | 123 | error("""\ |
|
138 | 124 | The profile module could not be found. If you are a Debian user, |
|
139 | 125 | it has been removed from the standard Debian package because of its non-free |
|
140 | 126 | license. To use profiling, please install"python2.3-profiler" from non-free.""") |
|
141 | 127 | |
|
142 | 128 | def default_option(self,fn,optstr): |
|
143 | 129 | """Make an entry in the options_table for fn, with value optstr""" |
|
144 | 130 | |
|
145 | 131 | if fn not in self.lsmagic(): |
|
146 | 132 | error("%s is not a magic function" % fn) |
|
147 | 133 | self.options_table[fn] = optstr |
|
148 | 134 | |
|
149 | 135 | def lsmagic(self): |
|
150 | 136 | """Return a list of currently available magic functions. |
|
151 | 137 | |
|
152 | 138 | Gives a list of the bare names after mangling (['ls','cd', ...], not |
|
153 | 139 | ['magic_ls','magic_cd',...]""" |
|
154 | 140 | |
|
155 | 141 | # FIXME. This needs a cleanup, in the way the magics list is built. |
|
156 | 142 | |
|
157 | 143 | # magics in class definition |
|
158 | 144 | class_magic = lambda fn: fn.startswith('magic_') and \ |
|
159 | 145 | callable(Magic.__dict__[fn]) |
|
160 | 146 | # in instance namespace (run-time user additions) |
|
161 | 147 | inst_magic = lambda fn: fn.startswith('magic_') and \ |
|
162 | 148 | callable(self.__dict__[fn]) |
|
163 | 149 | # and bound magics by user (so they can access self): |
|
164 | 150 | inst_bound_magic = lambda fn: fn.startswith('magic_') and \ |
|
165 | 151 | callable(self.__class__.__dict__[fn]) |
|
166 | 152 | magics = filter(class_magic,Magic.__dict__.keys()) + \ |
|
167 | 153 | filter(inst_magic,self.__dict__.keys()) + \ |
|
168 | 154 | filter(inst_bound_magic,self.__class__.__dict__.keys()) |
|
169 | 155 | out = [] |
|
170 | 156 | for fn in magics: |
|
171 | 157 | out.append(fn.replace('magic_','',1)) |
|
172 | 158 | out.sort() |
|
173 | 159 | return out |
|
174 | 160 | |
|
175 | 161 | def set_shell(self,shell): |
|
176 | 162 | self.shell = shell |
|
177 | 163 | self.alias_table = shell.alias_table |
|
178 | 164 | |
|
179 | 165 | def extract_input_slices(self,slices): |
|
180 | 166 | """Return as a string a set of input history slices. |
|
181 | 167 | |
|
182 | 168 | The set of slices is given as a list of strings (like ['1','4:8','9'], |
|
183 | 169 | since this function is for use by magic functions which get their |
|
184 | 170 | arguments as strings.""" |
|
185 | 171 | |
|
186 | 172 | cmds = [] |
|
187 | 173 | for chunk in slices: |
|
188 | 174 | if ':' in chunk: |
|
189 | 175 | ini,fin = map(int,chunk.split(':')) |
|
190 | 176 | else: |
|
191 | 177 | ini = int(chunk) |
|
192 | 178 | fin = ini+1 |
|
193 | 179 | cmds.append(self.shell.input_hist[ini:fin]) |
|
194 | 180 | return cmds |
|
195 | 181 | |
|
196 | 182 | def _ofind(self,oname): |
|
197 | 183 | """Find an object in the available namespaces. |
|
198 | 184 | |
|
199 | 185 | self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic |
|
200 | 186 | |
|
201 | 187 | Has special code to detect magic functions. |
|
202 | 188 | """ |
|
203 | 189 | |
|
204 | 190 | oname = oname.strip() |
|
205 | 191 | |
|
206 | 192 | # Namespaces to search in: |
|
207 | 193 | user_ns = self.shell.user_ns |
|
208 | 194 | internal_ns = self.shell.internal_ns |
|
209 | 195 | builtin_ns = __builtin__.__dict__ |
|
210 | 196 | alias_ns = self.shell.alias_table |
|
211 | 197 | |
|
212 | 198 | # Put them in a list. The order is important so that we find things in |
|
213 | 199 | # the same order that Python finds them. |
|
214 | 200 | namespaces = [ ('Interactive',user_ns), |
|
215 | 201 | ('IPython internal',internal_ns), |
|
216 | 202 | ('Python builtin',builtin_ns), |
|
217 | 203 | ('Alias',alias_ns), |
|
218 | 204 | ] |
|
219 | 205 | |
|
220 | 206 | # initialize results to 'null' |
|
221 | 207 | found = 0; obj = None; ospace = None; ds = None; |
|
222 | 208 | ismagic = 0; isalias = 0 |
|
223 | 209 | |
|
224 | 210 | # Look for the given name by splitting it in parts. If the head is |
|
225 | 211 | # found, then we look for all the remaining parts as members, and only |
|
226 | 212 | # declare success if we can find them all. |
|
227 | 213 | oname_parts = oname.split('.') |
|
228 | 214 | oname_head, oname_rest = oname_parts[0],oname_parts[1:] |
|
229 | 215 | for nsname,ns in namespaces: |
|
230 | 216 | try: |
|
231 | 217 | obj = ns[oname_head] |
|
232 | 218 | except KeyError: |
|
233 | 219 | continue |
|
234 | 220 | else: |
|
235 | 221 | for part in oname_rest: |
|
236 | 222 | try: |
|
237 | 223 | obj = getattr(obj,part) |
|
238 | 224 | except: |
|
239 | 225 | # Blanket except b/c some badly implemented objects |
|
240 | 226 | # allow __getattr__ to raise exceptions other than |
|
241 | 227 | # AttributeError, which then crashes IPython. |
|
242 | 228 | break |
|
243 | 229 | else: |
|
244 | 230 | # If we finish the for loop (no break), we got all members |
|
245 | 231 | found = 1 |
|
246 | 232 | ospace = nsname |
|
247 | 233 | if ns == alias_ns: |
|
248 | 234 | isalias = 1 |
|
249 | 235 | break # namespace loop |
|
250 | 236 | |
|
251 | 237 | # Try to see if it's magic |
|
252 | 238 | if not found: |
|
253 | 239 | if oname.startswith(self.shell.ESC_MAGIC): |
|
254 | 240 | oname = oname[1:] |
|
255 | 241 | obj = getattr(self,'magic_'+oname,None) |
|
256 | 242 | if obj is not None: |
|
257 | 243 | found = 1 |
|
258 | 244 | ospace = 'IPython internal' |
|
259 | 245 | ismagic = 1 |
|
260 | 246 | |
|
261 | 247 | # Last try: special-case some literals like '', [], {}, etc: |
|
262 | 248 | if not found and oname_head in ["''",'""','[]','{}','()']: |
|
263 | 249 | obj = eval(oname_head) |
|
264 | 250 | found = 1 |
|
265 | 251 | ospace = 'Interactive' |
|
266 | 252 | |
|
267 | 253 | return {'found':found, 'obj':obj, 'namespace':ospace, |
|
268 | 254 | 'ismagic':ismagic, 'isalias':isalias} |
|
269 | 255 | |
|
270 | 256 | def arg_err(self,func): |
|
271 | 257 | """Print docstring if incorrect arguments were passed""" |
|
272 | 258 | print 'Error in arguments:' |
|
273 | 259 | print OInspect.getdoc(func) |
|
274 | 260 | |
|
275 | 261 | |
|
276 | 262 | def format_latex(self,str): |
|
277 | 263 | """Format a string for latex inclusion.""" |
|
278 | 264 | |
|
279 | 265 | # Characters that need to be escaped for latex: |
|
280 | 266 | escape_re = re.compile(r'(%|_|\$)',re.MULTILINE) |
|
281 | 267 | # Magic command names as headers: |
|
282 | 268 | cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC, |
|
283 | 269 | re.MULTILINE) |
|
284 | 270 | # Magic commands |
|
285 | 271 | cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC, |
|
286 | 272 | re.MULTILINE) |
|
287 | 273 | # Paragraph continue |
|
288 | 274 | par_re = re.compile(r'\\$',re.MULTILINE) |
|
289 | 275 | |
|
290 | 276 | str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str) |
|
291 | 277 | str = cmd_re.sub(r'\\texttt{\g<cmd>}',str) |
|
292 | 278 | str = par_re.sub(r'\\\\',str) |
|
293 | 279 | str = escape_re.sub(r'\\\1',str) |
|
294 | 280 | return str |
|
295 | 281 | |
|
296 | 282 | def format_screen(self,str): |
|
297 | 283 | """Format a string for screen printing. |
|
298 | 284 | |
|
299 | 285 | This removes some latex-type format codes.""" |
|
300 | 286 | # Paragraph continue |
|
301 | 287 | par_re = re.compile(r'\\$',re.MULTILINE) |
|
302 | 288 | str = par_re.sub('',str) |
|
303 | 289 | return str |
|
304 | 290 | |
|
305 | 291 | def parse_options(self,arg_str,opt_str,*long_opts,**kw): |
|
306 | 292 | """Parse options passed to an argument string. |
|
307 | 293 | |
|
308 | 294 | The interface is similar to that of getopt(), but it returns back a |
|
309 | 295 | Struct with the options as keys and the stripped argument string still |
|
310 | 296 | as a string. |
|
311 | 297 | |
|
312 | 298 | arg_str is quoted as a true sys.argv vector by calling on the fly a |
|
313 | 299 | python process in a subshell. This allows us to easily expand |
|
314 | 300 | variables, glob files, quote arguments, etc, with all the power and |
|
315 | 301 | correctness of the underlying system shell. |
|
316 | 302 | |
|
317 | 303 | Options: |
|
318 | 304 | -mode: default 'string'. If given as 'list', the argument string is |
|
319 | 305 | returned as a list (split on whitespace) instead of a string. |
|
320 | 306 | |
|
321 | 307 | -list_all: put all option values in lists. Normally only options |
|
322 | 308 | appearing more than once are put in a list.""" |
|
323 | 309 | |
|
324 | 310 | # inject default options at the beginning of the input line |
|
325 | 311 | caller = sys._getframe(1).f_code.co_name.replace('magic_','') |
|
326 | 312 | arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str) |
|
327 | 313 | |
|
328 | 314 | mode = kw.get('mode','string') |
|
329 | 315 | if mode not in ['string','list']: |
|
330 | 316 | raise ValueError,'incorrect mode given: %s' % mode |
|
331 | 317 | # Get options |
|
332 | 318 | list_all = kw.get('list_all',0) |
|
333 | 319 | |
|
334 | 320 | # Check if we have more than one argument to warrant extra processing: |
|
335 | 321 | odict = {} # Dictionary with options |
|
336 | 322 | args = arg_str.split() |
|
337 | 323 | if len(args) >= 1: |
|
338 | 324 | # If the list of inputs only has 0 or 1 thing in it, there's no |
|
339 | 325 | # need to look for options |
|
340 | 326 | argv = shlex_split(arg_str) |
|
341 | 327 | # Do regular option processing |
|
342 | 328 | opts,args = getopt(argv,opt_str,*long_opts) |
|
343 | 329 | for o,a in opts: |
|
344 | 330 | if o.startswith('--'): |
|
345 | 331 | o = o[2:] |
|
346 | 332 | else: |
|
347 | 333 | o = o[1:] |
|
348 | 334 | try: |
|
349 | 335 | odict[o].append(a) |
|
350 | 336 | except AttributeError: |
|
351 | 337 | odict[o] = [odict[o],a] |
|
352 | 338 | except KeyError: |
|
353 | 339 | if list_all: |
|
354 | 340 | odict[o] = [a] |
|
355 | 341 | else: |
|
356 | 342 | odict[o] = a |
|
357 | 343 | |
|
358 | 344 | # Prepare opts,args for return |
|
359 | 345 | opts = Struct(odict) |
|
360 | 346 | if mode == 'string': |
|
361 | 347 | args = ' '.join(args) |
|
362 | 348 | |
|
363 | 349 | return opts,args |
|
364 | 350 | |
|
365 | 351 | #...................................................................... |
|
366 | 352 | # And now the actual magic functions |
|
367 | 353 | |
|
368 | 354 | # Functions for IPython shell work (vars,funcs, config, etc) |
|
369 | 355 | def magic_lsmagic(self, parameter_s = ''): |
|
370 | 356 | """List currently available magic functions.""" |
|
371 | 357 | mesc = self.shell.ESC_MAGIC |
|
372 | 358 | print 'Available magic functions:\n'+mesc+\ |
|
373 | 359 | (' '+mesc).join(self.lsmagic()) |
|
374 | 360 | print '\n' + Magic.auto_status[self.shell.rc.automagic] |
|
375 | 361 | return None |
|
376 | 362 | |
|
377 | 363 | def magic_magic(self, parameter_s = ''): |
|
378 | 364 | """Print information about the magic function system.""" |
|
379 | 365 | |
|
380 | 366 | mode = '' |
|
381 | 367 | try: |
|
382 | 368 | if parameter_s.split()[0] == '-latex': |
|
383 | 369 | mode = 'latex' |
|
384 | 370 | except: |
|
385 | 371 | pass |
|
386 | 372 | |
|
387 | 373 | magic_docs = [] |
|
388 | 374 | for fname in self.lsmagic(): |
|
389 | 375 | mname = 'magic_' + fname |
|
390 | 376 | for space in (Magic,self,self.__class__): |
|
391 | 377 | try: |
|
392 | 378 | fn = space.__dict__[mname] |
|
393 | 379 | except KeyError: |
|
394 | 380 | pass |
|
395 | 381 | else: |
|
396 | 382 | break |
|
397 | 383 | magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC, |
|
398 | 384 | fname,fn.__doc__)) |
|
399 | 385 | magic_docs = ''.join(magic_docs) |
|
400 | 386 | |
|
401 | 387 | if mode == 'latex': |
|
402 | 388 | print self.format_latex(magic_docs) |
|
403 | 389 | return |
|
404 | 390 | else: |
|
405 | 391 | magic_docs = self.format_screen(magic_docs) |
|
406 | 392 | |
|
407 | 393 | outmsg = """ |
|
408 | 394 | IPython's 'magic' functions |
|
409 | 395 | =========================== |
|
410 | 396 | |
|
411 | 397 | The magic function system provides a series of functions which allow you to |
|
412 | 398 | control the behavior of IPython itself, plus a lot of system-type |
|
413 | 399 | features. All these functions are prefixed with a % character, but parameters |
|
414 | 400 | are given without parentheses or quotes. |
|
415 | 401 | |
|
416 | 402 | NOTE: If you have 'automagic' enabled (via the command line option or with the |
|
417 | 403 | %automagic function), you don't need to type in the % explicitly. By default, |
|
418 | 404 | IPython ships with automagic on, so you should only rarely need the % escape. |
|
419 | 405 | |
|
420 | 406 | Example: typing '%cd mydir' (without the quotes) changes you working directory |
|
421 | 407 | to 'mydir', if it exists. |
|
422 | 408 | |
|
423 | 409 | You can define your own magic functions to extend the system. See the supplied |
|
424 | 410 | ipythonrc and example-magic.py files for details (in your ipython |
|
425 | 411 | configuration directory, typically $HOME/.ipython/). |
|
426 | 412 | |
|
427 | 413 | You can also define your own aliased names for magic functions. In your |
|
428 | 414 | ipythonrc file, placing a line like: |
|
429 | 415 | |
|
430 | 416 | execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile |
|
431 | 417 | |
|
432 | 418 | will define %pf as a new name for %profile. |
|
433 | 419 | |
|
434 | 420 | You can also call magics in code using the ipmagic() function, which IPython |
|
435 | 421 | automatically adds to the builtin namespace. Type 'ipmagic?' for details. |
|
436 | 422 | |
|
437 | 423 | For a list of the available magic functions, use %lsmagic. For a description |
|
438 | 424 | of any of them, type %magic_name?, e.g. '%cd?'. |
|
439 | 425 | |
|
440 | 426 | Currently the magic system has the following functions:\n""" |
|
441 | 427 | |
|
442 | 428 | mesc = self.shell.ESC_MAGIC |
|
443 | 429 | outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):" |
|
444 | 430 | "\n\n%s%s\n\n%s" % (outmsg, |
|
445 | 431 | magic_docs,mesc,mesc, |
|
446 | 432 | (' '+mesc).join(self.lsmagic()), |
|
447 | 433 | Magic.auto_status[self.shell.rc.automagic] ) ) |
|
448 | 434 | |
|
449 | 435 | page(outmsg,screen_lines=self.shell.rc.screen_length) |
|
450 | 436 | |
|
451 | 437 | def magic_automagic(self, parameter_s = ''): |
|
452 | 438 | """Make magic functions callable without having to type the initial %. |
|
453 | 439 | |
|
454 | 440 | Toggles on/off (when off, you must call it as %automagic, of |
|
455 | 441 | course). Note that magic functions have lowest priority, so if there's |
|
456 | 442 | a variable whose name collides with that of a magic fn, automagic |
|
457 | 443 | won't work for that function (you get the variable instead). However, |
|
458 | 444 | if you delete the variable (del var), the previously shadowed magic |
|
459 | 445 | function becomes visible to automagic again.""" |
|
460 | 446 | |
|
461 | 447 | rc = self.shell.rc |
|
462 | 448 | rc.automagic = not rc.automagic |
|
463 | 449 | print '\n' + Magic.auto_status[rc.automagic] |
|
464 | 450 | |
|
465 | 451 | def magic_autocall(self, parameter_s = ''): |
|
466 | 452 | """Make functions callable without having to type parentheses. |
|
467 | 453 | |
|
468 | 454 | This toggles the autocall command line option on and off.""" |
|
469 | 455 | |
|
470 | 456 | rc = self.shell.rc |
|
471 | 457 | rc.autocall = not rc.autocall |
|
472 | 458 | print "Automatic calling is:",['OFF','ON'][rc.autocall] |
|
473 | 459 | |
|
474 | 460 | def magic_autoindent(self, parameter_s = ''): |
|
475 | 461 | """Toggle autoindent on/off (if available).""" |
|
476 | 462 | |
|
477 | 463 | self.shell.set_autoindent() |
|
478 | 464 | print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent] |
|
479 | 465 | |
|
480 | 466 | def magic_system_verbose(self, parameter_s = ''): |
|
481 | 467 | """Toggle verbose printing of system calls on/off.""" |
|
482 | 468 | |
|
483 | 469 | self.shell.rc_set_toggle('system_verbose') |
|
484 | 470 | print "System verbose printing is:",\ |
|
485 | 471 | ['OFF','ON'][self.shell.rc.system_verbose] |
|
486 | 472 | |
|
487 | 473 | def magic_history(self, parameter_s = ''): |
|
488 | 474 | """Print input history (_i<n> variables), with most recent last. |
|
489 | 475 | |
|
490 | 476 | %history [-n] -> print at most 40 inputs (some may be multi-line)\\ |
|
491 | 477 | %history [-n] n -> print at most n inputs\\ |
|
492 | 478 | %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\ |
|
493 | 479 | |
|
494 | 480 | Each input's number <n> is shown, and is accessible as the |
|
495 | 481 | automatically generated variable _i<n>. Multi-line statements are |
|
496 | 482 | printed starting at a new line for easy copy/paste. |
|
497 | 483 | |
|
498 | 484 | If option -n is used, input numbers are not printed. This is useful if |
|
499 | 485 | you want to get a printout of many lines which can be directly pasted |
|
500 | 486 | into a text editor. |
|
501 | 487 | |
|
502 | 488 | This feature is only available if numbered prompts are in use.""" |
|
503 | 489 | |
|
504 | 490 | if not self.do_full_cache: |
|
505 | 491 | print 'This feature is only available if numbered prompts are in use.' |
|
506 | 492 | return |
|
507 | 493 | opts,args = self.parse_options(parameter_s,'n',mode='list') |
|
508 | 494 | |
|
509 | 495 | default_length = 40 |
|
510 | 496 | if len(args) == 0: |
|
511 | 497 | final = self.outputcache.prompt_count |
|
512 | 498 | init = max(1,final-default_length) |
|
513 | 499 | elif len(args) == 1: |
|
514 | 500 | final = self.outputcache.prompt_count |
|
515 | 501 | init = max(1,final-int(args[0])) |
|
516 | 502 | elif len(args) == 2: |
|
517 | 503 | init,final = map(int,args) |
|
518 | 504 | else: |
|
519 | 505 | warn('%hist takes 0, 1 or 2 arguments separated by spaces.') |
|
520 | 506 | print self.magic_hist.__doc__ |
|
521 | 507 | return |
|
522 | 508 | width = len(str(final)) |
|
523 | 509 | line_sep = ['','\n'] |
|
524 | 510 | input_hist = self.shell.input_hist |
|
525 | 511 | print_nums = not opts.has_key('n') |
|
526 | 512 | for in_num in range(init,final): |
|
527 | 513 | inline = input_hist[in_num] |
|
528 | 514 | multiline = inline.count('\n') > 1 |
|
529 | 515 | if print_nums: |
|
530 | 516 | print str(in_num).ljust(width)+':'+ line_sep[multiline], |
|
531 | 517 | if inline.startswith('#'+self.shell.ESC_MAGIC) or \ |
|
532 | 518 | inline.startswith('#!'): |
|
533 | 519 | print inline[1:], |
|
534 | 520 | else: |
|
535 | 521 | print inline, |
|
536 | 522 | |
|
537 | 523 | def magic_hist(self, parameter_s=''): |
|
538 | 524 | """Alternate name for %history.""" |
|
539 | 525 | return self.magic_history(parameter_s) |
|
540 | 526 | |
|
541 | 527 | def magic_p(self, parameter_s=''): |
|
542 | 528 | """Just a short alias for Python's 'print'.""" |
|
543 | 529 | exec 'print ' + parameter_s in self.shell.user_ns |
|
544 | 530 | |
|
545 | 531 | def magic_r(self, parameter_s=''): |
|
546 | 532 | """Repeat previous input. |
|
547 | 533 | |
|
548 | 534 | If given an argument, repeats the previous command which starts with |
|
549 | 535 | the same string, otherwise it just repeats the previous input. |
|
550 | 536 | |
|
551 | 537 | Shell escaped commands (with ! as first character) are not recognized |
|
552 | 538 | by this system, only pure python code and magic commands. |
|
553 | 539 | """ |
|
554 | 540 | |
|
555 | 541 | start = parameter_s.strip() |
|
556 | 542 | esc_magic = self.shell.ESC_MAGIC |
|
557 | 543 | # Identify magic commands even if automagic is on (which means |
|
558 | 544 | # the in-memory version is different from that typed by the user). |
|
559 | 545 | if self.shell.rc.automagic: |
|
560 | 546 | start_magic = esc_magic+start |
|
561 | 547 | else: |
|
562 | 548 | start_magic = start |
|
563 | 549 | # Look through the input history in reverse |
|
564 | 550 | for n in range(len(self.shell.input_hist)-2,0,-1): |
|
565 | 551 | input = self.shell.input_hist[n] |
|
566 | 552 | # skip plain 'r' lines so we don't recurse to infinity |
|
567 | 553 | if input != 'ipmagic("r")\n' and \ |
|
568 | 554 | (input.startswith(start) or input.startswith(start_magic)): |
|
569 | 555 | #print 'match',`input` # dbg |
|
570 | 556 | if input.startswith(esc_magic): |
|
571 | 557 | input = magic2python(input) |
|
572 | 558 | #print 'modified',`input` # dbg |
|
573 | 559 | print 'Executing:',input, |
|
574 | 560 | exec input in self.shell.user_ns |
|
575 | 561 | return |
|
576 | 562 | print 'No previous input matching `%s` found.' % start |
|
577 | 563 | |
|
578 | 564 | def magic_page(self, parameter_s=''): |
|
579 | 565 | """Pretty print the object and display it through a pager. |
|
580 | 566 | |
|
581 | 567 | If no parameter is given, use _ (last output).""" |
|
582 | 568 | # After a function contributed by Olivier Aubert, slightly modified. |
|
583 | 569 | |
|
584 | 570 | oname = parameter_s and parameter_s or '_' |
|
585 | 571 | info = self._ofind(oname) |
|
586 | 572 | if info['found']: |
|
587 | 573 | page(pformat(info['obj'])) |
|
588 | 574 | else: |
|
589 | 575 | print 'Object `%s` not found' % oname |
|
590 | 576 | |
|
591 | 577 | def magic_profile(self, parameter_s=''): |
|
592 | 578 | """Print your currently active IPyhton profile.""" |
|
593 | 579 | if self.shell.rc.profile: |
|
594 | 580 | printpl('Current IPython profile: $self.shell.rc.profile.') |
|
595 | 581 | else: |
|
596 | 582 | print 'No profile active.' |
|
597 | 583 | |
|
598 | 584 | def _inspect(self,meth,oname,**kw): |
|
599 | 585 | """Generic interface to the inspector system. |
|
600 | 586 | |
|
601 | 587 | This function is meant to be called by pdef, pdoc & friends.""" |
|
602 | 588 | |
|
603 | 589 | oname = oname.strip() |
|
604 | 590 | info = Struct(self._ofind(oname)) |
|
605 | 591 | if info.found: |
|
606 | 592 | pmethod = getattr(self.shell.inspector,meth) |
|
607 | 593 | formatter = info.ismagic and self.format_screen or None |
|
608 | 594 | if meth == 'pdoc': |
|
609 | 595 | pmethod(info.obj,oname,formatter) |
|
610 | 596 | elif meth == 'pinfo': |
|
611 | 597 | pmethod(info.obj,oname,formatter,info,**kw) |
|
612 | 598 | else: |
|
613 | 599 | pmethod(info.obj,oname) |
|
614 | 600 | else: |
|
615 | 601 | print 'Object `%s` not found.' % oname |
|
616 | 602 | return 'not found' # so callers can take other action |
|
617 | 603 | |
|
618 | 604 | def magic_pdef(self, parameter_s=''): |
|
619 | 605 | """Print the definition header for any callable object. |
|
620 | 606 | |
|
621 | 607 | If the object is a class, print the constructor information.""" |
|
622 | 608 | self._inspect('pdef',parameter_s) |
|
623 | 609 | |
|
624 | 610 | def magic_pdoc(self, parameter_s=''): |
|
625 | 611 | """Print the docstring for an object. |
|
626 | 612 | |
|
627 | 613 | If the given object is a class, it will print both the class and the |
|
628 | 614 | constructor docstrings.""" |
|
629 | 615 | self._inspect('pdoc',parameter_s) |
|
630 | 616 | |
|
631 | 617 | def magic_psource(self, parameter_s=''): |
|
632 | 618 | """Print (or run through pager) the source code for an object.""" |
|
633 | 619 | self._inspect('psource',parameter_s) |
|
634 | 620 | |
|
635 | 621 | def magic_pfile(self, parameter_s=''): |
|
636 | 622 | """Print (or run through pager) the file where an object is defined. |
|
637 | 623 | |
|
638 | 624 | The file opens at the line where the object definition begins. IPython |
|
639 | 625 | will honor the environment variable PAGER if set, and otherwise will |
|
640 | 626 | do its best to print the file in a convenient form. |
|
641 | 627 | |
|
642 | 628 | If the given argument is not an object currently defined, IPython will |
|
643 | 629 | try to interpret it as a filename (automatically adding a .py extension |
|
644 | 630 | if needed). You can thus use %pfile as a syntax highlighting code |
|
645 | 631 | viewer.""" |
|
646 | 632 | |
|
647 | 633 | # first interpret argument as an object name |
|
648 | 634 | out = self._inspect('pfile',parameter_s) |
|
649 | 635 | # if not, try the input as a filename |
|
650 | 636 | if out == 'not found': |
|
651 | 637 | try: |
|
652 | 638 | filename = get_py_filename(parameter_s) |
|
653 | 639 | except IOError,msg: |
|
654 | 640 | print msg |
|
655 | 641 | return |
|
656 | 642 | page(self.shell.inspector.format(file(filename).read())) |
|
657 | 643 | |
|
658 | 644 | def magic_pinfo(self, parameter_s=''): |
|
659 | 645 | """Provide detailed information about an object. |
|
660 | 646 | |
|
661 | 647 | '%pinfo object' is just a synonym for object? or ?object.""" |
|
662 | 648 | |
|
663 | 649 | #print 'pinfo par: <%s>' % parameter_s # dbg |
|
664 | 650 | |
|
665 | 651 | # detail_level: 0 -> obj? , 1 -> obj?? |
|
666 | 652 | detail_level = 0 |
|
667 | 653 | # We need to detect if we got called as 'pinfo pinfo foo', which can |
|
668 | 654 | # happen if the user types 'pinfo foo?' at the cmd line. |
|
669 | 655 | pinfo,qmark1,oname,qmark2 = \ |
|
670 | 656 | re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups() |
|
671 | 657 | if pinfo or qmark1 or qmark2: |
|
672 | 658 | detail_level = 1 |
|
673 | 659 | self._inspect('pinfo',oname,detail_level=detail_level) |
|
674 | 660 | |
|
675 | 661 | def magic_who_ls(self, parameter_s=''): |
|
676 | 662 | """Return a sorted list of all interactive variables. |
|
677 | 663 | |
|
678 | 664 | If arguments are given, only variables of types matching these |
|
679 | 665 | arguments are returned.""" |
|
680 | 666 | |
|
681 | 667 | user_ns = self.shell.user_ns |
|
682 | 668 | out = [] |
|
683 | 669 | typelist = parameter_s.split() |
|
684 | 670 | for i in self.shell.user_ns.keys(): |
|
685 | 671 | if not (i.startswith('_') or i.startswith('_i')) \ |
|
686 | 672 | and not (self.internal_ns.has_key(i) or |
|
687 | 673 | self.user_config_ns.has_key(i)): |
|
688 | 674 | if typelist: |
|
689 | 675 | if type(user_ns[i]).__name__ in typelist: |
|
690 | 676 | out.append(i) |
|
691 | 677 | else: |
|
692 | 678 | out.append(i) |
|
693 | 679 | out.sort() |
|
694 | 680 | return out |
|
695 | 681 | |
|
696 | 682 | def magic_who(self, parameter_s=''): |
|
697 | 683 | """Print all interactive variables, with some minimal formatting. |
|
698 | 684 | |
|
699 | 685 | If any arguments are given, only variables whose type matches one of |
|
700 | 686 | these are printed. For example: |
|
701 | 687 | |
|
702 | 688 | %who function str |
|
703 | 689 | |
|
704 | 690 | will only list functions and strings, excluding all other types of |
|
705 | 691 | variables. To find the proper type names, simply use type(var) at a |
|
706 | 692 | command line to see how python prints type names. For example: |
|
707 | 693 | |
|
708 | 694 | In [1]: type('hello')\\ |
|
709 | 695 | Out[1]: <type 'str'> |
|
710 | 696 | |
|
711 | 697 | indicates that the type name for strings is 'str'. |
|
712 | 698 | |
|
713 | 699 | %who always excludes executed names loaded through your configuration |
|
714 | 700 | file and things which are internal to IPython. |
|
715 | 701 | |
|
716 | 702 | This is deliberate, as typically you may load many modules and the |
|
717 | 703 | purpose of %who is to show you only what you've manually defined.""" |
|
718 | 704 | |
|
719 | 705 | varlist = self.magic_who_ls(parameter_s) |
|
720 | 706 | if not varlist: |
|
721 | 707 | print 'Interactive namespace is empty.' |
|
722 | 708 | return |
|
723 | 709 | |
|
724 | 710 | # if we have variables, move on... |
|
725 | 711 | |
|
726 | 712 | # stupid flushing problem: when prompts have no separators, stdout is |
|
727 | 713 | # getting lost. I'm starting to think this is a python bug. I'm having |
|
728 | 714 | # to force a flush with a print because even a sys.stdout.flush |
|
729 | 715 | # doesn't seem to do anything! |
|
730 | 716 | |
|
731 | 717 | count = 0 |
|
732 | 718 | for i in varlist: |
|
733 | 719 | print i+'\t', |
|
734 | 720 | count += 1 |
|
735 | 721 | if count > 8: |
|
736 | 722 | count = 0 |
|
737 | 723 | |
|
738 | 724 | sys.stdout.flush() # FIXME. Why the hell isn't this flushing??? |
|
739 | 725 | |
|
740 | 726 | print # well, this does force a flush at the expense of an extra \n |
|
741 | 727 | |
|
742 | 728 | def magic_whos(self, parameter_s=''): |
|
743 | 729 | """Like %who, but gives some extra information about each variable. |
|
744 | 730 | |
|
745 | 731 | The same type filtering of %who can be applied here. |
|
746 | 732 | |
|
747 | 733 | For all variables, the type is printed. Additionally it prints: |
|
748 | 734 | |
|
749 | 735 | - For {},[],(): their length. |
|
750 | 736 | |
|
751 | 737 | - For Numeric arrays, a summary with shape, number of elements, |
|
752 | 738 | typecode and size in memory. |
|
753 | 739 | |
|
754 | 740 | - Everything else: a string representation, snipping their middle if |
|
755 | 741 | too long.""" |
|
756 | 742 | |
|
757 | 743 | varnames = self.magic_who_ls(parameter_s) |
|
758 | 744 | if not varnames: |
|
759 | 745 | print 'Interactive namespace is empty.' |
|
760 | 746 | return |
|
761 | 747 | |
|
762 | 748 | # if we have variables, move on... |
|
763 | 749 | |
|
764 | 750 | # for these types, show len() instead of data: |
|
765 | 751 | seq_types = [types.DictType,types.ListType,types.TupleType] |
|
766 | 752 | |
|
767 | 753 | # for Numeric arrays, display summary info |
|
768 | 754 | try: |
|
769 | 755 | import Numeric |
|
770 | 756 | except ImportError: |
|
771 | 757 | array_type = None |
|
772 | 758 | else: |
|
773 | 759 | array_type = Numeric.ArrayType.__name__ |
|
774 | 760 | |
|
775 | 761 | # Find all variable names and types so we can figure out column sizes |
|
776 | 762 | get_vars = lambda i: self.locals[i] |
|
777 | 763 | type_name = lambda v: type(v).__name__ |
|
778 | 764 | varlist = map(get_vars,varnames) |
|
779 | 765 | typelist = map(type_name,varlist) |
|
780 | 766 | # column labels and # of spaces as separator |
|
781 | 767 | varlabel = 'Variable' |
|
782 | 768 | typelabel = 'Type' |
|
783 | 769 | datalabel = 'Data/Info' |
|
784 | 770 | colsep = 3 |
|
785 | 771 | # variable format strings |
|
786 | 772 | vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)" |
|
787 | 773 | vfmt_short = '$vstr[:25]<...>$vstr[-25:]' |
|
788 | 774 | aformat = "%s: %s elems, type `%s`, %s bytes" |
|
789 | 775 | # find the size of the columns to format the output nicely |
|
790 | 776 | varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep |
|
791 | 777 | typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep |
|
792 | 778 | # table header |
|
793 | 779 | print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \ |
|
794 | 780 | ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1) |
|
795 | 781 | # and the table itself |
|
796 | 782 | kb = 1024 |
|
797 | 783 | Mb = 1048576 # kb**2 |
|
798 | 784 | for vname,var,vtype in zip(varnames,varlist,typelist): |
|
799 | 785 | print itpl(vformat), |
|
800 | 786 | if vtype in seq_types: |
|
801 | 787 | print len(var) |
|
802 | 788 | elif vtype==array_type: |
|
803 | 789 | vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1] |
|
804 | 790 | vsize = Numeric.size(var) |
|
805 | 791 | vbytes = vsize*var.itemsize() |
|
806 | 792 | if vbytes < 100000: |
|
807 | 793 | print aformat % (vshape,vsize,var.typecode(),vbytes) |
|
808 | 794 | else: |
|
809 | 795 | print aformat % (vshape,vsize,var.typecode(),vbytes), |
|
810 | 796 | if vbytes < Mb: |
|
811 | 797 | print '(%s kb)' % (vbytes/kb,) |
|
812 | 798 | else: |
|
813 | 799 | print '(%s Mb)' % (vbytes/Mb,) |
|
814 | 800 | else: |
|
815 | 801 | vstr = str(var) |
|
816 | 802 | if len(vstr) < 50: |
|
817 | 803 | print vstr |
|
818 | 804 | else: |
|
819 | 805 | printpl(vfmt_short) |
|
820 | 806 | |
|
821 | 807 | def magic_reset(self, parameter_s=''): |
|
822 | 808 | """Resets the namespace by removing all names defined by the user. |
|
823 | 809 | |
|
824 | 810 | Input/Output history are left around in case you need them.""" |
|
825 | 811 | |
|
826 | 812 | ans = raw_input( |
|
827 | 813 | "Once deleted, variables cannot be recovered. Proceed (y/n)? ") |
|
828 | 814 | if not ans.lower() == 'y': |
|
829 | 815 | print 'Nothing done.' |
|
830 | 816 | return |
|
831 | 817 | for i in self.magic_who_ls(): |
|
832 | 818 | del(self.locals[i]) |
|
833 | 819 | |
|
834 | 820 | def magic_config(self,parameter_s=''): |
|
835 | 821 | """Show IPython's internal configuration.""" |
|
836 | 822 | |
|
837 | 823 | page('Current configuration structure:\n'+ |
|
838 | 824 | pformat(self.shell.rc.dict())) |
|
839 | 825 | |
|
840 | 826 | def magic_logstart(self,parameter_s=''): |
|
841 | 827 | """Start logging anywhere in a session. |
|
842 | 828 | |
|
843 | 829 | %logstart [log_name [log_mode]] |
|
844 | 830 | |
|
845 | 831 | If no name is given, it defaults to a file named 'ipython.log' in your |
|
846 | 832 | current directory, in 'rotate' mode (see below). |
|
847 | 833 | |
|
848 | 834 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
|
849 | 835 | history up to that point and then continues logging. |
|
850 | 836 | |
|
851 | 837 | %logstart takes a second optional parameter: logging mode. This can be one |
|
852 | 838 | of (note that the modes are given unquoted):\\ |
|
853 | 839 | over: overwrite existing log.\\ |
|
854 | 840 | backup: rename (if exists) to name~ and start name.\\ |
|
855 | 841 | append: well, that says it.\\ |
|
856 | 842 | rotate: create rotating logs name.1~, name.2~, etc. |
|
857 | 843 | """ |
|
858 | 844 | |
|
859 | 845 | #FIXME. This function should all be moved to the Logger class. |
|
860 | 846 | |
|
861 | 847 | valid_modes = qw('over backup append rotate') |
|
862 | 848 | if self.LOG: |
|
863 | 849 | print 'Logging is already in place. Logfile:',self.LOG |
|
864 | 850 | return |
|
865 | 851 | |
|
866 | 852 | par = parameter_s.strip() |
|
867 | 853 | if not par: |
|
868 | 854 | logname = self.LOGDEF |
|
869 | 855 | logmode = 'rotate' # use rotate for the auto-generated logs |
|
870 | 856 | else: |
|
871 | 857 | try: |
|
872 | 858 | logname,logmode = par.split() |
|
873 | 859 | except: |
|
874 | 860 | try: |
|
875 | 861 | logname = par |
|
876 | 862 | logmode = 'backup' |
|
877 | 863 | except: |
|
878 | 864 | warn('Usage: %log [log_name [log_mode]]') |
|
879 | 865 | return |
|
880 | 866 | if not logmode in valid_modes: |
|
881 | 867 | warn('Logging NOT activated.\n' |
|
882 | 868 | 'Usage: %log [log_name [log_mode]]\n' |
|
883 | 869 | 'Valid modes: '+str(valid_modes)) |
|
884 | 870 | return |
|
885 | 871 | |
|
886 | 872 | # If we made it this far, I think we're ok: |
|
887 | 873 | print 'Activating auto-logging.' |
|
888 | 874 | print 'Current session state plus future input saved to:',logname |
|
889 | 875 | print 'Logging mode: ',logmode |
|
890 | 876 | # put logname into rc struct as if it had been called on the command line, |
|
891 | 877 | # so it ends up saved in the log header |
|
892 | 878 | # Save it in case we need to restore it... |
|
893 | 879 | old_logfile = self.shell.rc.opts.get('logfile','') |
|
894 | 880 | logname = os.path.expanduser(logname) |
|
895 | 881 | self.shell.rc.opts.logfile = logname |
|
896 | 882 | self.LOGMODE = logmode # FIXME: this should be set through a function. |
|
897 | 883 | try: |
|
898 | 884 | header = str(self.LOGHEAD) |
|
899 | 885 | self.create_log(header,logname) |
|
900 | 886 | self.logstart(header,logname) |
|
901 | 887 | except: |
|
902 | 888 | self.LOG = '' # we are NOT logging, something went wrong |
|
903 | 889 | self.shell.rc.opts.logfile = old_logfile |
|
904 | 890 | warn("Couldn't start log: "+str(sys.exc_info()[1])) |
|
905 | 891 | else: # log input history up to this point |
|
906 | 892 | self.logfile.write(self.shell.user_ns['_ih'][1:]) |
|
907 | 893 | self.logfile.flush() |
|
908 | 894 | |
|
909 | 895 | def magic_logoff(self,parameter_s=''): |
|
910 | 896 | """Temporarily stop logging. |
|
911 | 897 | |
|
912 | 898 | You must have previously started logging.""" |
|
913 | 899 | self.switch_log(0) |
|
914 | 900 | |
|
915 | 901 | def magic_logon(self,parameter_s=''): |
|
916 | 902 | """Restart logging. |
|
917 | 903 | |
|
918 | 904 | This function is for restarting logging which you've temporarily |
|
919 | 905 | stopped with %logoff. For starting logging for the first time, you |
|
920 | 906 | must use the %logstart function, which allows you to specify an |
|
921 | 907 | optional log filename.""" |
|
922 | 908 | |
|
923 | 909 | self.switch_log(1) |
|
924 | 910 | |
|
925 | 911 | def magic_logstate(self,parameter_s=''): |
|
926 | 912 | """Print the status of the logging system.""" |
|
927 | 913 | |
|
928 | 914 | self.logstate() |
|
929 | 915 | |
|
930 | 916 | def magic_pdb(self, parameter_s=''): |
|
931 | 917 | """Control the calling of the pdb interactive debugger. |
|
932 | 918 | |
|
933 | 919 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
|
934 | 920 | argument it works as a toggle. |
|
935 | 921 | |
|
936 | 922 | When an exception is triggered, IPython can optionally call the |
|
937 | 923 | interactive pdb debugger after the traceback printout. %pdb toggles |
|
938 | 924 | this feature on and off.""" |
|
939 | 925 | |
|
940 | 926 | par = parameter_s.strip().lower() |
|
941 | 927 | |
|
942 | 928 | if par: |
|
943 | 929 | try: |
|
944 | 930 | pdb = {'off':0,'0':0,'on':1,'1':1}[par] |
|
945 | 931 | except KeyError: |
|
946 | 932 | print 'Incorrect argument. Use on/1, off/0 or nothing for a toggle.' |
|
947 | 933 | return |
|
948 | 934 | else: |
|
949 | 935 | self.shell.InteractiveTB.call_pdb = pdb |
|
950 | 936 | else: |
|
951 | 937 | self.shell.InteractiveTB.call_pdb = 1 - self.shell.InteractiveTB.call_pdb |
|
952 | 938 | print 'Automatic pdb calling has been turned',\ |
|
953 | 939 | on_off(self.shell.InteractiveTB.call_pdb) |
|
954 | 940 | |
|
955 | 941 | |
|
956 | 942 | def magic_prun(self, parameter_s ='',user_mode=1, |
|
957 | 943 | opts=None,arg_lst=None,prog_ns=None): |
|
958 | 944 | |
|
959 | 945 | """Run a statement through the python code profiler. |
|
960 | 946 | |
|
961 | 947 | Usage:\\ |
|
962 | 948 | %prun [options] statement |
|
963 | 949 | |
|
964 | 950 | The given statement (which doesn't require quote marks) is run via the |
|
965 | 951 | python profiler in a manner similar to the profile.run() function. |
|
966 | 952 | Namespaces are internally managed to work correctly; profile.run |
|
967 | 953 | cannot be used in IPython because it makes certain assumptions about |
|
968 | 954 | namespaces which do not hold under IPython. |
|
969 | 955 | |
|
970 | 956 | Options: |
|
971 | 957 | |
|
972 | 958 | -l <limit>: you can place restrictions on what or how much of the |
|
973 | 959 | profile gets printed. The limit value can be: |
|
974 | 960 | |
|
975 | 961 | * A string: only information for function names containing this string |
|
976 | 962 | is printed. |
|
977 | 963 | |
|
978 | 964 | * An integer: only these many lines are printed. |
|
979 | 965 | |
|
980 | 966 | * A float (between 0 and 1): this fraction of the report is printed |
|
981 | 967 | (for example, use a limit of 0.4 to see the topmost 40% only). |
|
982 | 968 | |
|
983 | 969 | You can combine several limits with repeated use of the option. For |
|
984 | 970 | example, '-l __init__ -l 5' will print only the topmost 5 lines of |
|
985 | 971 | information about class constructors. |
|
986 | 972 | |
|
987 | 973 | -r: return the pstats.Stats object generated by the profiling. This |
|
988 | 974 | object has all the information about the profile in it, and you can |
|
989 | 975 | later use it for further analysis or in other functions. |
|
990 | 976 | |
|
991 | 977 | Since magic functions have a particular form of calling which prevents |
|
992 | 978 | you from writing something like:\\ |
|
993 | 979 | In [1]: p = %prun -r print 4 # invalid!\\ |
|
994 | 980 | you must instead use IPython's automatic variables to assign this:\\ |
|
995 | 981 | In [1]: %prun -r print 4 \\ |
|
996 | 982 | Out[1]: <pstats.Stats instance at 0x8222cec>\\ |
|
997 | 983 | In [2]: stats = _ |
|
998 | 984 | |
|
999 | 985 | If you really need to assign this value via an explicit function call, |
|
1000 | 986 | you can always tap directly into the true name of the magic function |
|
1001 | 987 | by using the ipmagic function (which IPython automatically adds to the |
|
1002 | 988 | builtins):\\ |
|
1003 | 989 | In [3]: stats = ipmagic('prun','-r print 4') |
|
1004 | 990 | |
|
1005 | 991 | You can type ipmagic? for more details on ipmagic. |
|
1006 | 992 | |
|
1007 | 993 | -s <key>: sort profile by given key. You can provide more than one key |
|
1008 | 994 | by using the option several times: '-s key1 -s key2 -s key3...'. The |
|
1009 | 995 | default sorting key is 'time'. |
|
1010 | 996 | |
|
1011 | 997 | The following is copied verbatim from the profile documentation |
|
1012 | 998 | referenced below: |
|
1013 | 999 | |
|
1014 | 1000 | When more than one key is provided, additional keys are used as |
|
1015 | 1001 | secondary criteria when the there is equality in all keys selected |
|
1016 | 1002 | before them. |
|
1017 | 1003 | |
|
1018 | 1004 | Abbreviations can be used for any key names, as long as the |
|
1019 | 1005 | abbreviation is unambiguous. The following are the keys currently |
|
1020 | 1006 | defined: |
|
1021 | 1007 | |
|
1022 | 1008 | Valid Arg Meaning\\ |
|
1023 | 1009 | "calls" call count\\ |
|
1024 | 1010 | "cumulative" cumulative time\\ |
|
1025 | 1011 | "file" file name\\ |
|
1026 | 1012 | "module" file name\\ |
|
1027 | 1013 | "pcalls" primitive call count\\ |
|
1028 | 1014 | "line" line number\\ |
|
1029 | 1015 | "name" function name\\ |
|
1030 | 1016 | "nfl" name/file/line\\ |
|
1031 | 1017 | "stdname" standard name\\ |
|
1032 | 1018 | "time" internal time |
|
1033 | 1019 | |
|
1034 | 1020 | Note that all sorts on statistics are in descending order (placing |
|
1035 | 1021 | most time consuming items first), where as name, file, and line number |
|
1036 | 1022 | searches are in ascending order (i.e., alphabetical). The subtle |
|
1037 | 1023 | distinction between "nfl" and "stdname" is that the standard name is a |
|
1038 | 1024 | sort of the name as printed, which means that the embedded line |
|
1039 | 1025 | numbers get compared in an odd way. For example, lines 3, 20, and 40 |
|
1040 | 1026 | would (if the file names were the same) appear in the string order |
|
1041 | 1027 | "20" "3" and "40". In contrast, "nfl" does a numeric compare of the |
|
1042 | 1028 | line numbers. In fact, sort_stats("nfl") is the same as |
|
1043 | 1029 | sort_stats("name", "file", "line"). |
|
1044 | 1030 | |
|
1045 | 1031 | -T <filename>: save profile results as shown on screen to a text |
|
1046 | 1032 | file. The profile is still shown on screen. |
|
1047 | 1033 | |
|
1048 | 1034 | -D <filename>: save (via dump_stats) profile statistics to given |
|
1049 | 1035 | filename. This data is in a format understod by the pstats module, and |
|
1050 | 1036 | is generated by a call to the dump_stats() method of profile |
|
1051 | 1037 | objects. The profile is still shown on screen. |
|
1052 | 1038 | |
|
1053 | 1039 | If you want to run complete programs under the profiler's control, use |
|
1054 | 1040 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts |
|
1055 | 1041 | contains profiler specific options as described here. |
|
1056 | 1042 | |
|
1057 | 1043 | You can read the complete documentation for the profile module with:\\ |
|
1058 | 1044 | In [1]: import profile; profile.help() """ |
|
1059 | 1045 | |
|
1060 | 1046 | opts_def = Struct(D=[''],l=[],s=['time'],T=['']) |
|
1061 | 1047 | # protect user quote marks |
|
1062 | 1048 | parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'") |
|
1063 | 1049 | |
|
1064 | 1050 | if user_mode: # regular user call |
|
1065 | 1051 | opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:', |
|
1066 | 1052 | list_all=1) |
|
1067 | 1053 | namespace = self.shell.user_ns |
|
1068 | 1054 | else: # called to run a program by %run -p |
|
1069 | 1055 | try: |
|
1070 | 1056 | filename = get_py_filename(arg_lst[0]) |
|
1071 | 1057 | except IOError,msg: |
|
1072 | 1058 | error(msg) |
|
1073 | 1059 | return |
|
1074 | 1060 | |
|
1075 | 1061 | arg_str = 'execfile(filename,prog_ns)' |
|
1076 | 1062 | namespace = locals() |
|
1077 | 1063 | |
|
1078 | 1064 | opts.merge(opts_def) |
|
1079 | 1065 | |
|
1080 | 1066 | prof = profile.Profile() |
|
1081 | 1067 | try: |
|
1082 | 1068 | prof = prof.runctx(arg_str,namespace,namespace) |
|
1083 | 1069 | sys_exit = '' |
|
1084 | 1070 | except SystemExit: |
|
1085 | 1071 | sys_exit = """*** SystemExit exception caught in code being profiled.""" |
|
1086 | 1072 | |
|
1087 | 1073 | stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s) |
|
1088 | 1074 | |
|
1089 | 1075 | lims = opts.l |
|
1090 | 1076 | if lims: |
|
1091 | 1077 | lims = [] # rebuild lims with ints/floats/strings |
|
1092 | 1078 | for lim in opts.l: |
|
1093 | 1079 | try: |
|
1094 | 1080 | lims.append(int(lim)) |
|
1095 | 1081 | except ValueError: |
|
1096 | 1082 | try: |
|
1097 | 1083 | lims.append(float(lim)) |
|
1098 | 1084 | except ValueError: |
|
1099 | 1085 | lims.append(lim) |
|
1100 | 1086 | |
|
1101 | 1087 | # trap output |
|
1102 | 1088 | sys_stdout = sys.stdout |
|
1103 | 1089 | stdout_trap = StringIO() |
|
1104 | 1090 | try: |
|
1105 | 1091 | sys.stdout = stdout_trap |
|
1106 | 1092 | stats.print_stats(*lims) |
|
1107 | 1093 | finally: |
|
1108 | 1094 | sys.stdout = sys_stdout |
|
1109 | 1095 | output = stdout_trap.getvalue() |
|
1110 | 1096 | output = output.rstrip() |
|
1111 | 1097 | |
|
1112 | 1098 | page(output,screen_lines=self.shell.rc.screen_length) |
|
1113 | 1099 | print sys_exit, |
|
1114 | 1100 | |
|
1115 | 1101 | dump_file = opts.D[0] |
|
1116 | 1102 | text_file = opts.T[0] |
|
1117 | 1103 | if dump_file: |
|
1118 | 1104 | prof.dump_stats(dump_file) |
|
1119 | 1105 | print '\n*** Profile stats marshalled to file',\ |
|
1120 | 1106 | `dump_file`+'.',sys_exit |
|
1121 | 1107 | if text_file: |
|
1122 | 1108 | file(text_file,'w').write(output) |
|
1123 | 1109 | print '\n*** Profile printout saved to text file',\ |
|
1124 | 1110 | `text_file`+'.',sys_exit |
|
1125 | 1111 | |
|
1126 | 1112 | if opts.has_key('r'): |
|
1127 | 1113 | return stats |
|
1128 | 1114 | else: |
|
1129 | 1115 | return None |
|
1130 | 1116 | |
|
1131 | 1117 | def magic_run(self, parameter_s ='',runner=None): |
|
1132 | 1118 | """Run the named file inside IPython as a program. |
|
1133 | 1119 | |
|
1134 | 1120 | Usage:\\ |
|
1135 | 1121 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] |
|
1136 | 1122 | |
|
1137 | 1123 | Parameters after the filename are passed as command-line arguments to |
|
1138 | 1124 | the program (put in sys.argv). Then, control returns to IPython's |
|
1139 | 1125 | prompt. |
|
1140 | 1126 | |
|
1141 | 1127 | This is similar to running at a system prompt:\\ |
|
1142 | 1128 | $ python file args\\ |
|
1143 | 1129 | but with the advantage of giving you IPython's tracebacks, and of |
|
1144 | 1130 | loading all variables into your interactive namespace for further use |
|
1145 | 1131 | (unless -p is used, see below). |
|
1146 | 1132 | |
|
1147 | 1133 | The file is executed in a namespace initially consisting only of |
|
1148 | 1134 | __name__=='__main__' and sys.argv constructed as indicated. It thus |
|
1149 | 1135 | sees its environment as if it were being run as a stand-alone |
|
1150 | 1136 | program. But after execution, the IPython interactive namespace gets |
|
1151 | 1137 | updated with all variables defined in the program (except for __name__ |
|
1152 | 1138 | and sys.argv). This allows for very convenient loading of code for |
|
1153 | 1139 | interactive work, while giving each program a 'clean sheet' to run in. |
|
1154 | 1140 | |
|
1155 | 1141 | Options: |
|
1156 | 1142 | |
|
1157 | 1143 | -n: __name__ is NOT set to '__main__', but to the running file's name |
|
1158 | 1144 | without extension (as python does under import). This allows running |
|
1159 | 1145 | scripts and reloading the definitions in them without calling code |
|
1160 | 1146 | protected by an ' if __name__ == "__main__" ' clause. |
|
1161 | 1147 | |
|
1162 | 1148 | -i: run the file in IPython's namespace instead of an empty one. This |
|
1163 | 1149 | is useful if you are experimenting with code written in a text editor |
|
1164 | 1150 | which depends on variables defined interactively. |
|
1165 | 1151 | |
|
1166 | 1152 | -e: ignore sys.exit() calls or SystemExit exceptions in the script |
|
1167 | 1153 | being run. This is particularly useful if IPython is being used to |
|
1168 | 1154 | run unittests, which always exit with a sys.exit() call. In such |
|
1169 | 1155 | cases you are interested in the output of the test results, not in |
|
1170 | 1156 | seeing a traceback of the unittest module. |
|
1171 | 1157 | |
|
1172 | 1158 | -t: print timing information at the end of the run. IPython will give |
|
1173 | 1159 | you an estimated CPU time consumption for your script, which under |
|
1174 | 1160 | Unix uses the resource module to avoid the wraparound problems of |
|
1175 | 1161 | time.clock(). Under Unix, an estimate of time spent on system tasks |
|
1176 | 1162 | is also given (for Windows platforms this is reported as 0.0). |
|
1177 | 1163 | |
|
1178 | 1164 | If -t is given, an additional -N<N> option can be given, where <N> |
|
1179 | 1165 | must be an integer indicating how many times you want the script to |
|
1180 | 1166 | run. The final timing report will include total and per run results. |
|
1181 | 1167 | |
|
1182 | 1168 | For example (testing the script uniq_stable.py): |
|
1183 | 1169 | |
|
1184 | 1170 | In [1]: run -t uniq_stable |
|
1185 | 1171 | |
|
1186 | 1172 | IPython CPU timings (estimated):\\ |
|
1187 | 1173 | User : 0.19597 s.\\ |
|
1188 | 1174 | System: 0.0 s.\\ |
|
1189 | 1175 | |
|
1190 | 1176 | In [2]: run -t -N5 uniq_stable |
|
1191 | 1177 | |
|
1192 | 1178 | IPython CPU timings (estimated):\\ |
|
1193 | 1179 | Total runs performed: 5\\ |
|
1194 | 1180 | Times : Total Per run\\ |
|
1195 | 1181 | User : 0.910862 s, 0.1821724 s.\\ |
|
1196 | 1182 | System: 0.0 s, 0.0 s. |
|
1197 | 1183 | |
|
1198 | 1184 | -d: run your program under the control of pdb, the Python debugger. |
|
1199 | 1185 | This allows you to execute your program step by step, watch variables, |
|
1200 | 1186 | etc. Internally, what IPython does is similar to calling: |
|
1201 | 1187 | |
|
1202 | 1188 | pdb.run('execfile("YOURFILENAME")') |
|
1203 | 1189 | |
|
1204 | 1190 | with a breakpoint set on line 1 of your file. You can change the line |
|
1205 | 1191 | number for this automatic breakpoint to be <N> by using the -bN option |
|
1206 | 1192 | (where N must be an integer). For example: |
|
1207 | 1193 | |
|
1208 | 1194 | %run -d -b40 myscript |
|
1209 | 1195 | |
|
1210 | 1196 | will set the first breakpoint at line 40 in myscript.py. Note that |
|
1211 | 1197 | the first breakpoint must be set on a line which actually does |
|
1212 | 1198 | something (not a comment or docstring) for it to stop execution. |
|
1213 | 1199 | |
|
1214 | 1200 | When the pdb debugger starts, you will see a (Pdb) prompt. You must |
|
1215 | 1201 | first enter 'c' (without qoutes) to start execution up to the first |
|
1216 | 1202 | breakpoint. |
|
1217 | 1203 | |
|
1218 | 1204 | Entering 'help' gives information about the use of the debugger. You |
|
1219 | 1205 | can easily see pdb's full documentation with "import pdb;pdb.help()" |
|
1220 | 1206 | at a prompt. |
|
1221 | 1207 | |
|
1222 | 1208 | -p: run program under the control of the Python profiler module (which |
|
1223 | 1209 | prints a detailed report of execution times, function calls, etc). |
|
1224 | 1210 | |
|
1225 | 1211 | You can pass other options after -p which affect the behavior of the |
|
1226 | 1212 | profiler itself. See the docs for %prun for details. |
|
1227 | 1213 | |
|
1228 | 1214 | In this mode, the program's variables do NOT propagate back to the |
|
1229 | 1215 | IPython interactive namespace (because they remain in the namespace |
|
1230 | 1216 | where the profiler executes them). |
|
1231 | 1217 | |
|
1232 | 1218 | Internally this triggers a call to %prun, see its documentation for |
|
1233 | 1219 | details on the options available specifically for profiling.""" |
|
1234 | 1220 | |
|
1235 | 1221 | # get arguments and set sys.argv for program to be run. |
|
1236 | 1222 | opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e', |
|
1237 | 1223 | mode='list',list_all=1) |
|
1238 | 1224 | |
|
1239 | 1225 | try: |
|
1240 | 1226 | filename = get_py_filename(arg_lst[0]) |
|
1241 | 1227 | except IndexError: |
|
1242 | 1228 | warn('you must provide at least a filename.') |
|
1243 | 1229 | print '\n%run:\n',OInspect.getdoc(self.magic_run) |
|
1244 | 1230 | return |
|
1245 | 1231 | except IOError,msg: |
|
1246 | 1232 | error(msg) |
|
1247 | 1233 | return |
|
1248 | 1234 | |
|
1249 | 1235 | # Control the response to exit() calls made by the script being run |
|
1250 | 1236 | exit_ignore = opts.has_key('e') |
|
1251 | 1237 | |
|
1252 | 1238 | # Make sure that the running script gets a proper sys.argv as if it |
|
1253 | 1239 | # were run from a system shell. |
|
1254 | 1240 | save_argv = sys.argv # save it for later restoring |
|
1255 | 1241 | sys.argv = [filename]+ arg_lst[1:] # put in the proper filename |
|
1256 | 1242 | |
|
1257 | 1243 | if opts.has_key('i'): |
|
1258 | 1244 | prog_ns = self.shell.user_ns |
|
1259 | 1245 | __name__save = self.shell.user_ns['__name__'] |
|
1260 | 1246 | prog_ns['__name__'] = '__main__' |
|
1261 | 1247 | else: |
|
1262 | 1248 | if opts.has_key('n'): |
|
1263 | 1249 | name = os.path.splitext(os.path.basename(filename))[0] |
|
1264 | 1250 | else: |
|
1265 | 1251 | name = '__main__' |
|
1266 | 1252 | prog_ns = {'__name__':name} |
|
1267 | 1253 | |
|
1268 | 1254 | # pickle fix. See iplib for an explanation |
|
1269 | 1255 | sys.modules[prog_ns['__name__']] = FakeModule(prog_ns) |
|
1270 | 1256 | |
|
1271 | 1257 | stats = None |
|
1272 | 1258 | try: |
|
1273 | 1259 | if opts.has_key('p'): |
|
1274 | 1260 | stats = self.magic_prun('',0,opts,arg_lst,prog_ns) |
|
1275 | 1261 | else: |
|
1276 | 1262 | if opts.has_key('d'): |
|
1277 | 1263 | deb = pdb.Pdb() |
|
1278 | 1264 | # reset Breakpoint state, which is moronically kept |
|
1279 | 1265 | # in a class |
|
1280 | 1266 | bdb.Breakpoint.next = 1 |
|
1281 | 1267 | bdb.Breakpoint.bplist = {} |
|
1282 | 1268 | bdb.Breakpoint.bpbynumber = [None] |
|
1283 | 1269 | # Set an initial breakpoint to stop execution |
|
1284 | 1270 | maxtries = 10 |
|
1285 | 1271 | bp = int(opts.get('b',[1])[0]) |
|
1286 | 1272 | checkline = deb.checkline(filename,bp) |
|
1287 | 1273 | if not checkline: |
|
1288 | 1274 | for bp in range(bp+1,bp+maxtries+1): |
|
1289 | 1275 | if deb.checkline(filename,bp): |
|
1290 | 1276 | break |
|
1291 | 1277 | else: |
|
1292 | 1278 | msg = ("\nI failed to find a valid line to set " |
|
1293 | 1279 | "a breakpoint\n" |
|
1294 | 1280 | "after trying up to line: %s.\n" |
|
1295 | 1281 | "Please set a valid breakpoint manually " |
|
1296 | 1282 | "with the -b option." % bp) |
|
1297 | 1283 | error(msg) |
|
1298 | 1284 | return |
|
1299 | 1285 | # if we find a good linenumber, set the breakpoint |
|
1300 | 1286 | deb.do_break('%s:%s' % (filename,bp)) |
|
1301 | 1287 | # Start file run |
|
1302 | 1288 | print "NOTE: Enter 'c' at the", |
|
1303 | 1289 | print "(Pdb) prompt to start your script." |
|
1304 | 1290 | deb.run('execfile("%s")' % filename,prog_ns) |
|
1305 | 1291 | else: |
|
1306 | 1292 | if runner is None: |
|
1307 | 1293 | runner = self.shell.safe_execfile |
|
1308 | 1294 | if opts.has_key('t'): |
|
1309 | 1295 | try: |
|
1310 | 1296 | nruns = int(opts['N'][0]) |
|
1311 | 1297 | if nruns < 1: |
|
1312 | 1298 | error('Number of runs must be >=1') |
|
1313 | 1299 | return |
|
1314 | 1300 | except (KeyError): |
|
1315 | 1301 | nruns = 1 |
|
1316 | 1302 | if nruns == 1: |
|
1317 | 1303 | t0 = clock2() |
|
1318 | 1304 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1319 | 1305 | t1 = clock2() |
|
1320 | 1306 | t_usr = t1[0]-t0[0] |
|
1321 | 1307 | t_sys = t1[1]-t1[1] |
|
1322 | 1308 | print "\nIPython CPU timings (estimated):" |
|
1323 | 1309 | print " User : %10s s." % t_usr |
|
1324 | 1310 | print " System: %10s s." % t_sys |
|
1325 | 1311 | else: |
|
1326 | 1312 | runs = range(nruns) |
|
1327 | 1313 | t0 = clock2() |
|
1328 | 1314 | for nr in runs: |
|
1329 | 1315 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1330 | 1316 | t1 = clock2() |
|
1331 | 1317 | t_usr = t1[0]-t0[0] |
|
1332 | 1318 | t_sys = t1[1]-t1[1] |
|
1333 | 1319 | print "\nIPython CPU timings (estimated):" |
|
1334 | 1320 | print "Total runs performed:",nruns |
|
1335 | 1321 | print " Times : %10s %10s" % ('Total','Per run') |
|
1336 | 1322 | print " User : %10s s, %10s s." % (t_usr,t_usr/nruns) |
|
1337 | 1323 | print " System: %10s s, %10s s." % (t_sys,t_sys/nruns) |
|
1338 | 1324 | |
|
1339 | 1325 | else: |
|
1340 | 1326 | runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore) |
|
1341 | 1327 | if opts.has_key('i'): |
|
1342 | 1328 | self.shell.user_ns['__name__'] = __name__save |
|
1343 | 1329 | else: |
|
1344 | 1330 | # update IPython interactive namespace |
|
1345 | 1331 | del prog_ns['__name__'] |
|
1346 | 1332 | self.shell.user_ns.update(prog_ns) |
|
1347 | 1333 | finally: |
|
1348 | 1334 | sys.argv = save_argv |
|
1349 | 1335 | return stats |
|
1350 | 1336 | |
|
1351 | 1337 | def magic_runlog(self, parameter_s =''): |
|
1352 | 1338 | """Run files as logs. |
|
1353 | 1339 | |
|
1354 | 1340 | Usage:\\ |
|
1355 | 1341 | %runlog file1 file2 ... |
|
1356 | 1342 | |
|
1357 | 1343 | Run the named files (treating them as log files) in sequence inside |
|
1358 | 1344 | the interpreter, and return to the prompt. This is much slower than |
|
1359 | 1345 | %run because each line is executed in a try/except block, but it |
|
1360 | 1346 | allows running files with syntax errors in them. |
|
1361 | 1347 | |
|
1362 | 1348 | Normally IPython will guess when a file is one of its own logfiles, so |
|
1363 | 1349 | you can typically use %run even for logs. This shorthand allows you to |
|
1364 | 1350 | force any file to be treated as a log file.""" |
|
1365 | 1351 | |
|
1366 | 1352 | for f in parameter_s.split(): |
|
1367 | 1353 | self.shell.safe_execfile(f,self.shell.user_ns, |
|
1368 | 1354 | self.shell.user_ns,islog=1) |
|
1369 | 1355 | |
|
1370 | 1356 | def magic_time(self,parameter_s = ''): |
|
1371 | 1357 | """Time execution of a Python statement or expression. |
|
1372 | 1358 | |
|
1373 | 1359 | The CPU and wall clock times are printed, and the value of the |
|
1374 | 1360 | expression (if any) is returned. Note that under Win32, system time |
|
1375 | 1361 | is always reported as 0, since it can not be measured. |
|
1376 | 1362 | |
|
1377 | 1363 | This function provides very basic timing functionality. In Python |
|
1378 | 1364 | 2.3, the timeit module offers more control and sophistication, but for |
|
1379 | 1365 | now IPython supports Python 2.2, so we can not rely on timeit being |
|
1380 | 1366 | present. |
|
1381 | 1367 | |
|
1382 | 1368 | Some examples: |
|
1383 | 1369 | |
|
1384 | 1370 | In [1]: time 2**128 |
|
1385 | 1371 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
1386 | 1372 | Wall time: 0.00 |
|
1387 | 1373 | Out[1]: 340282366920938463463374607431768211456L |
|
1388 | 1374 | |
|
1389 | 1375 | In [2]: n = 1000000 |
|
1390 | 1376 | |
|
1391 | 1377 | In [3]: time sum(range(n)) |
|
1392 | 1378 | CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s |
|
1393 | 1379 | Wall time: 1.37 |
|
1394 | 1380 | Out[3]: 499999500000L |
|
1395 | 1381 | |
|
1396 | 1382 | In [4]: time print 'hello world' |
|
1397 | 1383 | hello world |
|
1398 | 1384 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
1399 | 1385 | Wall time: 0.00 |
|
1400 | 1386 | """ |
|
1401 | 1387 | |
|
1402 | 1388 | # fail immediately if the given expression can't be compiled |
|
1403 | 1389 | try: |
|
1404 | 1390 | mode = 'eval' |
|
1405 | 1391 | code = compile(parameter_s,'<timed eval>',mode) |
|
1406 | 1392 | except SyntaxError: |
|
1407 | 1393 | mode = 'exec' |
|
1408 | 1394 | code = compile(parameter_s,'<timed exec>',mode) |
|
1409 | 1395 | # skew measurement as little as possible |
|
1410 | 1396 | glob = self.shell.user_ns |
|
1411 | 1397 | clk = clock2 |
|
1412 | 1398 | wtime = time.time |
|
1413 | 1399 | # time execution |
|
1414 | 1400 | wall_st = wtime() |
|
1415 | 1401 | if mode=='eval': |
|
1416 | 1402 | st = clk() |
|
1417 | 1403 | out = eval(code,glob) |
|
1418 | 1404 | end = clk() |
|
1419 | 1405 | else: |
|
1420 | 1406 | st = clk() |
|
1421 | 1407 | exec code in glob |
|
1422 | 1408 | end = clk() |
|
1423 | 1409 | out = None |
|
1424 | 1410 | wall_end = wtime() |
|
1425 | 1411 | # Compute actual times and report |
|
1426 | 1412 | wall_time = wall_end-wall_st |
|
1427 | 1413 | cpu_user = end[0]-st[0] |
|
1428 | 1414 | cpu_sys = end[1]-st[1] |
|
1429 | 1415 | cpu_tot = cpu_user+cpu_sys |
|
1430 | 1416 | print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \ |
|
1431 | 1417 | (cpu_user,cpu_sys,cpu_tot) |
|
1432 | 1418 | print "Wall time: %.2f" % wall_time |
|
1433 | 1419 | return out |
|
1434 | 1420 | |
|
1435 | 1421 | def magic_macro(self,parameter_s = ''): |
|
1436 | 1422 | """Define a set of input lines as a macro for future re-execution. |
|
1437 | 1423 | |
|
1438 | 1424 | Usage:\\ |
|
1439 | 1425 | %macro name n1:n2 n3:n4 ... n5 .. n6 ... |
|
1440 | 1426 | |
|
1441 | 1427 | This will define a global variable called `name` which is a string |
|
1442 | 1428 | made of joining the slices and lines you specify (n1,n2,... numbers |
|
1443 | 1429 | above) from your input history into a single string. This variable |
|
1444 | 1430 | acts like an automatic function which re-executes those lines as if |
|
1445 | 1431 | you had typed them. You just type 'name' at the prompt and the code |
|
1446 | 1432 | executes. |
|
1447 | 1433 | |
|
1448 | 1434 | Note that the slices use the standard Python slicing notation (5:8 |
|
1449 | 1435 | means include lines numbered 5,6,7). |
|
1450 | 1436 | |
|
1451 | 1437 | For example, if your history contains (%hist prints it): |
|
1452 | 1438 | |
|
1453 | 1439 | 44: x=1\\ |
|
1454 | 1440 | 45: y=3\\ |
|
1455 | 1441 | 46: z=x+y\\ |
|
1456 | 1442 | 47: print x\\ |
|
1457 | 1443 | 48: a=5\\ |
|
1458 | 1444 | 49: print 'x',x,'y',y\\ |
|
1459 | 1445 | |
|
1460 | 1446 | you can create a macro with lines 44 through 47 (included) and line 49 |
|
1461 | 1447 | called my_macro with: |
|
1462 | 1448 | |
|
1463 | 1449 | In [51]: %macro my_macro 44:48 49 |
|
1464 | 1450 | |
|
1465 | 1451 | Now, typing `my_macro` (without quotes) will re-execute all this code |
|
1466 | 1452 | in one pass. |
|
1467 | 1453 | |
|
1468 | 1454 | You don't need to give the line-numbers in order, and any given line |
|
1469 | 1455 | number can appear multiple times. You can assemble macros with any |
|
1470 | 1456 | lines from your input history in any order. |
|
1471 | 1457 | |
|
1472 | 1458 | The macro is a simple object which holds its value in an attribute, |
|
1473 | 1459 | but IPython's display system checks for macros and executes them as |
|
1474 | 1460 | code instead of printing them when you type their name. |
|
1475 | 1461 | |
|
1476 | 1462 | You can view a macro's contents by explicitly printing it with: |
|
1477 | 1463 | |
|
1478 | 1464 | 'print macro_name'. |
|
1479 | 1465 | |
|
1480 | 1466 | For one-off cases which DON'T contain magic function calls in them you |
|
1481 | 1467 | can obtain similar results by explicitly executing slices from your |
|
1482 | 1468 | input history with: |
|
1483 | 1469 | |
|
1484 | 1470 | In [60]: exec In[44:48]+In[49]""" |
|
1485 | 1471 | |
|
1486 | 1472 | args = parameter_s.split() |
|
1487 | 1473 | name,ranges = args[0], args[1:] |
|
1488 | 1474 | #print 'rng',ranges # dbg |
|
1489 | 1475 | cmds = self.extract_input_slices(ranges) |
|
1490 | 1476 | macro = Macro(cmds) |
|
1491 | 1477 | self.shell.user_ns.update({name:macro}) |
|
1492 | 1478 | print 'Macro `%s` created. To execute, type its name (without quotes).' % name |
|
1493 | 1479 | print 'Macro contents:' |
|
1494 | 1480 | print str(macro).rstrip(), |
|
1495 | 1481 | |
|
1496 | 1482 | def magic_save(self,parameter_s = ''): |
|
1497 | 1483 | """Save a set of lines to a given filename. |
|
1498 | 1484 | |
|
1499 | 1485 | Usage:\\ |
|
1500 | 1486 | %save filename n1:n2 n3:n4 ... n5 .. n6 ... |
|
1501 | 1487 | |
|
1502 | 1488 | This function uses the same syntax as %macro for line extraction, but |
|
1503 | 1489 | instead of creating a macro it saves the resulting string to the |
|
1504 | 1490 | filename you specify. |
|
1505 | 1491 | |
|
1506 | 1492 | It adds a '.py' extension to the file if you don't do so yourself, and |
|
1507 | 1493 | it asks for confirmation before overwriting existing files.""" |
|
1508 | 1494 | |
|
1509 | 1495 | args = parameter_s.split() |
|
1510 | 1496 | fname,ranges = args[0], args[1:] |
|
1511 | 1497 | if not fname.endswith('.py'): |
|
1512 | 1498 | fname += '.py' |
|
1513 | 1499 | if os.path.isfile(fname): |
|
1514 | 1500 | ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname) |
|
1515 | 1501 | if ans.lower() not in ['y','yes']: |
|
1516 | 1502 | print 'Operation cancelled.' |
|
1517 | 1503 | return |
|
1518 | 1504 | cmds = ''.join(self.extract_input_slices(ranges)) |
|
1519 | 1505 | f = file(fname,'w') |
|
1520 | 1506 | f.write(cmds) |
|
1521 | 1507 | f.close() |
|
1522 | 1508 | print 'The following commands were written to file `%s`:' % fname |
|
1523 | 1509 | print cmds |
|
1524 | 1510 | |
|
1525 | 1511 | def magic_ed(self,parameter_s = ''): |
|
1526 | 1512 | """Alias to %edit.""" |
|
1527 | 1513 | return self.magic_edit(parameter_s) |
|
1528 | 1514 | |
|
1529 | 1515 | def magic_edit(self,parameter_s = '',last_call=['','']): |
|
1530 | 1516 | """Bring up an editor and execute the resulting code. |
|
1531 | 1517 | |
|
1532 | 1518 | Usage: |
|
1533 | 1519 | %edit [options] [args] |
|
1534 | 1520 | |
|
1535 | 1521 | %edit runs IPython's editor hook. The default version of this hook is |
|
1536 | 1522 | set to call the __IPYTHON__.rc.editor command. This is read from your |
|
1537 | 1523 | environment variable $EDITOR. If this isn't found, it will default to |
|
1538 | 1524 | vi under Linux/Unix and to notepad under Windows. See the end of this |
|
1539 | 1525 | docstring for how to change the editor hook. |
|
1540 | 1526 | |
|
1541 | 1527 | You can also set the value of this editor via the command line option |
|
1542 | 1528 | '-editor' or in your ipythonrc file. This is useful if you wish to use |
|
1543 | 1529 | specifically for IPython an editor different from your typical default |
|
1544 | 1530 | (and for Windows users who typically don't set environment variables). |
|
1545 | 1531 | |
|
1546 | 1532 | This command allows you to conveniently edit multi-line code right in |
|
1547 | 1533 | your IPython session. |
|
1548 | 1534 | |
|
1549 | 1535 | If called without arguments, %edit opens up an empty editor with a |
|
1550 | 1536 | temporary file and will execute the contents of this file when you |
|
1551 | 1537 | close it (don't forget to save it!). |
|
1552 | 1538 | |
|
1553 | 1539 | Options: |
|
1554 | 1540 | |
|
1555 | 1541 | -p: this will call the editor with the same data as the previous time |
|
1556 | 1542 | it was used, regardless of how long ago (in your current session) it |
|
1557 | 1543 | was. |
|
1558 | 1544 | |
|
1559 | 1545 | -x: do not execute the edited code immediately upon exit. This is |
|
1560 | 1546 | mainly useful if you are editing programs which need to be called with |
|
1561 | 1547 | command line arguments, which you can then do using %run. |
|
1562 | 1548 | |
|
1563 | 1549 | Arguments: |
|
1564 | 1550 | |
|
1565 | 1551 | If arguments are given, the following possibilites exist: |
|
1566 | 1552 | |
|
1567 | 1553 | - The arguments are numbers or pairs of colon-separated numbers (like |
|
1568 | 1554 | 1 4:8 9). These are interpreted as lines of previous input to be |
|
1569 | 1555 | loaded into the editor. The syntax is the same of the %macro command. |
|
1570 | 1556 | |
|
1571 | 1557 | - If the argument doesn't start with a number, it is evaluated as a |
|
1572 | 1558 | variable and its contents loaded into the editor. You can thus edit |
|
1573 | 1559 | any string which contains python code (including the result of |
|
1574 | 1560 | previous edits). |
|
1575 | 1561 | |
|
1576 | 1562 | - If the argument is the name of an object (other than a string), |
|
1577 | 1563 | IPython will try to locate the file where it was defined and open the |
|
1578 | 1564 | editor at the point where it is defined. You can use `%edit function` |
|
1579 | 1565 | to load an editor exactly at the point where 'function' is defined, |
|
1580 | 1566 | edit it and have the file be executed automatically. |
|
1581 | 1567 | |
|
1582 | 1568 | Note: opening at an exact line is only supported under Unix, and some |
|
1583 | 1569 | editors (like kedit and gedit up to Gnome 2.8) do not understand the |
|
1584 | 1570 | '+NUMBER' parameter necessary for this feature. Good editors like |
|
1585 | 1571 | (X)Emacs, vi, jed, pico and joe all do. |
|
1586 | 1572 | |
|
1587 | 1573 | - If the argument is not found as a variable, IPython will look for a |
|
1588 | 1574 | file with that name (adding .py if necessary) and load it into the |
|
1589 | 1575 | editor. It will execute its contents with execfile() when you exit, |
|
1590 | 1576 | loading any code in the file into your interactive namespace. |
|
1591 | 1577 | |
|
1592 | 1578 | After executing your code, %edit will return as output the code you |
|
1593 | 1579 | typed in the editor (except when it was an existing file). This way |
|
1594 | 1580 | you can reload the code in further invocations of %edit as a variable, |
|
1595 | 1581 | via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of |
|
1596 | 1582 | the output. |
|
1597 | 1583 | |
|
1598 | 1584 | Note that %edit is also available through the alias %ed. |
|
1599 | 1585 | |
|
1600 | 1586 | This is an example of creating a simple function inside the editor and |
|
1601 | 1587 | then modifying it. First, start up the editor: |
|
1602 | 1588 | |
|
1603 | 1589 | In [1]: ed\\ |
|
1604 | 1590 | Editing... done. Executing edited code...\\ |
|
1605 | 1591 | Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n' |
|
1606 | 1592 | |
|
1607 | 1593 | We can then call the function foo(): |
|
1608 | 1594 | |
|
1609 | 1595 | In [2]: foo()\\ |
|
1610 | 1596 | foo() was defined in an editing session |
|
1611 | 1597 | |
|
1612 | 1598 | Now we edit foo. IPython automatically loads the editor with the |
|
1613 | 1599 | (temporary) file where foo() was previously defined: |
|
1614 | 1600 | |
|
1615 | 1601 | In [3]: ed foo\\ |
|
1616 | 1602 | Editing... done. Executing edited code... |
|
1617 | 1603 | |
|
1618 | 1604 | And if we call foo() again we get the modified version: |
|
1619 | 1605 | |
|
1620 | 1606 | In [4]: foo()\\ |
|
1621 | 1607 | foo() has now been changed! |
|
1622 | 1608 | |
|
1623 | 1609 | Here is an example of how to edit a code snippet successive |
|
1624 | 1610 | times. First we call the editor: |
|
1625 | 1611 | |
|
1626 | 1612 | In [8]: ed\\ |
|
1627 | 1613 | Editing... done. Executing edited code...\\ |
|
1628 | 1614 | hello\\ |
|
1629 | 1615 | Out[8]: "print 'hello'\\n" |
|
1630 | 1616 | |
|
1631 | 1617 | Now we call it again with the previous output (stored in _): |
|
1632 | 1618 | |
|
1633 | 1619 | In [9]: ed _\\ |
|
1634 | 1620 | Editing... done. Executing edited code...\\ |
|
1635 | 1621 | hello world\\ |
|
1636 | 1622 | Out[9]: "print 'hello world'\\n" |
|
1637 | 1623 | |
|
1638 | 1624 | Now we call it with the output #8 (stored in _8, also as Out[8]): |
|
1639 | 1625 | |
|
1640 | 1626 | In [10]: ed _8\\ |
|
1641 | 1627 | Editing... done. Executing edited code...\\ |
|
1642 | 1628 | hello again\\ |
|
1643 | 1629 | Out[10]: "print 'hello again'\\n" |
|
1644 | 1630 | |
|
1645 | 1631 | |
|
1646 | 1632 | Changing the default editor hook: |
|
1647 | 1633 | |
|
1648 | 1634 | If you wish to write your own editor hook, you can put it in a |
|
1649 | 1635 | configuration file which you load at startup time. The default hook |
|
1650 | 1636 | is defined in the IPython.hooks module, and you can use that as a |
|
1651 | 1637 | starting example for further modifications. That file also has |
|
1652 | 1638 | general instructions on how to set a new hook for use once you've |
|
1653 | 1639 | defined it.""" |
|
1654 | 1640 | |
|
1655 | 1641 | # FIXME: This function has become a convoluted mess. It needs a |
|
1656 | 1642 | # ground-up rewrite with clean, simple logic. |
|
1657 | 1643 | |
|
1658 | 1644 | def make_filename(arg): |
|
1659 | 1645 | "Make a filename from the given args" |
|
1660 | 1646 | try: |
|
1661 | 1647 | filename = get_py_filename(arg) |
|
1662 | 1648 | except IOError: |
|
1663 | 1649 | if args.endswith('.py'): |
|
1664 | 1650 | filename = arg |
|
1665 | 1651 | else: |
|
1666 | 1652 | filename = None |
|
1667 | 1653 | return filename |
|
1668 | 1654 | |
|
1669 | 1655 | # custom exceptions |
|
1670 | 1656 | class DataIsObject(Exception): pass |
|
1671 | 1657 | |
|
1672 | 1658 | opts,args = self.parse_options(parameter_s,'px') |
|
1673 | 1659 | |
|
1674 | 1660 | # Default line number value |
|
1675 | 1661 | lineno = None |
|
1676 | 1662 | if opts.has_key('p'): |
|
1677 | 1663 | args = '_%s' % last_call[0] |
|
1678 | 1664 | if not self.shell.user_ns.has_key(args): |
|
1679 | 1665 | args = last_call[1] |
|
1680 | 1666 | |
|
1681 | 1667 | # use last_call to remember the state of the previous call, but don't |
|
1682 | 1668 | # let it be clobbered by successive '-p' calls. |
|
1683 | 1669 | try: |
|
1684 | 1670 | last_call[0] = self.shell.outputcache.prompt_count |
|
1685 | 1671 | if not opts.has_key('p'): |
|
1686 | 1672 | last_call[1] = parameter_s |
|
1687 | 1673 | except: |
|
1688 | 1674 | pass |
|
1689 | 1675 | |
|
1690 | 1676 | # by default this is done with temp files, except when the given |
|
1691 | 1677 | # arg is a filename |
|
1692 | 1678 | use_temp = 1 |
|
1693 | 1679 | |
|
1694 | 1680 | if re.match(r'\d',args): |
|
1695 | 1681 | # Mode where user specifies ranges of lines, like in %macro. |
|
1696 | 1682 | # This means that you can't edit files whose names begin with |
|
1697 | 1683 | # numbers this way. Tough. |
|
1698 | 1684 | ranges = args.split() |
|
1699 | 1685 | data = ''.join(self.extract_input_slices(ranges)) |
|
1700 | 1686 | elif args.endswith('.py'): |
|
1701 | 1687 | filename = make_filename(args) |
|
1702 | 1688 | data = '' |
|
1703 | 1689 | use_temp = 0 |
|
1704 | 1690 | elif args: |
|
1705 | 1691 | try: |
|
1706 | 1692 | # Load the parameter given as a variable. If not a string, |
|
1707 | 1693 | # process it as an object instead (below) |
|
1708 | 1694 | |
|
1709 | 1695 | #print '*** args',args,'type',type(args) # dbg |
|
1710 | 1696 | data = eval(args,self.shell.user_ns) |
|
1711 | 1697 | if not type(data) in StringTypes: |
|
1712 | 1698 | raise DataIsObject |
|
1713 | 1699 | except (NameError,SyntaxError): |
|
1714 | 1700 | # given argument is not a variable, try as a filename |
|
1715 | 1701 | filename = make_filename(args) |
|
1716 | 1702 | if filename is None: |
|
1717 | 1703 | warn("Argument given (%s) can't be found as a variable " |
|
1718 | 1704 | "or as a filename." % args) |
|
1719 | 1705 | return |
|
1720 | 1706 | data = '' |
|
1721 | 1707 | use_temp = 0 |
|
1722 | 1708 | except DataIsObject: |
|
1723 | 1709 | # For objects, try to edit the file where they are defined |
|
1724 | 1710 | try: |
|
1725 | 1711 | filename = inspect.getabsfile(data) |
|
1726 | 1712 | datafile = 1 |
|
1727 | 1713 | except TypeError: |
|
1728 | 1714 | filename = make_filename(args) |
|
1729 | 1715 | datafile = 1 |
|
1730 | 1716 | warn('Could not find file where `%s` is defined.\n' |
|
1731 | 1717 | 'Opening a file named `%s`' % (args,filename)) |
|
1732 | 1718 | # Now, make sure we can actually read the source (if it was in |
|
1733 | 1719 | # a temp file it's gone by now). |
|
1734 | 1720 | if datafile: |
|
1735 | 1721 | try: |
|
1736 | 1722 | lineno = inspect.getsourcelines(data)[1] |
|
1737 | 1723 | except IOError: |
|
1738 | 1724 | filename = make_filename(args) |
|
1739 | 1725 | if filename is None: |
|
1740 | 1726 | warn('The file `%s` where `%s` was defined cannot ' |
|
1741 | 1727 | 'be read.' % (filename,data)) |
|
1742 | 1728 | return |
|
1743 | 1729 | use_temp = 0 |
|
1744 | 1730 | else: |
|
1745 | 1731 | data = '' |
|
1746 | 1732 | |
|
1747 | 1733 | if use_temp: |
|
1748 | 1734 | filename = tempfile.mktemp('.py') |
|
1749 | 1735 | self.shell.tempfiles.append(filename) |
|
1750 | 1736 | |
|
1751 | 1737 | if data and use_temp: |
|
1752 | 1738 | tmp_file = open(filename,'w') |
|
1753 | 1739 | tmp_file.write(data) |
|
1754 | 1740 | tmp_file.close() |
|
1755 | 1741 | |
|
1756 | 1742 | # do actual editing here |
|
1757 | 1743 | print 'Editing...', |
|
1758 | 1744 | sys.stdout.flush() |
|
1759 | 1745 | self.shell.hooks.editor(filename,lineno) |
|
1760 | 1746 | if opts.has_key('x'): # -x prevents actual execution |
|
1761 | 1747 | |
|
1762 | 1748 | else: |
|
1763 | 1749 | print 'done. Executing edited code...' |
|
1764 | 1750 | try: |
|
1765 | 1751 | execfile(filename,self.shell.user_ns) |
|
1766 | 1752 | except IOError,msg: |
|
1767 | 1753 | if msg.filename == filename: |
|
1768 | 1754 | warn('File not found. Did you forget to save?') |
|
1769 | 1755 | return |
|
1770 | 1756 | else: |
|
1771 | 1757 | self.shell.showtraceback() |
|
1772 | 1758 | except: |
|
1773 | 1759 | self.shell.showtraceback() |
|
1774 | 1760 | if use_temp: |
|
1775 | 1761 | contents = open(filename).read() |
|
1776 | 1762 | return contents |
|
1777 | 1763 | |
|
1778 | 1764 | def magic_xmode(self,parameter_s = ''): |
|
1779 | 1765 | """Switch modes for the exception handlers. |
|
1780 | 1766 | |
|
1781 | 1767 | Valid modes: Plain, Context and Verbose. |
|
1782 | 1768 | |
|
1783 | 1769 | If called without arguments, acts as a toggle.""" |
|
1784 | 1770 | |
|
1785 | 1771 | new_mode = parameter_s.strip().capitalize() |
|
1786 | 1772 | try: |
|
1787 | 1773 | self.InteractiveTB.set_mode(mode = new_mode) |
|
1788 | 1774 | print 'Exception reporting mode:',self.InteractiveTB.mode |
|
1789 | 1775 | except: |
|
1790 | 1776 | warn('Error changing exception modes.\n' + str(sys.exc_info()[1])) |
|
1791 | 1777 | |
|
1792 | 1778 | def magic_colors(self,parameter_s = ''): |
|
1793 | 1779 | """Switch color scheme for prompts, info system and exception handlers. |
|
1794 | 1780 | |
|
1795 | 1781 | Currently implemented schemes: NoColor, Linux, LightBG. |
|
1796 | 1782 | |
|
1797 | 1783 | Color scheme names are not case-sensitive.""" |
|
1798 | 1784 | |
|
1799 | 1785 | new_scheme = parameter_s.strip() |
|
1800 | 1786 | if not new_scheme: |
|
1801 | 1787 | print 'You must specify a color scheme.' |
|
1802 | 1788 | return |
|
1803 | 1789 | # Under Windows, check for Gary Bishop's readline, which is necessary |
|
1804 | 1790 | # for ANSI coloring |
|
1805 | 1791 | if os.name in ['nt','dos']: |
|
1806 | 1792 | try: |
|
1807 | 1793 | import readline |
|
1808 | 1794 | except ImportError: |
|
1809 | 1795 | has_readline = 0 |
|
1810 | 1796 | else: |
|
1811 | 1797 | try: |
|
1812 | 1798 | readline.GetOutputFile() |
|
1813 | 1799 | except AttributeError: |
|
1814 | 1800 | has_readline = 0 |
|
1815 | 1801 | else: |
|
1816 | 1802 | has_readline = 1 |
|
1817 | 1803 | if not has_readline: |
|
1818 | 1804 | msg = """\ |
|
1819 | 1805 | Proper color support under MS Windows requires Gary Bishop's readline library. |
|
1820 | 1806 | You can find it at: |
|
1821 | 1807 | http://sourceforge.net/projects/uncpythontools |
|
1822 | 1808 | Gary's readline needs the ctypes module, from: |
|
1823 | 1809 | http://starship.python.net/crew/theller/ctypes |
|
1824 | 1810 | |
|
1825 | 1811 | Defaulting color scheme to 'NoColor'""" |
|
1826 | 1812 | new_scheme = 'NoColor' |
|
1827 | 1813 | warn(msg) |
|
1828 | 1814 | |
|
1829 | 1815 | # Set prompt colors |
|
1830 | 1816 | try: |
|
1831 | 1817 | self.shell.outputcache.set_colors(new_scheme) |
|
1832 | 1818 | except: |
|
1833 | 1819 | warn('Error changing prompt color schemes.\n' |
|
1834 | 1820 | + str(sys.exc_info()[1])) |
|
1835 | 1821 | else: |
|
1836 | 1822 | self.shell.rc.colors = \ |
|
1837 | 1823 | self.shell.outputcache.color_table.active_scheme_name |
|
1838 | 1824 | # Set exception colors |
|
1839 | 1825 | try: |
|
1840 | 1826 | self.shell.InteractiveTB.set_colors(scheme = new_scheme) |
|
1841 | 1827 | self.shell.SyntaxTB.set_colors(scheme = new_scheme) |
|
1842 | 1828 | except: |
|
1843 | 1829 | warn('Error changing exception color schemes.\n' |
|
1844 | 1830 | + str(sys.exc_info()[1])) |
|
1845 | 1831 | # Set info (for 'object?') colors |
|
1846 | 1832 | if self.shell.rc.color_info: |
|
1847 | 1833 | try: |
|
1848 | 1834 | self.shell.inspector.set_active_scheme(new_scheme) |
|
1849 | 1835 | except: |
|
1850 | 1836 | warn('Error changing object inspector color schemes.\n' |
|
1851 | 1837 | + str(sys.exc_info()[1])) |
|
1852 | 1838 | else: |
|
1853 | 1839 | self.shell.inspector.set_active_scheme('NoColor') |
|
1854 | 1840 | |
|
1855 | 1841 | def magic_color_info(self,parameter_s = ''): |
|
1856 | 1842 | """Toggle color_info. |
|
1857 | 1843 | |
|
1858 | 1844 | The color_info configuration parameter controls whether colors are |
|
1859 | 1845 | used for displaying object details (by things like %psource, %pfile or |
|
1860 | 1846 | the '?' system). This function toggles this value with each call. |
|
1861 | 1847 | |
|
1862 | 1848 | Note that unless you have a fairly recent pager (less works better |
|
1863 | 1849 | than more) in your system, using colored object information displays |
|
1864 | 1850 | will not work properly. Test it and see.""" |
|
1865 | 1851 | |
|
1866 | 1852 | self.shell.rc.color_info = 1 - self.shell.rc.color_info |
|
1867 | 1853 | self.magic_colors(self.shell.rc.colors) |
|
1868 | 1854 | print 'Object introspection functions have now coloring:', |
|
1869 | 1855 | print ['OFF','ON'][self.shell.rc.color_info] |
|
1870 | 1856 | |
|
1871 | 1857 | def magic_Pprint(self, parameter_s=''): |
|
1872 | 1858 | """Toggle pretty printing on/off.""" |
|
1873 | 1859 | |
|
1874 | 1860 | self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint |
|
1875 | 1861 | print 'Pretty printing has been turned', \ |
|
1876 | 1862 | ['OFF','ON'][self.shell.outputcache.Pprint] |
|
1877 | 1863 | |
|
1878 | 1864 | def magic_Exit(self, parameter_s=''): |
|
1879 | 1865 | """Exit IPython without confirmation.""" |
|
1880 | 1866 | |
|
1881 | 1867 | self.shell.exit_now = True |
|
1882 | 1868 | |
|
1883 | 1869 | def magic_Quit(self, parameter_s=''): |
|
1884 | 1870 | """Exit IPython without confirmation (like %Exit).""" |
|
1885 | 1871 | |
|
1886 | 1872 | self.shell.exit_now = True |
|
1887 | 1873 | |
|
1888 | 1874 | #...................................................................... |
|
1889 | 1875 | # Functions to implement unix shell-type things |
|
1890 | 1876 | |
|
1891 | 1877 | def magic_alias(self, parameter_s = ''): |
|
1892 | 1878 | """Define an alias for a system command. |
|
1893 | 1879 | |
|
1894 | 1880 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
|
1895 | 1881 | |
|
1896 | 1882 | Then, typing 'alias_name params' will execute the system command 'cmd |
|
1897 | 1883 | params' (from your underlying operating system). |
|
1898 | 1884 | |
|
1899 | 1885 | Aliases have lower precedence than magic functions and Python normal |
|
1900 | 1886 | variables, so if 'foo' is both a Python variable and an alias, the |
|
1901 | 1887 | alias can not be executed until 'del foo' removes the Python variable. |
|
1902 | 1888 | |
|
1903 | 1889 | You can use the %l specifier in an alias definition to represent the |
|
1904 | 1890 | whole line when the alias is called. For example: |
|
1905 | 1891 | |
|
1906 | 1892 | In [2]: alias all echo "Input in brackets: <%l>"\\ |
|
1907 | 1893 | In [3]: all hello world\\ |
|
1908 | 1894 | Input in brackets: <hello world> |
|
1909 | 1895 | |
|
1910 | 1896 | You can also define aliases with parameters using %s specifiers (one |
|
1911 | 1897 | per parameter): |
|
1912 | 1898 | |
|
1913 | 1899 | In [1]: alias parts echo first %s second %s\\ |
|
1914 | 1900 | In [2]: %parts A B\\ |
|
1915 | 1901 | first A second B\\ |
|
1916 | 1902 | In [3]: %parts A\\ |
|
1917 | 1903 | Incorrect number of arguments: 2 expected.\\ |
|
1918 | 1904 | parts is an alias to: 'echo first %s second %s' |
|
1919 | 1905 | |
|
1920 | 1906 | Note that %l and %s are mutually exclusive. You can only use one or |
|
1921 | 1907 | the other in your aliases. |
|
1922 | 1908 | |
|
1923 | 1909 | Aliases expand Python variables just like system calls using ! or !! |
|
1924 | 1910 | do: all expressions prefixed with '$' get expanded. For details of |
|
1925 | 1911 | the semantic rules, see PEP-215: |
|
1926 | 1912 | http://www.python.org/peps/pep-0215.html. This is the library used by |
|
1927 | 1913 | IPython for variable expansion. If you want to access a true shell |
|
1928 | 1914 | variable, an extra $ is necessary to prevent its expansion by IPython: |
|
1929 | 1915 | |
|
1930 | 1916 | In [6]: alias show echo\\ |
|
1931 | 1917 | In [7]: PATH='A Python string'\\ |
|
1932 | 1918 | In [8]: show $PATH\\ |
|
1933 | 1919 | A Python string\\ |
|
1934 | 1920 | In [9]: show $$PATH\\ |
|
1935 | 1921 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1936 | 1922 | |
|
1937 | 1923 | You can use the alias facility to acess all of $PATH. See the %rehash |
|
1938 | 1924 | and %rehashx functions, which automatically create aliases for the |
|
1939 | 1925 | contents of your $PATH. |
|
1940 | 1926 | |
|
1941 | 1927 | If called with no parameters, %alias prints the current alias table.""" |
|
1942 | 1928 | |
|
1943 | 1929 | par = parameter_s.strip() |
|
1944 | 1930 | if not par: |
|
1945 | 1931 | if self.shell.rc.automagic: |
|
1946 | 1932 | prechar = '' |
|
1947 | 1933 | else: |
|
1948 | 1934 | prechar = self.shell.ESC_MAGIC |
|
1949 | 1935 | print 'Alias\t\tSystem Command\n'+'-'*30 |
|
1950 | 1936 | atab = self.shell.alias_table |
|
1951 | 1937 | aliases = atab.keys() |
|
1952 | 1938 | aliases.sort() |
|
1953 | 1939 | for alias in aliases: |
|
1954 | 1940 | print prechar+alias+'\t\t'+atab[alias][1] |
|
1955 | 1941 | print '-'*30+'\nTotal number of aliases:',len(aliases) |
|
1956 | 1942 | return |
|
1957 | 1943 | try: |
|
1958 | 1944 | alias,cmd = par.split(None,1) |
|
1959 | 1945 | except: |
|
1960 | 1946 | print OInspect.getdoc(self.magic_alias) |
|
1961 | 1947 | else: |
|
1962 | 1948 | nargs = cmd.count('%s') |
|
1963 | 1949 | if nargs>0 and cmd.find('%l')>=0: |
|
1964 | 1950 | error('The %s and %l specifiers are mutually exclusive ' |
|
1965 | 1951 | 'in alias definitions.') |
|
1966 | 1952 | else: # all looks OK |
|
1967 | 1953 | self.shell.alias_table[alias] = (nargs,cmd) |
|
1968 | 1954 | self.shell.alias_table_validate(verbose=1) |
|
1969 | 1955 | # end magic_alias |
|
1970 | 1956 | |
|
1971 | 1957 | def magic_unalias(self, parameter_s = ''): |
|
1972 | 1958 | """Remove an alias""" |
|
1973 | 1959 | |
|
1974 | 1960 | aname = parameter_s.strip() |
|
1975 | 1961 | if aname in self.shell.alias_table: |
|
1976 | 1962 | del self.shell.alias_table[aname] |
|
1977 | 1963 | |
|
1978 | 1964 | def magic_rehash(self, parameter_s = ''): |
|
1979 | 1965 | """Update the alias table with all entries in $PATH. |
|
1980 | 1966 | |
|
1981 | 1967 | This version does no checks on execute permissions or whether the |
|
1982 | 1968 | contents of $PATH are truly files (instead of directories or something |
|
1983 | 1969 | else). For such a safer (but slower) version, use %rehashx.""" |
|
1984 | 1970 | |
|
1985 | 1971 | # This function (and rehashx) manipulate the alias_table directly |
|
1986 | 1972 | # rather than calling magic_alias, for speed reasons. A rehash on a |
|
1987 | 1973 | # typical Linux box involves several thousand entries, so efficiency |
|
1988 | 1974 | # here is a top concern. |
|
1989 | 1975 | |
|
1990 | 1976 | path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep)) |
|
1991 | 1977 | alias_table = self.shell.alias_table |
|
1992 | 1978 | for pdir in path: |
|
1993 | 1979 | for ff in os.listdir(pdir): |
|
1994 | 1980 | # each entry in the alias table must be (N,name), where |
|
1995 | 1981 | # N is the number of positional arguments of the alias. |
|
1996 | 1982 | alias_table[ff] = (0,ff) |
|
1997 | 1983 | # Make sure the alias table doesn't contain keywords or builtins |
|
1998 | 1984 | self.shell.alias_table_validate() |
|
1999 | 1985 | # Call again init_auto_alias() so we get 'rm -i' and other modified |
|
2000 | 1986 | # aliases since %rehash will probably clobber them |
|
2001 | 1987 | self.shell.init_auto_alias() |
|
2002 | 1988 | |
|
2003 | 1989 | def magic_rehashx(self, parameter_s = ''): |
|
2004 | 1990 | """Update the alias table with all executable files in $PATH. |
|
2005 | 1991 | |
|
2006 | 1992 | This version explicitly checks that every entry in $PATH is a file |
|
2007 | 1993 | with execute access (os.X_OK), so it is much slower than %rehash. |
|
2008 | 1994 | |
|
2009 | 1995 | Under Windows, it checks executability as a match agains a |
|
2010 | 1996 | '|'-separated string of extensions, stored in the IPython config |
|
2011 | 1997 | variable win_exec_ext. This defaults to 'exe|com|bat'. """ |
|
2012 | 1998 | |
|
2013 | 1999 | path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep)) |
|
2014 | 2000 | alias_table = self.shell.alias_table |
|
2015 | 2001 | |
|
2016 | 2002 | if os.name == 'posix': |
|
2017 | 2003 | isexec = lambda fname:os.path.isfile(fname) and \ |
|
2018 | 2004 | os.access(fname,os.X_OK) |
|
2019 | 2005 | else: |
|
2020 | 2006 | |
|
2021 | 2007 | try: |
|
2022 | 2008 | winext = os.environ['pathext'].replace(';','|').replace('.','') |
|
2023 | 2009 | except KeyError: |
|
2024 | 2010 | winext = 'exe|com|bat' |
|
2025 | 2011 | |
|
2026 | 2012 | execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE) |
|
2027 | 2013 | isexec = lambda fname:os.path.isfile(fname) and execre.match(fname) |
|
2028 | 2014 | savedir = os.getcwd() |
|
2029 | 2015 | try: |
|
2030 | 2016 | # write the whole loop for posix/Windows so we don't have an if in |
|
2031 | 2017 | # the innermost part |
|
2032 | 2018 | if os.name == 'posix': |
|
2033 | 2019 | for pdir in path: |
|
2034 | 2020 | os.chdir(pdir) |
|
2035 | 2021 | for ff in os.listdir(pdir): |
|
2036 | 2022 | if isexec(ff): |
|
2037 | 2023 | # each entry in the alias table must be (N,name), |
|
2038 | 2024 | # where N is the number of positional arguments of the |
|
2039 | 2025 | # alias. |
|
2040 | 2026 | alias_table[ff] = (0,ff) |
|
2041 | 2027 | else: |
|
2042 | 2028 | for pdir in path: |
|
2043 | 2029 | os.chdir(pdir) |
|
2044 | 2030 | for ff in os.listdir(pdir): |
|
2045 | 2031 | if isexec(ff): |
|
2046 | 2032 | alias_table[execre.sub(r'\1',ff)] = (0,ff) |
|
2047 | 2033 | # Make sure the alias table doesn't contain keywords or builtins |
|
2048 | 2034 | self.shell.alias_table_validate() |
|
2049 | 2035 | # Call again init_auto_alias() so we get 'rm -i' and other |
|
2050 | 2036 | # modified aliases since %rehashx will probably clobber them |
|
2051 | 2037 | self.shell.init_auto_alias() |
|
2052 | 2038 | finally: |
|
2053 | 2039 | os.chdir(savedir) |
|
2054 | 2040 | |
|
2055 | 2041 | def magic_pwd(self, parameter_s = ''): |
|
2056 | 2042 | """Return the current working directory path.""" |
|
2057 | 2043 | return os.getcwd() |
|
2058 | 2044 | |
|
2059 | 2045 | def magic_cd(self, parameter_s=''): |
|
2060 | 2046 | """Change the current working directory. |
|
2061 | 2047 | |
|
2062 | 2048 | This command automatically maintains an internal list of directories |
|
2063 | 2049 | you visit during your IPython session, in the variable _dh. The |
|
2064 | 2050 | command %dhist shows this history nicely formatted. |
|
2065 | 2051 | |
|
2066 | 2052 | Usage: |
|
2067 | 2053 | |
|
2068 | 2054 | cd 'dir': changes to directory 'dir'. |
|
2069 | 2055 | |
|
2070 | 2056 | cd -: changes to the last visited directory. |
|
2071 | 2057 | |
|
2072 | 2058 | cd -<n>: changes to the n-th directory in the directory history. |
|
2073 | 2059 | |
|
2074 | 2060 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark |
|
2075 | 2061 | (note: cd <bookmark_name> is enough if there is no |
|
2076 | 2062 | directory <bookmark_name>, but a bookmark with the name exists.) |
|
2077 | 2063 | |
|
2078 | 2064 | Options: |
|
2079 | 2065 | |
|
2080 | 2066 | -q: quiet. Do not print the working directory after the cd command is |
|
2081 | 2067 | executed. By default IPython's cd command does print this directory, |
|
2082 | 2068 | since the default prompts do not display path information. |
|
2083 | 2069 | |
|
2084 | 2070 | Note that !cd doesn't work for this purpose because the shell where |
|
2085 | 2071 | !command runs is immediately discarded after executing 'command'.""" |
|
2086 | 2072 | |
|
2087 | 2073 | parameter_s = parameter_s.strip() |
|
2088 | 2074 | bkms = self.shell.persist.get("bookmarks",{}) |
|
2089 | 2075 | |
|
2090 | 2076 | numcd = re.match(r'(-)(\d+)$',parameter_s) |
|
2091 | 2077 | # jump in directory history by number |
|
2092 | 2078 | if numcd: |
|
2093 | 2079 | nn = int(numcd.group(2)) |
|
2094 | 2080 | try: |
|
2095 | 2081 | ps = self.shell.user_ns['_dh'][nn] |
|
2096 | 2082 | except IndexError: |
|
2097 | 2083 | print 'The requested directory does not exist in history.' |
|
2098 | 2084 | return |
|
2099 | 2085 | else: |
|
2100 | 2086 | opts = {} |
|
2101 | 2087 | else: |
|
2102 | 2088 | opts,ps = self.parse_options(parameter_s,'qb',mode='string') |
|
2103 | 2089 | # jump to previous |
|
2104 | 2090 | if ps == '-': |
|
2105 | 2091 | try: |
|
2106 | 2092 | ps = self.shell.user_ns['_dh'][-2] |
|
2107 | 2093 | except IndexError: |
|
2108 | 2094 | print 'No previous directory to change to.' |
|
2109 | 2095 | return |
|
2110 | 2096 | # jump to bookmark |
|
2111 | 2097 | elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)): |
|
2112 | 2098 | if bkms.has_key(ps): |
|
2113 | 2099 | target = bkms[ps] |
|
2114 | 2100 | print '(bookmark:%s) -> %s' % (ps,target) |
|
2115 | 2101 | ps = target |
|
2116 | 2102 | else: |
|
2117 | 2103 | if bkms: |
|
2118 | 2104 | error("Bookmark '%s' not found. " |
|
2119 | 2105 | "Use '%bookmark -l' to see your bookmarks." % ps) |
|
2120 | 2106 | else: |
|
2121 | 2107 | print "Bookmarks not set - use %bookmark <bookmarkname>" |
|
2122 | 2108 | return |
|
2123 | 2109 | |
|
2124 | 2110 | # at this point ps should point to the target dir |
|
2125 | 2111 | if ps: |
|
2126 | 2112 | try: |
|
2127 | 2113 | os.chdir(os.path.expanduser(ps)) |
|
2128 | 2114 | except OSError: |
|
2129 | 2115 | print sys.exc_info()[1] |
|
2130 | 2116 | else: |
|
2131 | 2117 | self.shell.user_ns['_dh'].append(os.getcwd()) |
|
2132 | 2118 | else: |
|
2133 | 2119 | os.chdir(self.home_dir) |
|
2134 | 2120 | self.shell.user_ns['_dh'].append(os.getcwd()) |
|
2135 | 2121 | if not 'q' in opts: |
|
2136 | 2122 | print self.shell.user_ns['_dh'][-1] |
|
2137 | 2123 | |
|
2138 | 2124 | def magic_dhist(self, parameter_s=''): |
|
2139 | 2125 | """Print your history of visited directories. |
|
2140 | 2126 | |
|
2141 | 2127 | %dhist -> print full history\\ |
|
2142 | 2128 | %dhist n -> print last n entries only\\ |
|
2143 | 2129 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\ |
|
2144 | 2130 | |
|
2145 | 2131 | This history is automatically maintained by the %cd command, and |
|
2146 | 2132 | always available as the global list variable _dh. You can use %cd -<n> |
|
2147 | 2133 | to go to directory number <n>.""" |
|
2148 | 2134 | |
|
2149 | 2135 | dh = self.shell.user_ns['_dh'] |
|
2150 | 2136 | if parameter_s: |
|
2151 | 2137 | try: |
|
2152 | 2138 | args = map(int,parameter_s.split()) |
|
2153 | 2139 | except: |
|
2154 | 2140 | self.arg_err(Magic.magic_dhist) |
|
2155 | 2141 | return |
|
2156 | 2142 | if len(args) == 1: |
|
2157 | 2143 | ini,fin = max(len(dh)-(args[0]),0),len(dh) |
|
2158 | 2144 | elif len(args) == 2: |
|
2159 | 2145 | ini,fin = args |
|
2160 | 2146 | else: |
|
2161 | 2147 | self.arg_err(Magic.magic_dhist) |
|
2162 | 2148 | return |
|
2163 | 2149 | else: |
|
2164 | 2150 | ini,fin = 0,len(dh) |
|
2165 | 2151 | nlprint(dh, |
|
2166 | 2152 | header = 'Directory history (kept in _dh)', |
|
2167 | 2153 | start=ini,stop=fin) |
|
2168 | 2154 | |
|
2169 | 2155 | def magic_env(self, parameter_s=''): |
|
2170 | 2156 | """List environment variables.""" |
|
2171 | 2157 | |
|
2172 | 2158 | # environ is an instance of UserDict |
|
2173 | 2159 | return os.environ.data |
|
2174 | 2160 | |
|
2175 | 2161 | def magic_pushd(self, parameter_s=''): |
|
2176 | 2162 | """Place the current dir on stack and change directory. |
|
2177 | 2163 | |
|
2178 | 2164 | Usage:\\ |
|
2179 | 2165 | %pushd ['dirname'] |
|
2180 | 2166 | |
|
2181 | 2167 | %pushd with no arguments does a %pushd to your home directory. |
|
2182 | 2168 | """ |
|
2183 | 2169 | if parameter_s == '': parameter_s = '~' |
|
2184 | 2170 | if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \ |
|
2185 | 2171 | os.path.expanduser(self.dir_stack[0]): |
|
2186 | 2172 | try: |
|
2187 | 2173 | self.magic_cd(parameter_s) |
|
2188 | 2174 | self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~')) |
|
2189 | 2175 | self.magic_dirs() |
|
2190 | 2176 | except: |
|
2191 | 2177 | print 'Invalid directory' |
|
2192 | 2178 | else: |
|
2193 | 2179 | print 'You are already there!' |
|
2194 | 2180 | |
|
2195 | 2181 | def magic_popd(self, parameter_s=''): |
|
2196 | 2182 | """Change to directory popped off the top of the stack. |
|
2197 | 2183 | """ |
|
2198 | 2184 | if len (self.dir_stack) > 1: |
|
2199 | 2185 | self.dir_stack.pop(0) |
|
2200 | 2186 | self.magic_cd(self.dir_stack[0]) |
|
2201 | 2187 | print self.dir_stack[0] |
|
2202 | 2188 | else: |
|
2203 | 2189 | print "You can't remove the starting directory from the stack:",\ |
|
2204 | 2190 | self.dir_stack |
|
2205 | 2191 | |
|
2206 | 2192 | def magic_dirs(self, parameter_s=''): |
|
2207 | 2193 | """Return the current directory stack.""" |
|
2208 | 2194 | |
|
2209 | 2195 | return self.dir_stack[:] |
|
2210 | 2196 | |
|
2211 | 2197 | def magic_sc(self, parameter_s=''): |
|
2212 | 2198 | """Shell capture - execute a shell command and capture its output. |
|
2213 | 2199 | |
|
2214 | 2200 | %sc [options] varname=command |
|
2215 | 2201 | |
|
2216 | 2202 | IPython will run the given command using commands.getoutput(), and |
|
2217 | 2203 | will then update the user's interactive namespace with a variable |
|
2218 | 2204 | called varname, containing the value of the call. Your command can |
|
2219 | 2205 | contain shell wildcards, pipes, etc. |
|
2220 | 2206 | |
|
2221 | 2207 | The '=' sign in the syntax is mandatory, and the variable name you |
|
2222 | 2208 | supply must follow Python's standard conventions for valid names. |
|
2223 | 2209 | |
|
2224 | 2210 | Options: |
|
2225 | 2211 | |
|
2226 | 2212 | -l: list output. Split the output on newlines into a list before |
|
2227 | 2213 | assigning it to the given variable. By default the output is stored |
|
2228 | 2214 | as a single string. |
|
2229 | 2215 | |
|
2230 | 2216 | -v: verbose. Print the contents of the variable. |
|
2231 | 2217 | |
|
2232 | 2218 | In most cases you should not need to split as a list, because the |
|
2233 | 2219 | returned value is a special type of string which can automatically |
|
2234 | 2220 | provide its contents either as a list (split on newlines) or as a |
|
2235 | 2221 | space-separated string. These are convenient, respectively, either |
|
2236 | 2222 | for sequential processing or to be passed to a shell command. |
|
2237 | 2223 | |
|
2238 | 2224 | For example: |
|
2239 | 2225 | |
|
2240 | 2226 | # Capture into variable a |
|
2241 | 2227 | In [9]: sc a=ls *py |
|
2242 | 2228 | |
|
2243 | 2229 | # a is a string with embedded newlines |
|
2244 | 2230 | In [10]: a |
|
2245 | 2231 | Out[10]: 'setup.py\nwin32_manual_post_install.py' |
|
2246 | 2232 | |
|
2247 | 2233 | # which can be seen as a list: |
|
2248 | 2234 | In [11]: a.l |
|
2249 | 2235 | Out[11]: ['setup.py', 'win32_manual_post_install.py'] |
|
2250 | 2236 | |
|
2251 | 2237 | # or as a whitespace-separated string: |
|
2252 | 2238 | In [12]: a.s |
|
2253 | 2239 | Out[12]: 'setup.py win32_manual_post_install.py' |
|
2254 | 2240 | |
|
2255 | 2241 | # a.s is useful to pass as a single command line: |
|
2256 | 2242 | In [13]: !wc -l $a.s |
|
2257 | 2243 | 146 setup.py |
|
2258 | 2244 | 130 win32_manual_post_install.py |
|
2259 | 2245 | 276 total |
|
2260 | 2246 | |
|
2261 | 2247 | # while the list form is useful to loop over: |
|
2262 | 2248 | In [14]: for f in a.l: |
|
2263 | 2249 | ....: !wc -l $f |
|
2264 | 2250 | ....: |
|
2265 | 2251 | 146 setup.py |
|
2266 | 2252 | 130 win32_manual_post_install.py |
|
2267 | 2253 | |
|
2268 | 2254 | Similiarly, the lists returned by the -l option are also special, in |
|
2269 | 2255 | the sense that you can equally invoke the .s attribute on them to |
|
2270 | 2256 | automatically get a whitespace-separated string from their contents: |
|
2271 | 2257 | |
|
2272 | 2258 | In [1]: sc -l b=ls *py |
|
2273 | 2259 | |
|
2274 | 2260 | In [2]: b |
|
2275 | 2261 | Out[2]: ['setup.py', 'win32_manual_post_install.py'] |
|
2276 | 2262 | |
|
2277 | 2263 | In [3]: b.s |
|
2278 | 2264 | Out[3]: 'setup.py win32_manual_post_install.py' |
|
2279 | 2265 | |
|
2280 | 2266 | In summary, both the lists and strings used for ouptut capture have |
|
2281 | 2267 | the following special attributes: |
|
2282 | 2268 | |
|
2283 | 2269 | .l (or .list) : value as list. |
|
2284 | 2270 | .n (or .nlstr): value as newline-separated string. |
|
2285 | 2271 | .s (or .spstr): value as space-separated string. |
|
2286 | 2272 | """ |
|
2287 | 2273 | |
|
2288 | 2274 | opts,args = self.parse_options(parameter_s,'lv') |
|
2289 | 2275 | # Try to get a variable name and command to run |
|
2290 | 2276 | try: |
|
2291 | 2277 | # the variable name must be obtained from the parse_options |
|
2292 | 2278 | # output, which uses shlex.split to strip options out. |
|
2293 | 2279 | var,_ = args.split('=',1) |
|
2294 | 2280 | var = var.strip() |
|
2295 | 2281 | # But the the command has to be extracted from the original input |
|
2296 | 2282 | # parameter_s, not on what parse_options returns, to avoid the |
|
2297 | 2283 | # quote stripping which shlex.split performs on it. |
|
2298 | 2284 | _,cmd = parameter_s.split('=',1) |
|
2299 | 2285 | except ValueError: |
|
2300 | 2286 | var,cmd = '','' |
|
2301 | 2287 | if not var: |
|
2302 | 2288 | error('you must specify a variable to assign the command to.') |
|
2303 | 2289 | return |
|
2304 | 2290 | # If all looks ok, proceed |
|
2305 | 2291 | out,err = self.shell.getoutputerror(cmd) |
|
2306 | 2292 | if err: |
|
2307 | 2293 | print >> Term.cerr,err |
|
2308 | 2294 | if opts.has_key('l'): |
|
2309 | 2295 | out = SList(out.split('\n')) |
|
2310 | 2296 | else: |
|
2311 | 2297 | out = LSString(out) |
|
2312 | 2298 | if opts.has_key('v'): |
|
2313 | 2299 | print '%s ==\n%s' % (var,pformat(out)) |
|
2314 | 2300 | self.shell.user_ns.update({var:out}) |
|
2315 | 2301 | |
|
2316 | 2302 | def magic_sx(self, parameter_s=''): |
|
2317 | 2303 | """Shell execute - run a shell command and capture its output. |
|
2318 | 2304 | |
|
2319 | 2305 | %sx command |
|
2320 | 2306 | |
|
2321 | 2307 | IPython will run the given command using commands.getoutput(), and |
|
2322 | 2308 | return the result formatted as a list (split on '\\n'). Since the |
|
2323 | 2309 | output is _returned_, it will be stored in ipython's regular output |
|
2324 | 2310 | cache Out[N] and in the '_N' automatic variables. |
|
2325 | 2311 | |
|
2326 | 2312 | Notes: |
|
2327 | 2313 | |
|
2328 | 2314 | 1) If an input line begins with '!!', then %sx is automatically |
|
2329 | 2315 | invoked. That is, while: |
|
2330 | 2316 | !ls |
|
2331 | 2317 | causes ipython to simply issue system('ls'), typing |
|
2332 | 2318 | !!ls |
|
2333 | 2319 | is a shorthand equivalent to: |
|
2334 | 2320 | %sx ls |
|
2335 | 2321 | |
|
2336 | 2322 | 2) %sx differs from %sc in that %sx automatically splits into a list, |
|
2337 | 2323 | like '%sc -l'. The reason for this is to make it as easy as possible |
|
2338 | 2324 | to process line-oriented shell output via further python commands. |
|
2339 | 2325 | %sc is meant to provide much finer control, but requires more |
|
2340 | 2326 | typing. |
|
2341 | 2327 | |
|
2342 | 2328 | 3) Just like %sc -l, this is a list with special attributes: |
|
2343 | 2329 | |
|
2344 | 2330 | .l (or .list) : value as list. |
|
2345 | 2331 | .n (or .nlstr): value as newline-separated string. |
|
2346 | 2332 | .s (or .spstr): value as whitespace-separated string. |
|
2347 | 2333 | |
|
2348 | 2334 | This is very useful when trying to use such lists as arguments to |
|
2349 | 2335 | system commands.""" |
|
2350 | 2336 | |
|
2351 | 2337 | if parameter_s: |
|
2352 | 2338 | out,err = self.shell.getoutputerror(parameter_s) |
|
2353 | 2339 | if err: |
|
2354 | 2340 | print >> Term.cerr,err |
|
2355 | 2341 | return SList(out.split('\n')) |
|
2356 | 2342 | |
|
2357 | 2343 | def magic_bg(self, parameter_s=''): |
|
2358 | 2344 | """Run a job in the background, in a separate thread. |
|
2359 | 2345 | |
|
2360 | 2346 | For example, |
|
2361 | 2347 | |
|
2362 | 2348 | %bg myfunc(x,y,z=1) |
|
2363 | 2349 | |
|
2364 | 2350 | will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the |
|
2365 | 2351 | execution starts, a message will be printed indicating the job |
|
2366 | 2352 | number. If your job number is 5, you can use |
|
2367 | 2353 | |
|
2368 | 2354 | myvar = jobs.result(5) or myvar = jobs[5].result |
|
2369 | 2355 | |
|
2370 | 2356 | to assign this result to variable 'myvar'. |
|
2371 | 2357 | |
|
2372 | 2358 | IPython has a job manager, accessible via the 'jobs' object. You can |
|
2373 | 2359 | type jobs? to get more information about it, and use jobs.<TAB> to see |
|
2374 | 2360 | its attributes. All attributes not starting with an underscore are |
|
2375 | 2361 | meant for public use. |
|
2376 | 2362 | |
|
2377 | 2363 | In particular, look at the jobs.new() method, which is used to create |
|
2378 | 2364 | new jobs. This magic %bg function is just a convenience wrapper |
|
2379 | 2365 | around jobs.new(), for expression-based jobs. If you want to create a |
|
2380 | 2366 | new job with an explicit function object and arguments, you must call |
|
2381 | 2367 | jobs.new() directly. |
|
2382 | 2368 | |
|
2383 | 2369 | The jobs.new docstring also describes in detail several important |
|
2384 | 2370 | caveats associated with a thread-based model for background job |
|
2385 | 2371 | execution. Type jobs.new? for details. |
|
2386 | 2372 | |
|
2387 | 2373 | You can check the status of all jobs with jobs.status(). |
|
2388 | 2374 | |
|
2389 | 2375 | The jobs variable is set by IPython into the Python builtin namespace. |
|
2390 | 2376 | If you ever declare a variable named 'jobs', you will shadow this |
|
2391 | 2377 | name. You can either delete your global jobs variable to regain |
|
2392 | 2378 | access to the job manager, or make a new name and assign it manually |
|
2393 | 2379 | to the manager (stored in IPython's namespace). For example, to |
|
2394 | 2380 | assign the job manager to the Jobs name, use: |
|
2395 | 2381 | |
|
2396 | 2382 | Jobs = __builtins__.jobs""" |
|
2397 | 2383 | |
|
2398 | 2384 | self.shell.jobs.new(parameter_s,self.shell.user_ns) |
|
2399 | 2385 | |
|
2400 | 2386 | def magic_bookmark(self, parameter_s=''): |
|
2401 | 2387 | """Manage IPython's bookmark system. |
|
2402 | 2388 | |
|
2403 | 2389 | %bookmark <name> - set bookmark to current dir |
|
2404 | 2390 | %bookmark <name> <dir> - set bookmark to <dir> |
|
2405 | 2391 | %bookmark -l - list all bookmarks |
|
2406 | 2392 | %bookmark -d <name> - remove bookmark |
|
2407 | 2393 | %bookmark -r - remove all bookmarks |
|
2408 | 2394 | |
|
2409 | 2395 | You can later on access a bookmarked folder with: |
|
2410 | 2396 | %cd -b <name> |
|
2411 | 2397 | or simply '%cd <name>' if there is no directory called <name> AND |
|
2412 | 2398 | there is such a bookmark defined. |
|
2413 | 2399 | |
|
2414 | 2400 | Your bookmarks persist through IPython sessions, but they are |
|
2415 | 2401 | associated with each profile.""" |
|
2416 | 2402 | |
|
2417 | 2403 | opts,args = self.parse_options(parameter_s,'drl',mode='list') |
|
2418 | 2404 | if len(args) > 2: |
|
2419 | 2405 | error('You can only give at most two arguments') |
|
2420 | 2406 | return |
|
2421 | 2407 | |
|
2422 | 2408 | bkms = self.shell.persist.get('bookmarks',{}) |
|
2423 | 2409 | |
|
2424 | 2410 | if opts.has_key('d'): |
|
2425 | 2411 | try: |
|
2426 | 2412 | todel = args[0] |
|
2427 | 2413 | except IndexError: |
|
2428 | 2414 | error('You must provide a bookmark to delete') |
|
2429 | 2415 | else: |
|
2430 | 2416 | try: |
|
2431 | 2417 | del bkms[todel] |
|
2432 | 2418 | except: |
|
2433 | 2419 | error("Can't delete bookmark '%s'" % todel) |
|
2434 | 2420 | elif opts.has_key('r'): |
|
2435 | 2421 | bkms = {} |
|
2436 | 2422 | elif opts.has_key('l'): |
|
2437 | 2423 | bks = bkms.keys() |
|
2438 | 2424 | bks.sort() |
|
2439 | 2425 | if bks: |
|
2440 | 2426 | size = max(map(len,bks)) |
|
2441 | 2427 | else: |
|
2442 | 2428 | size = 0 |
|
2443 | 2429 | fmt = '%-'+str(size)+'s -> %s' |
|
2444 | 2430 | print 'Current bookmarks:' |
|
2445 | 2431 | for bk in bks: |
|
2446 | 2432 | print fmt % (bk,bkms[bk]) |
|
2447 | 2433 | else: |
|
2448 | 2434 | if not args: |
|
2449 | 2435 | error("You must specify the bookmark name") |
|
2450 | 2436 | elif len(args)==1: |
|
2451 | 2437 | bkms[args[0]] = os.getcwd() |
|
2452 | 2438 | elif len(args)==2: |
|
2453 | 2439 | bkms[args[0]] = args[1] |
|
2454 | 2440 | self.persist['bookmarks'] = bkms |
|
2455 | 2441 | |
|
2456 | 2442 | def magic_pycat(self, parameter_s=''): |
|
2457 | 2443 | """Show a syntax-highlighted file through a pager. |
|
2458 | 2444 | |
|
2459 | 2445 | This magic is similar to the cat utility, but it will assume the file |
|
2460 | 2446 | to be Python source and will show it with syntax highlighting. """ |
|
2461 | 2447 | |
|
2462 | try: | |
|
2463 | 2448 |
|
|
2464 | except IndexError: | |
|
2465 | warn('you must provide at least a filename.') | |
|
2466 | return | |
|
2467 | fobj=open(filename,'r') | |
|
2468 | source = fobj.read() | |
|
2469 | fobj.close() | |
|
2470 | colorize = Parser().format | |
|
2471 | colorized_src = colorize(source,'str',self.shell.rc['colors']) | |
|
2472 | page(colorized_src,screen_lines=self.shell.rc.screen_length) | |
|
2449 | page(self.shell.colorize(file_read(filename)), | |
|
2450 | screen_lines=self.shell.rc.screen_length) | |
|
2473 | 2451 | |
|
2474 | 2452 | # end Magic |
@@ -1,201 +1,309 b'' | |||
|
1 | 1 | """Module for interactive demos using IPython. |
|
2 | 2 | |
|
3 | Sorry, but this uses Python 2.3 features, so it won't work in 2.2 environments. | |
|
3 | This module implements a single class, Demo, for running Python scripts | |
|
4 | interactively in IPython for demonstrations. With very simple markup (a few | |
|
5 | tags in comments), you can control points where the script stops executing and | |
|
6 | returns control to IPython. | |
|
7 | ||
|
8 | The file is run in its own empty namespace (though you can pass it a string of | |
|
9 | arguments as if in a command line environment, and it will see those as | |
|
10 | sys.argv). But at each stop, the global IPython namespace is updated with the | |
|
11 | current internal demo namespace, so you can work interactively with the data | |
|
12 | accumulated so far. | |
|
13 | ||
|
14 | By default, each block of code is printed (with syntax highlighting) before | |
|
15 | executing it and you have to confirm execution. This is intended to show the | |
|
16 | code to an audience first so you can discuss it, and only proceed with | |
|
17 | execution once you agree. There are a few tags which allow you to modify this | |
|
18 | behavior. | |
|
19 | ||
|
20 | The supported tags are: | |
|
21 | ||
|
22 | # <demo> --- stop --- | |
|
23 | ||
|
24 | Defines block boundaries, the points where IPython stops execution of the | |
|
25 | file and returns to the interactive prompt. | |
|
26 | ||
|
27 | # <demo> silent | |
|
28 | ||
|
29 | Make a block execute silently (and hence automatically). Typically used in | |
|
30 | cases where you have some boilerplate or initialization code which you need | |
|
31 | executed but do not want to be seen in the demo. | |
|
32 | ||
|
33 | # <demo> auto | |
|
34 | ||
|
35 | Make a block execute automatically, but still being printed. Useful for | |
|
36 | simple code which does not warrant discussion, since it avoids the extra | |
|
37 | manual confirmation. | |
|
38 | ||
|
39 | # <demo> auto_all | |
|
40 | ||
|
41 | This tag can _only_ be in the first block, and if given it overrides the | |
|
42 | individual auto tags to make the whole demo fully automatic (no block asks | |
|
43 | for confirmation). It can also be given at creation time (or the attribute | |
|
44 | set later) to override what's in the file. | |
|
45 | ||
|
46 | While _any_ python file can be run as a Demo instance, if there are no stop | |
|
47 | tags the whole file will run in a single block (no different that calling | |
|
48 | first %pycat and then %run). The minimal markup to make this useful is to | |
|
49 | place a set of stop tags; the other tags are only there to let you fine-tune | |
|
50 | the execution. | |
|
51 | ||
|
52 | This is probably best explained with the simple example file below. You can | |
|
53 | copy this into a file named ex_demo.py, and try running it via: | |
|
54 | ||
|
55 | from IPython.demo import Demo | |
|
56 | d = Demo('ex_demo.py') | |
|
57 | d() <--- Call the d object (omit the parens if you have autocall on). | |
|
58 | ||
|
59 | Each time you call the demo object, it runs the next block. The demo object | |
|
60 | has a few useful methods for navigation, like again(), jump(), seek() and | |
|
61 | back(). It can be reset for a new run via reset() or reloaded from disk (in | |
|
62 | case you've edited the source) via reload(). See their docstrings below. | |
|
63 | ||
|
64 | #################### EXAMPLE DEMO <ex_demo.py> ############################### | |
|
65 | '''A simple interactive demo to illustrate the use of IPython's Demo class.''' | |
|
66 | ||
|
67 | print 'Hello, welcome to an interactive IPython demo.' | |
|
68 | ||
|
69 | # The mark below defines a block boundary, which is a point where IPython will | |
|
70 | # stop execution and return to the interactive prompt. | |
|
71 | # Note that in actual interactive execution, | |
|
72 | # <demo> --- stop --- | |
|
73 | ||
|
74 | x = 1 | |
|
75 | y = 2 | |
|
76 | ||
|
77 | # <demo> --- stop --- | |
|
78 | ||
|
79 | # the mark below makes this block as silent | |
|
80 | # <demo> silent | |
|
81 | ||
|
82 | print 'This is a silent block, which gets executed but not printed.' | |
|
83 | ||
|
84 | # <demo> --- stop --- | |
|
85 | # <demo> auto | |
|
86 | print 'This is an automatic block.' | |
|
87 | print 'It is executed without asking for confirmation, but printed.' | |
|
88 | z = x+y | |
|
89 | ||
|
90 | print 'z=',x | |
|
91 | ||
|
92 | # <demo> --- stop --- | |
|
93 | # This is just another normal block. | |
|
94 | print 'z is now:', z | |
|
95 | ||
|
96 | print 'bye!' | |
|
97 | ################### END EXAMPLE DEMO <ex_demo.py> ############################ | |
|
98 | ||
|
99 | WARNING: this module uses Python 2.3 features, so it won't work in 2.2 | |
|
100 | environments. | |
|
4 | 101 | """ |
|
5 | 102 | #***************************************************************************** |
|
6 | 103 | # Copyright (C) 2005 Fernando Perez. <Fernando.Perez@colorado.edu> |
|
7 | 104 | # |
|
8 | 105 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | 106 | # the file COPYING, distributed as part of this software. |
|
10 | 107 | # |
|
11 | 108 | #***************************************************************************** |
|
12 | 109 | |
|
13 | 110 | import sys |
|
14 | 111 | import exceptions |
|
15 | 112 | import re |
|
16 | 113 | |
|
17 | 114 | from IPython.PyColorize import Parser |
|
18 | from IPython.genutils import marquee, shlex_split | |
|
115 | from IPython.genutils import marquee, shlex_split, file_read | |
|
116 | ||
|
117 | __all__ = ['Demo','DemoError'] | |
|
19 | 118 | |
|
20 | 119 | class DemoError(exceptions.Exception): pass |
|
21 | 120 | |
|
121 | def re_mark(mark): | |
|
122 | return re.compile(r'^\s*#\s+<demo>\s+%s\s*$' % mark,re.MULTILINE) | |
|
123 | ||
|
22 | 124 | class Demo: |
|
23 | def __init__(self,fname,arg_str='',mark_pause='# pause', | |
|
24 | mark_silent='# silent',mark_auto='# auto',auto=False): | |
|
125 | ||
|
126 | re_stop = re_mark('---\s?stop\s?---') | |
|
127 | re_silent = re_mark('silent') | |
|
128 | re_auto = re_mark('auto') | |
|
129 | re_auto_all = re_mark('auto_all') | |
|
130 | ||
|
131 | def __init__(self,fname,arg_str='',auto_all=None): | |
|
25 | 132 | """Make a new demo object. To run the demo, simply call the object. |
|
26 | 133 | |
|
134 | See the module docstring for full details and an example (you can use | |
|
135 | IPython.Demo? in IPython to see it). | |
|
136 | ||
|
27 | 137 | Inputs: |
|
28 | 138 | |
|
29 | 139 | - fname = filename. |
|
30 | 140 | |
|
31 | 141 | Optional inputs: |
|
32 | 142 | |
|
33 | 143 | - arg_str(''): a string of arguments, internally converted to a list |
|
34 | 144 | just like sys.argv, so the demo script can see a similar |
|
35 | 145 | environment. |
|
36 | 146 | |
|
37 | - mark_pause ('# pause'): marks for pausing (block boundaries). The | |
|
38 | marks are turned into regexps which match them as standalone in a | |
|
39 | line, with all leading/trailing whitespace ignored. | |
|
40 | ||
|
41 | - mark_silent('# silent'): mark blocks as silent, which means that | |
|
42 | they are executed without printing their content to screen. Silent | |
|
43 | blocks are always automatically executed. | |
|
44 | ||
|
45 | - mark_auto ('# auto'): mark individual blocks as automatically | |
|
46 | executed (without asking for confirmation). | |
|
47 | ||
|
48 | - auto(False): global flag to run all blocks automatically without | |
|
147 | - auto_all(None): global flag to run all blocks automatically without | |
|
49 | 148 | confirmation. This attribute overrides the block-level tags and |
|
50 | 149 | applies to the whole demo. It is an attribute of the object, and |
|
51 | 150 | can be changed at runtime simply by reassigning it to a boolean |
|
52 | 151 | value. |
|
53 | 152 | """ |
|
54 | 153 | |
|
55 | 154 |
self.fname |
|
56 | 155 |
self.sys_argv |
|
57 | self.mark_pause = mark_pause | |
|
58 | self.mark_silent = mark_silent | |
|
59 | self.re_pause = re.compile(r'^\s*%s\s*$' % mark_pause,re.MULTILINE) | |
|
60 | self.re_silent = re.compile(r'^\s*%s\s*$' % mark_silent,re.MULTILINE) | |
|
61 | self.re_auto = re.compile(r'^\s*%s\s*$' % mark_auto,re.MULTILINE) | |
|
62 | self.auto = auto | |
|
156 | self.auto_all = auto_all | |
|
63 | 157 | |
|
64 | 158 | # get a few things from ipython. While it's a bit ugly design-wise, |
|
65 | 159 | # it ensures that things like color scheme and the like are always in |
|
66 | 160 | # sync with the ipython mode being used. This class is only meant to |
|
67 | 161 | # be used inside ipython anyways, so it's OK. |
|
68 | 162 | self.ip_showtb = __IPYTHON__.showtraceback |
|
69 | 163 | self.ip_ns = __IPYTHON__.user_ns |
|
70 |
self.ip_color |
|
|
71 | self.colorize = Parser().format | |
|
164 | self.ip_colorize = __IPYTHON__.pycolorize | |
|
72 | 165 | |
|
73 | 166 | # load user data and initialize data structures |
|
74 | 167 | self.reload() |
|
75 | 168 | |
|
76 | 169 | def reload(self): |
|
77 | 170 | """Reload source from disk and initialize state.""" |
|
78 | 171 | # read data and parse into blocks |
|
79 |
|
|
|
80 | self.src = fobj.read() | |
|
81 | fobj.close() | |
|
82 | src_blocks = [b.strip() for b in self.re_pause.split(self.src) if b] | |
|
83 | self._silent = [bool(self.re_silent.findall(b)) for b in src_blocks] | |
|
84 | self._auto = [bool(self.re_auto.findall(b)) for b in src_blocks] | |
|
85 | # strip out the 'auto' markers | |
|
86 | src_b = [] | |
|
172 | self.src = file_read(self.fname) | |
|
173 | src_b = [b.strip() for b in self.re_stop.split(self.src) if b] | |
|
174 | self._silent = [bool(self.re_silent.findall(b)) for b in src_b] | |
|
175 | self._auto = [bool(self.re_auto.findall(b)) for b in src_b] | |
|
176 | ||
|
177 | # if auto_all is not given (def. None), we read it from the file | |
|
178 | if self.auto_all is None: | |
|
179 | self.auto_all = bool(self.re_auto_all.findall(src_b[0])) | |
|
180 | else: | |
|
181 | self.auto_all = bool(self.auto_all) | |
|
182 | ||
|
183 | # Clean the sources from all markup so it doesn't get displayed when | |
|
184 | # running the demo | |
|
185 | src_blocks = [] | |
|
87 | 186 | auto_strip = lambda s: self.re_auto.sub('',s) |
|
88 |
for i,b in enumerate(src_b |
|
|
187 | for i,b in enumerate(src_b): | |
|
89 | 188 | if self._auto[i]: |
|
90 | src_b.append(auto_strip(b)) | |
|
189 | src_blocks.append(auto_strip(b)) | |
|
91 | 190 | else: |
|
92 | src_b.append(b) | |
|
93 | self.nblocks = len(src_b) | |
|
94 | self.src_blocks = src_b | |
|
95 | ||
|
96 | # try to colorize blocks | |
|
97 | col_scheme = self.ip_colors | |
|
98 | self.src_blocks_colored = [self.colorize(s_blk,'str',col_scheme) | |
|
99 | for s_blk in self.src_blocks] | |
|
191 | src_blocks.append(b) | |
|
192 | # remove the auto_all marker | |
|
193 | src_blocks[0] = self.re_auto_all.sub('',src_blocks[0]) | |
|
194 | ||
|
195 | self.nblocks = len(src_blocks) | |
|
196 | self.src_blocks = src_blocks | |
|
197 | ||
|
198 | # also build syntax-highlighted source | |
|
199 | self.src_blocks_colored = map(self.ip_colorize,self.src_blocks) | |
|
200 | ||
|
100 | 201 | # ensure clean namespace and seek offset |
|
101 | 202 | self.reset() |
|
102 | 203 | |
|
103 | 204 | def reset(self): |
|
104 | 205 | """Reset the namespace and seek pointer to restart the demo""" |
|
105 | 206 | self.user_ns = {} |
|
106 | 207 | self.finished = False |
|
107 | 208 | self.block_index = 0 |
|
108 | 209 | |
|
109 | def again(self): | |
|
110 | """Repeat the last block""" | |
|
111 | self.block_index -= 1 | |
|
112 | self.finished = False | |
|
113 | self() | |
|
114 | ||
|
115 | 210 | def _validate_index(self,index): |
|
116 | 211 | if index<0 or index>=self.nblocks: |
|
117 | 212 | raise ValueError('invalid block index %s' % index) |
|
118 | 213 | |
|
119 | 214 | def seek(self,index): |
|
120 | 215 | """Move the current seek pointer to the given block""" |
|
121 | 216 | self._validate_index(index) |
|
122 | 217 | self.block_index = index |
|
123 | 218 | self.finished = False |
|
124 | 219 | |
|
220 | def back(self,num=1): | |
|
221 | """Move the seek pointer back num blocks (default is 1).""" | |
|
222 | self.seek(self.block_index-num) | |
|
223 | ||
|
224 | def jump(self,num): | |
|
225 | """Jump a given number of blocks relative to the current one.""" | |
|
226 | self.seek(self.block_index+num) | |
|
227 | ||
|
228 | def again(self): | |
|
229 | """Move the seek pointer back one block and re-execute.""" | |
|
230 | self.back(1) | |
|
231 | self() | |
|
232 | ||
|
125 | 233 | def show(self,index=None): |
|
126 | 234 | """Show a single block on screen""" |
|
127 | 235 | if index is None: |
|
128 | 236 | if self.finished: |
|
129 | 237 | print 'Demo finished. Use reset() if you want to rerun it.' |
|
130 | 238 | return |
|
131 | 239 | index = self.block_index |
|
132 | 240 | else: |
|
133 | 241 | self._validate_index(index) |
|
134 | 242 | print marquee('<%s> block # %s (%s remaining)' % |
|
135 | 243 | (self.fname,index,self.nblocks-index-1)) |
|
136 | 244 | print self.src_blocks_colored[index], |
|
137 | 245 | |
|
138 | 246 | def show_all(self): |
|
139 | 247 | """Show entire demo on screen, block by block""" |
|
140 | 248 | |
|
141 | 249 | fname = self.fname |
|
142 | 250 | nblocks = self.nblocks |
|
143 | 251 | silent = self._silent |
|
144 | 252 | for index,block in enumerate(self.src_blocks_colored): |
|
145 | 253 | if silent[index]: |
|
146 | 254 | print marquee('<%s> SILENT block # %s (%s remaining)' % |
|
147 | 255 | (fname,index,nblocks-index-1)) |
|
148 | 256 | else: |
|
149 | 257 | print marquee('<%s> block # %s (%s remaining)' % |
|
150 | 258 | (fname,index,nblocks-index-1)) |
|
151 | 259 | print block, |
|
152 | 260 | |
|
153 | 261 | def __call__(self,index=None): |
|
154 | 262 | """run a block of the demo. |
|
155 | 263 | |
|
156 | 264 | If index is given, it should be an integer >=1 and <= nblocks. This |
|
157 | 265 | means that the calling convention is one off from typical Python |
|
158 | 266 | lists. The reason for the inconsistency is that the demo always |
|
159 | 267 | prints 'Block n/N, and N is the total, so it would be very odd to use |
|
160 | 268 | zero-indexing here.""" |
|
161 | 269 | |
|
162 | 270 | if index is None and self.finished: |
|
163 | 271 | print 'Demo finished. Use reset() if you want to rerun it.' |
|
164 | 272 | return |
|
165 | 273 | if index is None: |
|
166 | 274 | index = self.block_index |
|
167 | 275 | self._validate_index(index) |
|
168 | 276 | try: |
|
169 | 277 | next_block = self.src_blocks[index] |
|
170 | 278 | self.block_index += 1 |
|
171 | 279 | if self._silent[index]: |
|
172 | 280 | print marquee('Executing silent block # %s (%s remaining)' % |
|
173 | 281 | (index,self.nblocks-index-1)) |
|
174 | 282 | else: |
|
175 | 283 | self.show(index) |
|
176 | if self.auto or self._auto[index]: | |
|
284 | if self.auto_all or self._auto[index]: | |
|
177 | 285 | print marquee('output') |
|
178 | 286 | else: |
|
179 | 287 | print marquee('Press <q> to quit, <Enter> to execute...'), |
|
180 | 288 | ans = raw_input().strip() |
|
181 | 289 | if ans: |
|
182 | 290 | print marquee('Block NOT executed') |
|
183 | 291 | return |
|
184 | 292 | try: |
|
185 | 293 | save_argv = sys.argv |
|
186 | 294 | sys.argv = self.sys_argv |
|
187 | 295 | exec next_block in self.user_ns |
|
188 | 296 | finally: |
|
189 | 297 | sys.argv = save_argv |
|
190 | 298 | |
|
191 | 299 | except: |
|
192 | 300 | self.ip_showtb(filename=self.fname) |
|
193 | 301 | else: |
|
194 | 302 | self.ip_ns.update(self.user_ns) |
|
195 | 303 | |
|
196 | 304 | if self.block_index == self.nblocks: |
|
197 | 305 | |
|
198 | 306 | print marquee(' END OF DEMO ') |
|
199 | 307 | print marquee('Use reset() if you want to rerun it.') |
|
200 | 308 | self.finished = True |
|
201 | 309 |
@@ -1,1578 +1,1601 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | General purpose utilities. |
|
4 | 4 | |
|
5 | 5 | This is a grab-bag of stuff I find useful in most programs I write. Some of |
|
6 | 6 | these things are also convenient when working at the command line. |
|
7 | 7 | |
|
8 |
$Id: genutils.py |
|
|
8 | $Id: genutils.py 908 2005-09-26 16:05:48Z fperez $""" | |
|
9 | 9 | |
|
10 | 10 | #***************************************************************************** |
|
11 | 11 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
12 | 12 | # |
|
13 | 13 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | 14 | # the file COPYING, distributed as part of this software. |
|
15 | 15 | #***************************************************************************** |
|
16 | 16 | |
|
17 | 17 | from __future__ import generators # 2.2 compatibility |
|
18 | 18 | |
|
19 | 19 | from IPython import Release |
|
20 | 20 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
21 | 21 | __license__ = Release.license |
|
22 | 22 | |
|
23 | 23 | #**************************************************************************** |
|
24 | 24 | # required modules |
|
25 | 25 | import __main__ |
|
26 | 26 | import types,commands,time,sys,os,re,shutil |
|
27 | 27 | import shlex |
|
28 | 28 | import tempfile |
|
29 | 29 | from IPython.Itpl import Itpl,itpl,printpl |
|
30 | 30 | from IPython import DPyGetOpt |
|
31 | 31 | |
|
32 | 32 | # Build objects which appeared in Python 2.3 for 2.2, to make ipython |
|
33 | 33 | # 2.2-friendly |
|
34 | 34 | try: |
|
35 | 35 | basestring |
|
36 | 36 | except NameError: |
|
37 | 37 | import types |
|
38 | 38 | basestring = (types.StringType, types.UnicodeType) |
|
39 | 39 | True = 1==1 |
|
40 | 40 | False = 1==0 |
|
41 | 41 | |
|
42 | 42 | def enumerate(obj): |
|
43 | 43 | i = -1 |
|
44 | 44 | for item in obj: |
|
45 | 45 | i += 1 |
|
46 | 46 | yield i, item |
|
47 | 47 | |
|
48 | 48 | # add these to the builtin namespace, so that all modules find them |
|
49 | 49 | import __builtin__ |
|
50 | 50 | __builtin__.basestring = basestring |
|
51 | 51 | __builtin__.True = True |
|
52 | 52 | __builtin__.False = False |
|
53 | 53 | __builtin__.enumerate = enumerate |
|
54 | 54 | |
|
55 | 55 | # Try to use shlex.split for converting an input string into a sys.argv-type |
|
56 | 56 | # list. This appeared in Python 2.3, so here's a quick backport for 2.2. |
|
57 | 57 | try: |
|
58 | 58 | shlex_split = shlex.split |
|
59 | 59 | except AttributeError: |
|
60 | 60 | _quotesre = re.compile(r'[\'"](.*)[\'"]') |
|
61 | 61 | _wordchars = ('abcdfeghijklmnopqrstuvwxyz' |
|
62 | 62 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.~*?' |
|
63 | 63 | 'ßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' |
|
64 | 64 | 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ%s' |
|
65 | 65 | % os.sep) |
|
66 | 66 | |
|
67 | 67 | def shlex_split(s): |
|
68 | 68 | """Simplified backport to Python 2.2 of shlex.split(). |
|
69 | 69 | |
|
70 | 70 | This is a quick and dirty hack, since the shlex module under 2.2 lacks |
|
71 | 71 | several of the features needed to really match the functionality of |
|
72 | 72 | shlex.split() in 2.3.""" |
|
73 | 73 | |
|
74 | 74 | lex = shlex.shlex(StringIO(s)) |
|
75 | 75 | # Try to get options, extensions and path separators as characters |
|
76 | 76 | lex.wordchars = _wordchars |
|
77 | 77 | lex.commenters = '' |
|
78 | 78 | # Make a list out of the lexer by hand, since in 2.2 it's not an |
|
79 | 79 | # iterator. |
|
80 | 80 | lout = [] |
|
81 | 81 | while 1: |
|
82 | 82 | token = lex.get_token() |
|
83 | 83 | if token == '': |
|
84 | 84 | break |
|
85 | 85 | # Try to handle quoted tokens correctly |
|
86 | 86 | quotes = _quotesre.match(token) |
|
87 | 87 | if quotes: |
|
88 | 88 | token = quotes.group(1) |
|
89 | 89 | lout.append(token) |
|
90 | 90 | return lout |
|
91 | 91 | |
|
92 | 92 | #**************************************************************************** |
|
93 | 93 | # Exceptions |
|
94 | 94 | class Error(Exception): |
|
95 | 95 | """Base class for exceptions in this module.""" |
|
96 | 96 | pass |
|
97 | 97 | |
|
98 | 98 | #---------------------------------------------------------------------------- |
|
99 | 99 | class IOStream: |
|
100 | 100 | def __init__(self,stream,fallback): |
|
101 | 101 | if not hasattr(stream,'write') or not hasattr(stream,'flush'): |
|
102 | 102 | stream = fallback |
|
103 | 103 | self.stream = stream |
|
104 | 104 | self._swrite = stream.write |
|
105 | 105 | self.flush = stream.flush |
|
106 | 106 | |
|
107 | 107 | def write(self,data): |
|
108 | 108 | try: |
|
109 | 109 | self._swrite(data) |
|
110 | 110 | except: |
|
111 | 111 | try: |
|
112 | 112 | # print handles some unicode issues which may trip a plain |
|
113 | 113 | # write() call. Attempt to emulate write() by using a |
|
114 | 114 | # trailing comma |
|
115 | 115 | print >> self.stream, data, |
|
116 | 116 | except: |
|
117 | 117 | # if we get here, something is seriously broken. |
|
118 | 118 | print >> sys.stderr, \ |
|
119 | 119 | 'ERROR - failed to write data to stream:', stream |
|
120 | 120 | |
|
121 | 121 | class IOTerm: |
|
122 | 122 | """ Term holds the file or file-like objects for handling I/O operations. |
|
123 | 123 | |
|
124 | 124 | These are normally just sys.stdin, sys.stdout and sys.stderr but for |
|
125 | 125 | Windows they can can replaced to allow editing the strings before they are |
|
126 | 126 | displayed.""" |
|
127 | 127 | |
|
128 | 128 | # In the future, having IPython channel all its I/O operations through |
|
129 | 129 | # this class will make it easier to embed it into other environments which |
|
130 | 130 | # are not a normal terminal (such as a GUI-based shell) |
|
131 | 131 | def __init__(self,cin=None,cout=None,cerr=None): |
|
132 | 132 | self.cin = IOStream(cin,sys.stdin) |
|
133 | 133 | self.cout = IOStream(cout,sys.stdout) |
|
134 | 134 | self.cerr = IOStream(cerr,sys.stderr) |
|
135 | 135 | |
|
136 | 136 | # Global variable to be used for all I/O |
|
137 | 137 | Term = IOTerm() |
|
138 | 138 | |
|
139 | 139 | # Windows-specific code to load Gary Bishop's readline and configure it |
|
140 | 140 | # automatically for the users |
|
141 | 141 | # Note: os.name on cygwin returns posix, so this should only pick up 'native' |
|
142 | 142 | # windows. Cygwin returns 'cygwin' for sys.platform. |
|
143 | 143 | if os.name == 'nt': |
|
144 | 144 | try: |
|
145 | 145 | import readline |
|
146 | 146 | except ImportError: |
|
147 | 147 | pass |
|
148 | 148 | else: |
|
149 | 149 | try: |
|
150 | 150 | _out = readline.GetOutputFile() |
|
151 | 151 | except AttributeError: |
|
152 | 152 | pass |
|
153 | 153 | else: |
|
154 | 154 | # Remake Term to use the readline i/o facilities |
|
155 | 155 | Term = IOTerm(cout=_out,cerr=_out) |
|
156 | 156 | del _out |
|
157 | 157 | |
|
158 | 158 | #**************************************************************************** |
|
159 | 159 | # Generic warning/error printer, used by everything else |
|
160 | 160 | def warn(msg,level=2,exit_val=1): |
|
161 | 161 | """Standard warning printer. Gives formatting consistency. |
|
162 | 162 | |
|
163 | 163 | Output is sent to Term.cerr (sys.stderr by default). |
|
164 | 164 | |
|
165 | 165 | Options: |
|
166 | 166 | |
|
167 | 167 | -level(2): allows finer control: |
|
168 | 168 | 0 -> Do nothing, dummy function. |
|
169 | 169 | 1 -> Print message. |
|
170 | 170 | 2 -> Print 'WARNING:' + message. (Default level). |
|
171 | 171 | 3 -> Print 'ERROR:' + message. |
|
172 | 172 | 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val). |
|
173 | 173 | |
|
174 | 174 | -exit_val (1): exit value returned by sys.exit() for a level 4 |
|
175 | 175 | warning. Ignored for all other levels.""" |
|
176 | 176 | |
|
177 | 177 | if level>0: |
|
178 | 178 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
179 | 179 | print >> Term.cerr, '%s%s' % (header[level],msg) |
|
180 | 180 | if level == 4: |
|
181 | 181 | print >> Term.cerr,'Exiting.\n' |
|
182 | 182 | sys.exit(exit_val) |
|
183 | 183 | |
|
184 | 184 | def info(msg): |
|
185 | 185 | """Equivalent to warn(msg,level=1).""" |
|
186 | 186 | |
|
187 | 187 | warn(msg,level=1) |
|
188 | 188 | |
|
189 | 189 | def error(msg): |
|
190 | 190 | """Equivalent to warn(msg,level=3).""" |
|
191 | 191 | |
|
192 | 192 | warn(msg,level=3) |
|
193 | 193 | |
|
194 | 194 | def fatal(msg,exit_val=1): |
|
195 | 195 | """Equivalent to warn(msg,exit_val=exit_val,level=4).""" |
|
196 | 196 | |
|
197 | 197 | warn(msg,exit_val=exit_val,level=4) |
|
198 | 198 | |
|
199 | 199 | #---------------------------------------------------------------------------- |
|
200 | 200 | StringTypes = types.StringTypes |
|
201 | 201 | |
|
202 | 202 | # Basic timing functionality |
|
203 | 203 | |
|
204 | 204 | # If possible (Unix), use the resource module instead of time.clock() |
|
205 | 205 | try: |
|
206 | 206 | import resource |
|
207 | 207 | def clock(): |
|
208 | 208 | """clock() -> floating point number |
|
209 | 209 | |
|
210 | 210 | Return the CPU time in seconds (user time only, system time is |
|
211 | 211 | ignored) since the start of the process. This is done via a call to |
|
212 | 212 | resource.getrusage, so it avoids the wraparound problems in |
|
213 | 213 | time.clock().""" |
|
214 | 214 | |
|
215 | 215 | return resource.getrusage(resource.RUSAGE_SELF)[0] |
|
216 | 216 | |
|
217 | 217 | def clock2(): |
|
218 | 218 | """clock2() -> (t_user,t_system) |
|
219 | 219 | |
|
220 | 220 | Similar to clock(), but return a tuple of user/system times.""" |
|
221 | 221 | return resource.getrusage(resource.RUSAGE_SELF)[:2] |
|
222 | 222 | |
|
223 | 223 | except ImportError: |
|
224 | 224 | clock = time.clock |
|
225 | 225 | def clock2(): |
|
226 | 226 | """Under windows, system CPU time can't be measured. |
|
227 | 227 | |
|
228 | 228 | This just returns clock() and zero.""" |
|
229 | 229 | return time.clock(),0.0 |
|
230 | 230 | |
|
231 | 231 | def timings_out(reps,func,*args,**kw): |
|
232 | 232 | """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) |
|
233 | 233 | |
|
234 | 234 | Execute a function reps times, return a tuple with the elapsed total |
|
235 | 235 | CPU time in seconds, the time per call and the function's output. |
|
236 | 236 | |
|
237 | 237 | Under Unix, the return value is the sum of user+system time consumed by |
|
238 | 238 | the process, computed via the resource module. This prevents problems |
|
239 | 239 | related to the wraparound effect which the time.clock() function has. |
|
240 | 240 | |
|
241 | 241 | Under Windows the return value is in wall clock seconds. See the |
|
242 | 242 | documentation for the time module for more details.""" |
|
243 | 243 | |
|
244 | 244 | reps = int(reps) |
|
245 | 245 | assert reps >=1, 'reps must be >= 1' |
|
246 | 246 | if reps==1: |
|
247 | 247 | start = clock() |
|
248 | 248 | out = func(*args,**kw) |
|
249 | 249 | tot_time = clock()-start |
|
250 | 250 | else: |
|
251 | 251 | rng = xrange(reps-1) # the last time is executed separately to store output |
|
252 | 252 | start = clock() |
|
253 | 253 | for dummy in rng: func(*args,**kw) |
|
254 | 254 | out = func(*args,**kw) # one last time |
|
255 | 255 | tot_time = clock()-start |
|
256 | 256 | av_time = tot_time / reps |
|
257 | 257 | return tot_time,av_time,out |
|
258 | 258 | |
|
259 | 259 | def timings(reps,func,*args,**kw): |
|
260 | 260 | """timings(reps,func,*args,**kw) -> (t_total,t_per_call) |
|
261 | 261 | |
|
262 | 262 | Execute a function reps times, return a tuple with the elapsed total CPU |
|
263 | 263 | time in seconds and the time per call. These are just the first two values |
|
264 | 264 | in timings_out().""" |
|
265 | 265 | |
|
266 | 266 | return timings_out(reps,func,*args,**kw)[0:2] |
|
267 | 267 | |
|
268 | 268 | def timing(func,*args,**kw): |
|
269 | 269 | """timing(func,*args,**kw) -> t_total |
|
270 | 270 | |
|
271 | 271 | Execute a function once, return the elapsed total CPU time in |
|
272 | 272 | seconds. This is just the first value in timings_out().""" |
|
273 | 273 | |
|
274 | 274 | return timings_out(1,func,*args,**kw)[0] |
|
275 | 275 | |
|
276 | 276 | #**************************************************************************** |
|
277 | 277 | # file and system |
|
278 | 278 | |
|
279 | 279 | def system(cmd,verbose=0,debug=0,header=''): |
|
280 | 280 | """Execute a system command, return its exit status. |
|
281 | 281 | |
|
282 | 282 | Options: |
|
283 | 283 | |
|
284 | 284 | - verbose (0): print the command to be executed. |
|
285 | 285 | |
|
286 | 286 | - debug (0): only print, do not actually execute. |
|
287 | 287 | |
|
288 | 288 | - header (''): Header to print on screen prior to the executed command (it |
|
289 | 289 | is only prepended to the command, no newlines are added). |
|
290 | 290 | |
|
291 | 291 | Note: a stateful version of this function is available through the |
|
292 | 292 | SystemExec class.""" |
|
293 | 293 | |
|
294 | 294 | stat = 0 |
|
295 | 295 | if verbose or debug: print header+cmd |
|
296 | 296 | sys.stdout.flush() |
|
297 | 297 | if not debug: stat = os.system(cmd) |
|
298 | 298 | return stat |
|
299 | 299 | |
|
300 | 300 | def shell(cmd,verbose=0,debug=0,header=''): |
|
301 | 301 | """Execute a command in the system shell, always return None. |
|
302 | 302 | |
|
303 | 303 | Options: |
|
304 | 304 | |
|
305 | 305 | - verbose (0): print the command to be executed. |
|
306 | 306 | |
|
307 | 307 | - debug (0): only print, do not actually execute. |
|
308 | 308 | |
|
309 | 309 | - header (''): Header to print on screen prior to the executed command (it |
|
310 | 310 | is only prepended to the command, no newlines are added). |
|
311 | 311 | |
|
312 | 312 | Note: this is similar to genutils.system(), but it returns None so it can |
|
313 | 313 | be conveniently used in interactive loops without getting the return value |
|
314 | 314 | (typically 0) printed many times.""" |
|
315 | 315 | |
|
316 | 316 | stat = 0 |
|
317 | 317 | if verbose or debug: print header+cmd |
|
318 | 318 | # flush stdout so we don't mangle python's buffering |
|
319 | 319 | sys.stdout.flush() |
|
320 | 320 | if not debug: |
|
321 | 321 | os.system(cmd) |
|
322 | 322 | |
|
323 | 323 | def getoutput(cmd,verbose=0,debug=0,header='',split=0): |
|
324 | 324 | """Dummy substitute for perl's backquotes. |
|
325 | 325 | |
|
326 | 326 | Executes a command and returns the output. |
|
327 | 327 | |
|
328 | 328 | Accepts the same arguments as system(), plus: |
|
329 | 329 | |
|
330 | 330 | - split(0): if true, the output is returned as a list split on newlines. |
|
331 | 331 | |
|
332 | 332 | Note: a stateful version of this function is available through the |
|
333 | 333 | SystemExec class.""" |
|
334 | 334 | |
|
335 | 335 | if verbose or debug: print header+cmd |
|
336 | 336 | if not debug: |
|
337 | 337 | output = commands.getoutput(cmd) |
|
338 | 338 | if split: |
|
339 | 339 | return output.split('\n') |
|
340 | 340 | else: |
|
341 | 341 | return output |
|
342 | 342 | |
|
343 | 343 | def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): |
|
344 | 344 | """Return (standard output,standard error) of executing cmd in a shell. |
|
345 | 345 | |
|
346 | 346 | Accepts the same arguments as system(), plus: |
|
347 | 347 | |
|
348 | 348 | - split(0): if true, each of stdout/err is returned as a list split on |
|
349 | 349 | newlines. |
|
350 | 350 | |
|
351 | 351 | Note: a stateful version of this function is available through the |
|
352 | 352 | SystemExec class.""" |
|
353 | 353 | |
|
354 | 354 | if verbose or debug: print header+cmd |
|
355 | 355 | if not cmd: |
|
356 | 356 | if split: |
|
357 | 357 | return [],[] |
|
358 | 358 | else: |
|
359 | 359 | return '','' |
|
360 | 360 | if not debug: |
|
361 | 361 | pin,pout,perr = os.popen3(cmd) |
|
362 | 362 | tout = pout.read().rstrip() |
|
363 | 363 | terr = perr.read().rstrip() |
|
364 | 364 | pin.close() |
|
365 | 365 | pout.close() |
|
366 | 366 | perr.close() |
|
367 | 367 | if split: |
|
368 | 368 | return tout.split('\n'),terr.split('\n') |
|
369 | 369 | else: |
|
370 | 370 | return tout,terr |
|
371 | 371 | |
|
372 | 372 | # for compatibility with older naming conventions |
|
373 | 373 | xsys = system |
|
374 | 374 | bq = getoutput |
|
375 | 375 | |
|
376 | 376 | class SystemExec: |
|
377 | 377 | """Access the system and getoutput functions through a stateful interface. |
|
378 | 378 | |
|
379 | 379 | Note: here we refer to the system and getoutput functions from this |
|
380 | 380 | library, not the ones from the standard python library. |
|
381 | 381 | |
|
382 | 382 | This class offers the system and getoutput functions as methods, but the |
|
383 | 383 | verbose, debug and header parameters can be set for the instance (at |
|
384 | 384 | creation time or later) so that they don't need to be specified on each |
|
385 | 385 | call. |
|
386 | 386 | |
|
387 | 387 | For efficiency reasons, there's no way to override the parameters on a |
|
388 | 388 | per-call basis other than by setting instance attributes. If you need |
|
389 | 389 | local overrides, it's best to directly call system() or getoutput(). |
|
390 | 390 | |
|
391 | 391 | The following names are provided as alternate options: |
|
392 | 392 | - xsys: alias to system |
|
393 | 393 | - bq: alias to getoutput |
|
394 | 394 | |
|
395 | 395 | An instance can then be created as: |
|
396 | 396 | >>> sysexec = SystemExec(verbose=1,debug=0,header='Calling: ') |
|
397 | 397 | |
|
398 | 398 | And used as: |
|
399 | 399 | >>> sysexec.xsys('pwd') |
|
400 | 400 | >>> dirlist = sysexec.bq('ls -l') |
|
401 | 401 | """ |
|
402 | 402 | |
|
403 | 403 | def __init__(self,verbose=0,debug=0,header='',split=0): |
|
404 | 404 | """Specify the instance's values for verbose, debug and header.""" |
|
405 | 405 | setattr_list(self,'verbose debug header split') |
|
406 | 406 | |
|
407 | 407 | def system(self,cmd): |
|
408 | 408 | """Stateful interface to system(), with the same keyword parameters.""" |
|
409 | 409 | |
|
410 | 410 | system(cmd,self.verbose,self.debug,self.header) |
|
411 | 411 | |
|
412 | 412 | def shell(self,cmd): |
|
413 | 413 | """Stateful interface to shell(), with the same keyword parameters.""" |
|
414 | 414 | |
|
415 | 415 | shell(cmd,self.verbose,self.debug,self.header) |
|
416 | 416 | |
|
417 | 417 | xsys = system # alias |
|
418 | 418 | |
|
419 | 419 | def getoutput(self,cmd): |
|
420 | 420 | """Stateful interface to getoutput().""" |
|
421 | 421 | |
|
422 | 422 | return getoutput(cmd,self.verbose,self.debug,self.header,self.split) |
|
423 | 423 | |
|
424 | 424 | def getoutputerror(self,cmd): |
|
425 | 425 | """Stateful interface to getoutputerror().""" |
|
426 | 426 | |
|
427 | 427 | return getoutputerror(cmd,self.verbose,self.debug,self.header,self.split) |
|
428 | 428 | |
|
429 | 429 | bq = getoutput # alias |
|
430 | 430 | |
|
431 | 431 | #----------------------------------------------------------------------------- |
|
432 | 432 | def mutex_opts(dict,ex_op): |
|
433 | 433 | """Check for presence of mutually exclusive keys in a dict. |
|
434 | 434 | |
|
435 | 435 | Call: mutex_opts(dict,[[op1a,op1b],[op2a,op2b]...]""" |
|
436 | 436 | for op1,op2 in ex_op: |
|
437 | 437 | if op1 in dict and op2 in dict: |
|
438 | 438 | raise ValueError,'\n*** ERROR in Arguments *** '\ |
|
439 | 439 | 'Options '+op1+' and '+op2+' are mutually exclusive.' |
|
440 | 440 | |
|
441 | 441 | #----------------------------------------------------------------------------- |
|
442 | def get_py_filename(name): | |
|
443 | """Return a valid python filename in the current directory. | |
|
444 | ||
|
445 | If the given name is not a file, it adds '.py' and searches again. | |
|
446 | Raises IOError with an informative message if the file isn't found.""" | |
|
447 | ||
|
448 | name = os.path.expanduser(name) | |
|
449 | if not os.path.isfile(name) and not name.endswith('.py'): | |
|
450 | name += '.py' | |
|
451 | if os.path.isfile(name): | |
|
452 | return name | |
|
453 | else: | |
|
454 | raise IOError,'File `%s` not found.' % name | |
|
455 | ||
|
456 | #----------------------------------------------------------------------------- | |
|
442 | 457 | def filefind(fname,alt_dirs = None): |
|
443 | 458 | """Return the given filename either in the current directory, if it |
|
444 | 459 | exists, or in a specified list of directories. |
|
445 | 460 | |
|
446 | 461 | ~ expansion is done on all file and directory names. |
|
447 | 462 | |
|
448 | 463 | Upon an unsuccessful search, raise an IOError exception.""" |
|
449 | 464 | |
|
450 | 465 | if alt_dirs is None: |
|
451 | 466 | try: |
|
452 | 467 | alt_dirs = get_home_dir() |
|
453 | 468 | except HomeDirError: |
|
454 | 469 | alt_dirs = os.getcwd() |
|
455 | 470 | search = [fname] + list_strings(alt_dirs) |
|
456 | 471 | search = map(os.path.expanduser,search) |
|
457 | 472 | #print 'search list for',fname,'list:',search # dbg |
|
458 | 473 | fname = search[0] |
|
459 | 474 | if os.path.isfile(fname): |
|
460 | 475 | return fname |
|
461 | 476 | for direc in search[1:]: |
|
462 | 477 | testname = os.path.join(direc,fname) |
|
463 | 478 | #print 'testname',testname # dbg |
|
464 | 479 | if os.path.isfile(testname): |
|
465 | 480 | return testname |
|
466 | 481 | raise IOError,'File' + `fname` + \ |
|
467 | 482 | ' not found in current or supplied directories:' + `alt_dirs` |
|
468 | 483 | |
|
469 | 484 | #---------------------------------------------------------------------------- |
|
485 | def file_read(filename): | |
|
486 | """Read a file and close it. Returns the file source.""" | |
|
487 | fobj=open(filename,'r'); | |
|
488 | source = fobj.read(); | |
|
489 | fobj.close() | |
|
490 | return source | |
|
491 | ||
|
492 | #---------------------------------------------------------------------------- | |
|
470 | 493 | def target_outdated(target,deps): |
|
471 | 494 | """Determine whether a target is out of date. |
|
472 | 495 | |
|
473 | 496 | target_outdated(target,deps) -> 1/0 |
|
474 | 497 | |
|
475 | 498 | deps: list of filenames which MUST exist. |
|
476 | 499 | target: single filename which may or may not exist. |
|
477 | 500 | |
|
478 | 501 | If target doesn't exist or is older than any file listed in deps, return |
|
479 | 502 | true, otherwise return false. |
|
480 | 503 | """ |
|
481 | 504 | try: |
|
482 | 505 | target_time = os.path.getmtime(target) |
|
483 | 506 | except os.error: |
|
484 | 507 | return 1 |
|
485 | 508 | for dep in deps: |
|
486 | 509 | dep_time = os.path.getmtime(dep) |
|
487 | 510 | if dep_time > target_time: |
|
488 | 511 | #print "For target",target,"Dep failed:",dep # dbg |
|
489 | 512 | #print "times (dep,tar):",dep_time,target_time # dbg |
|
490 | 513 | return 1 |
|
491 | 514 | return 0 |
|
492 | 515 | |
|
493 | 516 | #----------------------------------------------------------------------------- |
|
494 | 517 | def target_update(target,deps,cmd): |
|
495 | 518 | """Update a target with a given command given a list of dependencies. |
|
496 | 519 | |
|
497 | 520 | target_update(target,deps,cmd) -> runs cmd if target is outdated. |
|
498 | 521 | |
|
499 | 522 | This is just a wrapper around target_outdated() which calls the given |
|
500 | 523 | command if target is outdated.""" |
|
501 | 524 | |
|
502 | 525 | if target_outdated(target,deps): |
|
503 | 526 | xsys(cmd) |
|
504 | 527 | |
|
505 | 528 | #---------------------------------------------------------------------------- |
|
506 | 529 | def unquote_ends(istr): |
|
507 | 530 | """Remove a single pair of quotes from the endpoints of a string.""" |
|
508 | 531 | |
|
509 | 532 | if not istr: |
|
510 | 533 | return istr |
|
511 | 534 | if (istr[0]=="'" and istr[-1]=="'") or \ |
|
512 | 535 | (istr[0]=='"' and istr[-1]=='"'): |
|
513 | 536 | return istr[1:-1] |
|
514 | 537 | else: |
|
515 | 538 | return istr |
|
516 | 539 | |
|
517 | 540 | #---------------------------------------------------------------------------- |
|
518 | 541 | def process_cmdline(argv,names=[],defaults={},usage=''): |
|
519 | 542 | """ Process command-line options and arguments. |
|
520 | 543 | |
|
521 | 544 | Arguments: |
|
522 | 545 | |
|
523 | 546 | - argv: list of arguments, typically sys.argv. |
|
524 | 547 | |
|
525 | 548 | - names: list of option names. See DPyGetOpt docs for details on options |
|
526 | 549 | syntax. |
|
527 | 550 | |
|
528 | 551 | - defaults: dict of default values. |
|
529 | 552 | |
|
530 | 553 | - usage: optional usage notice to print if a wrong argument is passed. |
|
531 | 554 | |
|
532 | 555 | Return a dict of options and a list of free arguments.""" |
|
533 | 556 | |
|
534 | 557 | getopt = DPyGetOpt.DPyGetOpt() |
|
535 | 558 | getopt.setIgnoreCase(0) |
|
536 | 559 | getopt.parseConfiguration(names) |
|
537 | 560 | |
|
538 | 561 | try: |
|
539 | 562 | getopt.processArguments(argv) |
|
540 | 563 | except: |
|
541 | 564 | print usage |
|
542 | 565 | warn(`sys.exc_value`,level=4) |
|
543 | 566 | |
|
544 | 567 | defaults.update(getopt.optionValues) |
|
545 | 568 | args = getopt.freeValues |
|
546 | 569 | |
|
547 | 570 | return defaults,args |
|
548 | 571 | |
|
549 | 572 | #---------------------------------------------------------------------------- |
|
550 | 573 | def optstr2types(ostr): |
|
551 | 574 | """Convert a string of option names to a dict of type mappings. |
|
552 | 575 | |
|
553 | 576 | optstr2types(str) -> {None:'string_opts',int:'int_opts',float:'float_opts'} |
|
554 | 577 | |
|
555 | 578 | This is used to get the types of all the options in a string formatted |
|
556 | 579 | with the conventions of DPyGetOpt. The 'type' None is used for options |
|
557 | 580 | which are strings (they need no further conversion). This function's main |
|
558 | 581 | use is to get a typemap for use with read_dict(). |
|
559 | 582 | """ |
|
560 | 583 | |
|
561 | 584 | typeconv = {None:'',int:'',float:''} |
|
562 | 585 | typemap = {'s':None,'i':int,'f':float} |
|
563 | 586 | opt_re = re.compile(r'([\w]*)([^:=]*:?=?)([sif]?)') |
|
564 | 587 | |
|
565 | 588 | for w in ostr.split(): |
|
566 | 589 | oname,alias,otype = opt_re.match(w).groups() |
|
567 | 590 | if otype == '' or alias == '!': # simple switches are integers too |
|
568 | 591 | otype = 'i' |
|
569 | 592 | typeconv[typemap[otype]] += oname + ' ' |
|
570 | 593 | return typeconv |
|
571 | 594 | |
|
572 | 595 | #---------------------------------------------------------------------------- |
|
573 | 596 | def read_dict(filename,type_conv=None,**opt): |
|
574 | 597 | |
|
575 | 598 | """Read a dictionary of key=value pairs from an input file, optionally |
|
576 | 599 | performing conversions on the resulting values. |
|
577 | 600 | |
|
578 | 601 | read_dict(filename,type_conv,**opt) -> dict |
|
579 | 602 | |
|
580 | 603 | Only one value per line is accepted, the format should be |
|
581 | 604 | # optional comments are ignored |
|
582 | 605 | key value\n |
|
583 | 606 | |
|
584 | 607 | Args: |
|
585 | 608 | |
|
586 | 609 | - type_conv: A dictionary specifying which keys need to be converted to |
|
587 | 610 | which types. By default all keys are read as strings. This dictionary |
|
588 | 611 | should have as its keys valid conversion functions for strings |
|
589 | 612 | (int,long,float,complex, or your own). The value for each key |
|
590 | 613 | (converter) should be a whitespace separated string containing the names |
|
591 | 614 | of all the entries in the file to be converted using that function. For |
|
592 | 615 | keys to be left alone, use None as the conversion function (only needed |
|
593 | 616 | with purge=1, see below). |
|
594 | 617 | |
|
595 | 618 | - opt: dictionary with extra options as below (default in parens) |
|
596 | 619 | |
|
597 | 620 | purge(0): if set to 1, all keys *not* listed in type_conv are purged out |
|
598 | 621 | of the dictionary to be returned. If purge is going to be used, the |
|
599 | 622 | set of keys to be left as strings also has to be explicitly specified |
|
600 | 623 | using the (non-existent) conversion function None. |
|
601 | 624 | |
|
602 | 625 | fs(None): field separator. This is the key/value separator to be used |
|
603 | 626 | when parsing the file. The None default means any whitespace [behavior |
|
604 | 627 | of string.split()]. |
|
605 | 628 | |
|
606 | 629 | strip(0): if 1, strip string values of leading/trailinig whitespace. |
|
607 | 630 | |
|
608 | 631 | warn(1): warning level if requested keys are not found in file. |
|
609 | 632 | - 0: silently ignore. |
|
610 | 633 | - 1: inform but proceed. |
|
611 | 634 | - 2: raise KeyError exception. |
|
612 | 635 | |
|
613 | 636 | no_empty(0): if 1, remove keys with whitespace strings as a value. |
|
614 | 637 | |
|
615 | 638 | unique([]): list of keys (or space separated string) which can't be |
|
616 | 639 | repeated. If one such key is found in the file, each new instance |
|
617 | 640 | overwrites the previous one. For keys not listed here, the behavior is |
|
618 | 641 | to make a list of all appearances. |
|
619 | 642 | |
|
620 | 643 | Example: |
|
621 | 644 | If the input file test.ini has: |
|
622 | 645 | i 3 |
|
623 | 646 | x 4.5 |
|
624 | 647 | y 5.5 |
|
625 | 648 | s hi ho |
|
626 | 649 | Then: |
|
627 | 650 | |
|
628 | 651 | >>> type_conv={int:'i',float:'x',None:'s'} |
|
629 | 652 | >>> read_dict('test.ini') |
|
630 | 653 | {'i': '3', 's': 'hi ho', 'x': '4.5', 'y': '5.5'} |
|
631 | 654 | >>> read_dict('test.ini',type_conv) |
|
632 | 655 | {'i': 3, 's': 'hi ho', 'x': 4.5, 'y': '5.5'} |
|
633 | 656 | >>> read_dict('test.ini',type_conv,purge=1) |
|
634 | 657 | {'i': 3, 's': 'hi ho', 'x': 4.5} |
|
635 | 658 | """ |
|
636 | 659 | |
|
637 | 660 | # starting config |
|
638 | 661 | opt.setdefault('purge',0) |
|
639 | 662 | opt.setdefault('fs',None) # field sep defaults to any whitespace |
|
640 | 663 | opt.setdefault('strip',0) |
|
641 | 664 | opt.setdefault('warn',1) |
|
642 | 665 | opt.setdefault('no_empty',0) |
|
643 | 666 | opt.setdefault('unique','') |
|
644 | 667 | if type(opt['unique']) in StringTypes: |
|
645 | 668 | unique_keys = qw(opt['unique']) |
|
646 | 669 | elif type(opt['unique']) in (types.TupleType,types.ListType): |
|
647 | 670 | unique_keys = opt['unique'] |
|
648 | 671 | else: |
|
649 | 672 | raise ValueError, 'Unique keys must be given as a string, List or Tuple' |
|
650 | 673 | |
|
651 | 674 | dict = {} |
|
652 | 675 | # first read in table of values as strings |
|
653 | 676 | file = open(filename,'r') |
|
654 | 677 | for line in file.readlines(): |
|
655 | 678 | line = line.strip() |
|
656 | 679 | if len(line) and line[0]=='#': continue |
|
657 | 680 | if len(line)>0: |
|
658 | 681 | lsplit = line.split(opt['fs'],1) |
|
659 | 682 | try: |
|
660 | 683 | key,val = lsplit |
|
661 | 684 | except ValueError: |
|
662 | 685 | key,val = lsplit[0],'' |
|
663 | 686 | key = key.strip() |
|
664 | 687 | if opt['strip']: val = val.strip() |
|
665 | 688 | if val == "''" or val == '""': val = '' |
|
666 | 689 | if opt['no_empty'] and (val=='' or val.isspace()): |
|
667 | 690 | continue |
|
668 | 691 | # if a key is found more than once in the file, build a list |
|
669 | 692 | # unless it's in the 'unique' list. In that case, last found in file |
|
670 | 693 | # takes precedence. User beware. |
|
671 | 694 | try: |
|
672 | 695 | if dict[key] and key in unique_keys: |
|
673 | 696 | dict[key] = val |
|
674 | 697 | elif type(dict[key]) is types.ListType: |
|
675 | 698 | dict[key].append(val) |
|
676 | 699 | else: |
|
677 | 700 | dict[key] = [dict[key],val] |
|
678 | 701 | except KeyError: |
|
679 | 702 | dict[key] = val |
|
680 | 703 | # purge if requested |
|
681 | 704 | if opt['purge']: |
|
682 | 705 | accepted_keys = qwflat(type_conv.values()) |
|
683 | 706 | for key in dict.keys(): |
|
684 | 707 | if key in accepted_keys: continue |
|
685 | 708 | del(dict[key]) |
|
686 | 709 | # now convert if requested |
|
687 | 710 | if type_conv==None: return dict |
|
688 | 711 | conversions = type_conv.keys() |
|
689 | 712 | try: conversions.remove(None) |
|
690 | 713 | except: pass |
|
691 | 714 | for convert in conversions: |
|
692 | 715 | for val in qw(type_conv[convert]): |
|
693 | 716 | try: |
|
694 | 717 | dict[val] = convert(dict[val]) |
|
695 | 718 | except KeyError,e: |
|
696 | 719 | if opt['warn'] == 0: |
|
697 | 720 | pass |
|
698 | 721 | elif opt['warn'] == 1: |
|
699 | 722 | print >>sys.stderr, 'Warning: key',val,\ |
|
700 | 723 | 'not found in file',filename |
|
701 | 724 | elif opt['warn'] == 2: |
|
702 | 725 | raise KeyError,e |
|
703 | 726 | else: |
|
704 | 727 | raise ValueError,'Warning level must be 0,1 or 2' |
|
705 | 728 | |
|
706 | 729 | return dict |
|
707 | 730 | |
|
708 | 731 | #---------------------------------------------------------------------------- |
|
709 | 732 | def flag_calls(func): |
|
710 | 733 | """Wrap a function to detect and flag when it gets called. |
|
711 | 734 | |
|
712 | 735 | This is a decorator which takes a function and wraps it in a function with |
|
713 | 736 | a 'called' attribute. wrapper.called is initialized to False. |
|
714 | 737 | |
|
715 | 738 | The wrapper.called attribute is set to False right before each call to the |
|
716 | 739 | wrapped function, so if the call fails it remains False. After the call |
|
717 | 740 | completes, wrapper.called is set to True and the output is returned. |
|
718 | 741 | |
|
719 | 742 | Testing for truth in wrapper.called allows you to determine if a call to |
|
720 | 743 | func() was attempted and succeeded.""" |
|
721 | 744 | |
|
722 | 745 | def wrapper(*args,**kw): |
|
723 | 746 | wrapper.called = False |
|
724 | 747 | out = func(*args,**kw) |
|
725 | 748 | wrapper.called = True |
|
726 | 749 | return out |
|
727 | 750 | |
|
728 | 751 | wrapper.called = False |
|
729 | 752 | wrapper.__doc__ = func.__doc__ |
|
730 | 753 | return wrapper |
|
731 | 754 | |
|
732 | 755 | #---------------------------------------------------------------------------- |
|
733 | 756 | class HomeDirError(Error): |
|
734 | 757 | pass |
|
735 | 758 | |
|
736 | 759 | def get_home_dir(): |
|
737 | 760 | """Return the closest possible equivalent to a 'home' directory. |
|
738 | 761 | |
|
739 | 762 | We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. |
|
740 | 763 | |
|
741 | 764 | Currently only Posix and NT are implemented, a HomeDirError exception is |
|
742 | 765 | raised for all other OSes. """ |
|
743 | 766 | |
|
744 | 767 | isdir = os.path.isdir |
|
745 | 768 | env = os.environ |
|
746 | 769 | try: |
|
747 | 770 | homedir = env['HOME'] |
|
748 | 771 | if not isdir(homedir): |
|
749 | 772 | # in case a user stuck some string which does NOT resolve to a |
|
750 | 773 | # valid path, it's as good as if we hadn't foud it |
|
751 | 774 | raise KeyError |
|
752 | 775 | return homedir |
|
753 | 776 | except KeyError: |
|
754 | 777 | if os.name == 'posix': |
|
755 | 778 | raise HomeDirError,'undefined $HOME, IPython can not proceed.' |
|
756 | 779 | elif os.name == 'nt': |
|
757 | 780 | # For some strange reason, win9x returns 'nt' for os.name. |
|
758 | 781 | try: |
|
759 | 782 | homedir = os.path.join(env['HOMEDRIVE'],env['HOMEPATH']) |
|
760 | 783 | if not isdir(homedir): |
|
761 | 784 | homedir = os.path.join(env['USERPROFILE']) |
|
762 | 785 | if not isdir(homedir): |
|
763 | 786 | raise HomeDirError |
|
764 | 787 | return homedir |
|
765 | 788 | except: |
|
766 | 789 | try: |
|
767 | 790 | # Use the registry to get the 'My Documents' folder. |
|
768 | 791 | import _winreg as wreg |
|
769 | 792 | key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, |
|
770 | 793 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") |
|
771 | 794 | homedir = wreg.QueryValueEx(key,'Personal')[0] |
|
772 | 795 | key.Close() |
|
773 | 796 | if not isdir(homedir): |
|
774 | 797 | e = ('Invalid "Personal" folder registry key ' |
|
775 | 798 | 'typically "My Documents".\n' |
|
776 | 799 | 'Value: %s\n' |
|
777 | 800 | 'This is not a valid directory on your system.' % |
|
778 | 801 | homedir) |
|
779 | 802 | raise HomeDirError(e) |
|
780 | 803 | return homedir |
|
781 | 804 | except HomeDirError: |
|
782 | 805 | raise |
|
783 | 806 | except: |
|
784 | 807 | return 'C:\\' |
|
785 | 808 | elif os.name == 'dos': |
|
786 | 809 | # Desperate, may do absurd things in classic MacOS. May work under DOS. |
|
787 | 810 | return 'C:\\' |
|
788 | 811 | else: |
|
789 | 812 | raise HomeDirError,'support for your operating system not implemented.' |
|
790 | 813 | |
|
791 | 814 | #**************************************************************************** |
|
792 | 815 | # strings and text |
|
793 | 816 | |
|
794 | 817 | class LSString(str): |
|
795 | 818 | """String derivative with a special access attributes. |
|
796 | 819 | |
|
797 | 820 | These are normal strings, but with the special attributes: |
|
798 | 821 | |
|
799 | 822 | .l (or .list) : value as list (split on newlines). |
|
800 | 823 | .n (or .nlstr): original value (the string itself). |
|
801 | 824 | .s (or .spstr): value as whitespace-separated string. |
|
802 | 825 | |
|
803 | 826 | Any values which require transformations are computed only once and |
|
804 | 827 | cached. |
|
805 | 828 | |
|
806 | 829 | Such strings are very useful to efficiently interact with the shell, which |
|
807 | 830 | typically only understands whitespace-separated options for commands.""" |
|
808 | 831 | |
|
809 | 832 | def get_list(self): |
|
810 | 833 | try: |
|
811 | 834 | return self.__list |
|
812 | 835 | except AttributeError: |
|
813 | 836 | self.__list = self.split('\n') |
|
814 | 837 | return self.__list |
|
815 | 838 | |
|
816 | 839 | l = list = property(get_list) |
|
817 | 840 | |
|
818 | 841 | def get_spstr(self): |
|
819 | 842 | try: |
|
820 | 843 | return self.__spstr |
|
821 | 844 | except AttributeError: |
|
822 | 845 | self.__spstr = self.replace('\n',' ') |
|
823 | 846 | return self.__spstr |
|
824 | 847 | |
|
825 | 848 | s = spstr = property(get_spstr) |
|
826 | 849 | |
|
827 | 850 | def get_nlstr(self): |
|
828 | 851 | return self |
|
829 | 852 | |
|
830 | 853 | n = nlstr = property(get_nlstr) |
|
831 | 854 | |
|
832 | 855 | class SList(list): |
|
833 | 856 | """List derivative with a special access attributes. |
|
834 | 857 | |
|
835 | 858 | These are normal lists, but with the special attributes: |
|
836 | 859 | |
|
837 | 860 | .l (or .list) : value as list (the list itself). |
|
838 | 861 | .n (or .nlstr): value as a string, joined on newlines. |
|
839 | 862 | .s (or .spstr): value as a string, joined on spaces. |
|
840 | 863 | |
|
841 | 864 | Any values which require transformations are computed only once and |
|
842 | 865 | cached.""" |
|
843 | 866 | |
|
844 | 867 | def get_list(self): |
|
845 | 868 | return self |
|
846 | 869 | |
|
847 | 870 | l = list = property(get_list) |
|
848 | 871 | |
|
849 | 872 | def get_spstr(self): |
|
850 | 873 | try: |
|
851 | 874 | return self.__spstr |
|
852 | 875 | except AttributeError: |
|
853 | 876 | self.__spstr = ' '.join(self) |
|
854 | 877 | return self.__spstr |
|
855 | 878 | |
|
856 | 879 | s = spstr = property(get_spstr) |
|
857 | 880 | |
|
858 | 881 | def get_nlstr(self): |
|
859 | 882 | try: |
|
860 | 883 | return self.__nlstr |
|
861 | 884 | except AttributeError: |
|
862 | 885 | self.__nlstr = '\n'.join(self) |
|
863 | 886 | return self.__nlstr |
|
864 | 887 | |
|
865 | 888 | n = nlstr = property(get_nlstr) |
|
866 | 889 | |
|
867 | 890 | def raw_input_multi(header='', ps1='==> ', ps2='..> ',terminate_str = '.'): |
|
868 | 891 | """Take multiple lines of input. |
|
869 | 892 | |
|
870 | 893 | A list with each line of input as a separate element is returned when a |
|
871 | 894 | termination string is entered (defaults to a single '.'). Input can also |
|
872 | 895 | terminate via EOF (^D in Unix, ^Z-RET in Windows). |
|
873 | 896 | |
|
874 | 897 | Lines of input which end in \\ are joined into single entries (and a |
|
875 | 898 | secondary continuation prompt is issued as long as the user terminates |
|
876 | 899 | lines with \\). This allows entering very long strings which are still |
|
877 | 900 | meant to be treated as single entities. |
|
878 | 901 | """ |
|
879 | 902 | |
|
880 | 903 | try: |
|
881 | 904 | if header: |
|
882 | 905 | header += '\n' |
|
883 | 906 | lines = [raw_input(header + ps1)] |
|
884 | 907 | except EOFError: |
|
885 | 908 | return [] |
|
886 | 909 | terminate = [terminate_str] |
|
887 | 910 | try: |
|
888 | 911 | while lines[-1:] != terminate: |
|
889 | 912 | new_line = raw_input(ps1) |
|
890 | 913 | while new_line.endswith('\\'): |
|
891 | 914 | new_line = new_line[:-1] + raw_input(ps2) |
|
892 | 915 | lines.append(new_line) |
|
893 | 916 | |
|
894 | 917 | return lines[:-1] # don't return the termination command |
|
895 | 918 | except EOFError: |
|
896 | 919 | |
|
897 | 920 | return lines |
|
898 | 921 | |
|
899 | 922 | #---------------------------------------------------------------------------- |
|
900 | 923 | def raw_input_ext(prompt='', ps2='... '): |
|
901 | 924 | """Similar to raw_input(), but accepts extended lines if input ends with \\.""" |
|
902 | 925 | |
|
903 | 926 | line = raw_input(prompt) |
|
904 | 927 | while line.endswith('\\'): |
|
905 | 928 | line = line[:-1] + raw_input(ps2) |
|
906 | 929 | return line |
|
907 | 930 | |
|
908 | 931 | #---------------------------------------------------------------------------- |
|
909 | 932 | def ask_yes_no(prompt,default=None): |
|
910 | 933 | """Asks a question and returns an integer 1/0 (y/n) answer. |
|
911 | 934 | |
|
912 | 935 | If default is given (one of 'y','n'), it is used if the user input is |
|
913 | 936 | empty. Otherwise the question is repeated until an answer is given. |
|
914 | 937 | If EOF occurs 20 times consecutively, the default answer is assumed, |
|
915 | 938 | or if there is no default, an exception is raised to prevent infinite |
|
916 | 939 | loops. |
|
917 | 940 | |
|
918 | 941 | Valid answers are: y/yes/n/no (match is not case sensitive).""" |
|
919 | 942 | |
|
920 | 943 | answers = {'y':1,'n':0,'yes':1,'no':0} |
|
921 | 944 | ans = None |
|
922 | 945 | eofs, max_eofs = 0, 20 |
|
923 | 946 | while ans not in answers.keys(): |
|
924 | 947 | try: |
|
925 | 948 | ans = raw_input(prompt+' ').lower() |
|
926 | 949 | if not ans: # response was an empty string |
|
927 | 950 | ans = default |
|
928 | 951 | eofs = 0 |
|
929 | 952 | except (EOFError,KeyboardInterrupt): |
|
930 | 953 | eofs = eofs + 1 |
|
931 | 954 | if eofs >= max_eofs: |
|
932 | 955 | if default in answers.keys(): |
|
933 | 956 | ans = default |
|
934 | 957 | else: |
|
935 | 958 | raise |
|
936 | 959 | |
|
937 | 960 | return answers[ans] |
|
938 | 961 | |
|
939 | 962 | #---------------------------------------------------------------------------- |
|
940 |
def marquee(txt='',width=8 |
|
|
963 | def marquee(txt='',width=78,mark='*'): | |
|
941 | 964 | """Return the input string centered in a 'marquee'.""" |
|
942 | 965 | if not txt: |
|
943 | 966 | return (mark*width)[:width] |
|
944 | 967 | nmark = (width-len(txt)-2)/len(mark)/2 |
|
945 | 968 | if nmark < 0: nmark =0 |
|
946 | 969 | marks = mark*nmark |
|
947 | 970 | return '%s %s %s' % (marks,txt,marks) |
|
948 | 971 | |
|
949 | 972 | #---------------------------------------------------------------------------- |
|
950 | 973 | class EvalDict: |
|
951 | 974 | """ |
|
952 | 975 | Emulate a dict which evaluates its contents in the caller's frame. |
|
953 | 976 | |
|
954 | 977 | Usage: |
|
955 | 978 | >>>number = 19 |
|
956 | 979 | >>>text = "python" |
|
957 | 980 | >>>print "%(text.capitalize())s %(number/9.0).1f rules!" % EvalDict() |
|
958 | 981 | """ |
|
959 | 982 | |
|
960 | 983 | # This version is due to sismex01@hebmex.com on c.l.py, and is basically a |
|
961 | 984 | # modified (shorter) version of: |
|
962 | 985 | # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66018 by |
|
963 | 986 | # Skip Montanaro (skip@pobox.com). |
|
964 | 987 | |
|
965 | 988 | def __getitem__(self, name): |
|
966 | 989 | frame = sys._getframe(1) |
|
967 | 990 | return eval(name, frame.f_globals, frame.f_locals) |
|
968 | 991 | |
|
969 | 992 | EvalString = EvalDict # for backwards compatibility |
|
970 | 993 | #---------------------------------------------------------------------------- |
|
971 | 994 | def qw(words,flat=0,sep=None,maxsplit=-1): |
|
972 | 995 | """Similar to Perl's qw() operator, but with some more options. |
|
973 | 996 | |
|
974 | 997 | qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit) |
|
975 | 998 | |
|
976 | 999 | words can also be a list itself, and with flat=1, the output will be |
|
977 | 1000 | recursively flattened. Examples: |
|
978 | 1001 | |
|
979 | 1002 | >>> qw('1 2') |
|
980 | 1003 | ['1', '2'] |
|
981 | 1004 | >>> qw(['a b','1 2',['m n','p q']]) |
|
982 | 1005 | [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]] |
|
983 | 1006 | >>> qw(['a b','1 2',['m n','p q']],flat=1) |
|
984 | 1007 | ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """ |
|
985 | 1008 | |
|
986 | 1009 | if type(words) in StringTypes: |
|
987 | 1010 | return [word.strip() for word in words.split(sep,maxsplit) |
|
988 | 1011 | if word and not word.isspace() ] |
|
989 | 1012 | if flat: |
|
990 | 1013 | return flatten(map(qw,words,[1]*len(words))) |
|
991 | 1014 | return map(qw,words) |
|
992 | 1015 | |
|
993 | 1016 | #---------------------------------------------------------------------------- |
|
994 | 1017 | def qwflat(words,sep=None,maxsplit=-1): |
|
995 | 1018 | """Calls qw(words) in flat mode. It's just a convenient shorthand.""" |
|
996 | 1019 | return qw(words,1,sep,maxsplit) |
|
997 | 1020 | |
|
998 | 1021 | #----------------------------------------------------------------------------- |
|
999 | 1022 | def list_strings(arg): |
|
1000 | 1023 | """Always return a list of strings, given a string or list of strings |
|
1001 | 1024 | as input.""" |
|
1002 | 1025 | |
|
1003 | 1026 | if type(arg) in StringTypes: return [arg] |
|
1004 | 1027 | else: return arg |
|
1005 | 1028 | |
|
1006 | 1029 | #---------------------------------------------------------------------------- |
|
1007 | 1030 | def grep(pat,list,case=1): |
|
1008 | 1031 | """Simple minded grep-like function. |
|
1009 | 1032 | grep(pat,list) returns occurrences of pat in list, None on failure. |
|
1010 | 1033 | |
|
1011 | 1034 | It only does simple string matching, with no support for regexps. Use the |
|
1012 | 1035 | option case=0 for case-insensitive matching.""" |
|
1013 | 1036 | |
|
1014 | 1037 | # This is pretty crude. At least it should implement copying only references |
|
1015 | 1038 | # to the original data in case it's big. Now it copies the data for output. |
|
1016 | 1039 | out=[] |
|
1017 | 1040 | if case: |
|
1018 | 1041 | for term in list: |
|
1019 | 1042 | if term.find(pat)>-1: out.append(term) |
|
1020 | 1043 | else: |
|
1021 | 1044 | lpat=pat.lower() |
|
1022 | 1045 | for term in list: |
|
1023 | 1046 | if term.lower().find(lpat)>-1: out.append(term) |
|
1024 | 1047 | |
|
1025 | 1048 | if len(out): return out |
|
1026 | 1049 | else: return None |
|
1027 | 1050 | |
|
1028 | 1051 | #---------------------------------------------------------------------------- |
|
1029 | 1052 | def dgrep(pat,*opts): |
|
1030 | 1053 | """Return grep() on dir()+dir(__builtins__). |
|
1031 | 1054 | |
|
1032 | 1055 | A very common use of grep() when working interactively.""" |
|
1033 | 1056 | |
|
1034 | 1057 | return grep(pat,dir(__main__)+dir(__main__.__builtins__),*opts) |
|
1035 | 1058 | |
|
1036 | 1059 | #---------------------------------------------------------------------------- |
|
1037 | 1060 | def idgrep(pat): |
|
1038 | 1061 | """Case-insensitive dgrep()""" |
|
1039 | 1062 | |
|
1040 | 1063 | return dgrep(pat,0) |
|
1041 | 1064 | |
|
1042 | 1065 | #---------------------------------------------------------------------------- |
|
1043 | 1066 | def igrep(pat,list): |
|
1044 | 1067 | """Synonym for case-insensitive grep.""" |
|
1045 | 1068 | |
|
1046 | 1069 | return grep(pat,list,case=0) |
|
1047 | 1070 | |
|
1048 | 1071 | #---------------------------------------------------------------------------- |
|
1049 | 1072 | def indent(str,nspaces=4,ntabs=0): |
|
1050 | 1073 | """Indent a string a given number of spaces or tabstops. |
|
1051 | 1074 | |
|
1052 | 1075 | indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces. |
|
1053 | 1076 | """ |
|
1054 | 1077 | if str is None: |
|
1055 | 1078 | return |
|
1056 | 1079 | ind = '\t'*ntabs+' '*nspaces |
|
1057 | 1080 | outstr = '%s%s' % (ind,str.replace(os.linesep,os.linesep+ind)) |
|
1058 | 1081 | if outstr.endswith(os.linesep+ind): |
|
1059 | 1082 | return outstr[:-len(ind)] |
|
1060 | 1083 | else: |
|
1061 | 1084 | return outstr |
|
1062 | 1085 | |
|
1063 | 1086 | #----------------------------------------------------------------------------- |
|
1064 | 1087 | def native_line_ends(filename,backup=1): |
|
1065 | 1088 | """Convert (in-place) a file to line-ends native to the current OS. |
|
1066 | 1089 | |
|
1067 | 1090 | If the optional backup argument is given as false, no backup of the |
|
1068 | 1091 | original file is left. """ |
|
1069 | 1092 | |
|
1070 | 1093 | backup_suffixes = {'posix':'~','dos':'.bak','nt':'.bak','mac':'.bak'} |
|
1071 | 1094 | |
|
1072 | 1095 | bak_filename = filename + backup_suffixes[os.name] |
|
1073 | 1096 | |
|
1074 | 1097 | original = open(filename).read() |
|
1075 | 1098 | shutil.copy2(filename,bak_filename) |
|
1076 | 1099 | try: |
|
1077 | 1100 | new = open(filename,'wb') |
|
1078 | 1101 | new.write(os.linesep.join(original.splitlines())) |
|
1079 | 1102 | new.write(os.linesep) # ALWAYS put an eol at the end of the file |
|
1080 | 1103 | new.close() |
|
1081 | 1104 | except: |
|
1082 | 1105 | os.rename(bak_filename,filename) |
|
1083 | 1106 | if not backup: |
|
1084 | 1107 | try: |
|
1085 | 1108 | os.remove(bak_filename) |
|
1086 | 1109 | except: |
|
1087 | 1110 | pass |
|
1088 | 1111 | |
|
1089 | 1112 | #---------------------------------------------------------------------------- |
|
1090 | 1113 | def get_pager_cmd(pager_cmd = None): |
|
1091 | 1114 | """Return a pager command. |
|
1092 | 1115 | |
|
1093 | 1116 | Makes some attempts at finding an OS-correct one.""" |
|
1094 | 1117 | |
|
1095 | 1118 | if os.name == 'posix': |
|
1096 | 1119 | default_pager_cmd = 'less -r' # -r for color control sequences |
|
1097 | 1120 | elif os.name in ['nt','dos']: |
|
1098 | 1121 | default_pager_cmd = 'type' |
|
1099 | 1122 | |
|
1100 | 1123 | if pager_cmd is None: |
|
1101 | 1124 | try: |
|
1102 | 1125 | pager_cmd = os.environ['PAGER'] |
|
1103 | 1126 | except: |
|
1104 | 1127 | pager_cmd = default_pager_cmd |
|
1105 | 1128 | return pager_cmd |
|
1106 | 1129 | |
|
1107 | 1130 | #----------------------------------------------------------------------------- |
|
1108 | 1131 | def get_pager_start(pager,start): |
|
1109 | 1132 | """Return the string for paging files with an offset. |
|
1110 | 1133 | |
|
1111 | 1134 | This is the '+N' argument which less and more (under Unix) accept. |
|
1112 | 1135 | """ |
|
1113 | 1136 | |
|
1114 | 1137 | if pager in ['less','more']: |
|
1115 | 1138 | if start: |
|
1116 | 1139 | start_string = '+' + str(start) |
|
1117 | 1140 | else: |
|
1118 | 1141 | start_string = '' |
|
1119 | 1142 | else: |
|
1120 | 1143 | start_string = '' |
|
1121 | 1144 | return start_string |
|
1122 | 1145 | |
|
1123 | 1146 | #---------------------------------------------------------------------------- |
|
1124 | 1147 | def page_dumb(strng,start=0,screen_lines=25): |
|
1125 | 1148 | """Very dumb 'pager' in Python, for when nothing else works. |
|
1126 | 1149 | |
|
1127 | 1150 | Only moves forward, same interface as page(), except for pager_cmd and |
|
1128 | 1151 | mode.""" |
|
1129 | 1152 | |
|
1130 | 1153 | out_ln = strng.splitlines()[start:] |
|
1131 | 1154 | screens = chop(out_ln,screen_lines-1) |
|
1132 | 1155 | if len(screens) == 1: |
|
1133 | 1156 | print >>Term.cout, os.linesep.join(screens[0]) |
|
1134 | 1157 | else: |
|
1135 | 1158 | for scr in screens[0:-1]: |
|
1136 | 1159 | print >>Term.cout, os.linesep.join(scr) |
|
1137 | 1160 | ans = raw_input('---Return to continue, q to quit--- ') |
|
1138 | 1161 | if ans.lower().startswith('q'): |
|
1139 | 1162 | return |
|
1140 | 1163 | print >>Term.cout, os.linesep.join(screens[-1]) |
|
1141 | 1164 | |
|
1142 | 1165 | #---------------------------------------------------------------------------- |
|
1143 | 1166 | def page(strng,start=0,screen_lines=0,pager_cmd = None): |
|
1144 | 1167 | """Print a string, piping through a pager after a certain length. |
|
1145 | 1168 | |
|
1146 | 1169 | The screen_lines parameter specifies the number of *usable* lines of your |
|
1147 | 1170 | terminal screen (total lines minus lines you need to reserve to show other |
|
1148 | 1171 | information). |
|
1149 | 1172 | |
|
1150 | 1173 | If you set screen_lines to a number <=0, page() will try to auto-determine |
|
1151 | 1174 | your screen size and will only use up to (screen_size+screen_lines) for |
|
1152 | 1175 | printing, paging after that. That is, if you want auto-detection but need |
|
1153 | 1176 | to reserve the bottom 3 lines of the screen, use screen_lines = -3, and for |
|
1154 | 1177 | auto-detection without any lines reserved simply use screen_lines = 0. |
|
1155 | 1178 | |
|
1156 | 1179 | If a string won't fit in the allowed lines, it is sent through the |
|
1157 | 1180 | specified pager command. If none given, look for PAGER in the environment, |
|
1158 | 1181 | and ultimately default to less. |
|
1159 | 1182 | |
|
1160 | 1183 | If no system pager works, the string is sent through a 'dumb pager' |
|
1161 | 1184 | written in python, very simplistic. |
|
1162 | 1185 | """ |
|
1163 | 1186 | |
|
1164 | 1187 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs |
|
1165 | 1188 | TERM = os.environ.get('TERM','dumb') |
|
1166 | 1189 | if TERM in ['dumb','emacs'] and os.name != 'nt': |
|
1167 | 1190 | print strng |
|
1168 | 1191 | return |
|
1169 | 1192 | # chop off the topmost part of the string we don't want to see |
|
1170 | 1193 | str_lines = strng.split(os.linesep)[start:] |
|
1171 | 1194 | str_toprint = os.linesep.join(str_lines) |
|
1172 | 1195 | num_newlines = len(str_lines) |
|
1173 | 1196 | len_str = len(str_toprint) |
|
1174 | 1197 | |
|
1175 | 1198 | # Dumb heuristics to guesstimate number of on-screen lines the string |
|
1176 | 1199 | # takes. Very basic, but good enough for docstrings in reasonable |
|
1177 | 1200 | # terminals. If someone later feels like refining it, it's not hard. |
|
1178 | 1201 | numlines = max(num_newlines,int(len_str/80)+1) |
|
1179 | 1202 | |
|
1180 | 1203 | screen_lines_def = 25 # default value if we can't auto-determine |
|
1181 | 1204 | |
|
1182 | 1205 | # auto-determine screen size |
|
1183 | 1206 | if screen_lines <= 0: |
|
1184 | 1207 | if TERM=='xterm': |
|
1185 | 1208 | try: |
|
1186 | 1209 | import curses |
|
1187 | 1210 | if hasattr(curses,'initscr'): |
|
1188 | 1211 | use_curses = 1 |
|
1189 | 1212 | else: |
|
1190 | 1213 | use_curses = 0 |
|
1191 | 1214 | except ImportError: |
|
1192 | 1215 | use_curses = 0 |
|
1193 | 1216 | else: |
|
1194 | 1217 | # curses causes problems on many terminals other than xterm. |
|
1195 | 1218 | use_curses = 0 |
|
1196 | 1219 | if use_curses: |
|
1197 | 1220 | scr = curses.initscr() |
|
1198 | 1221 | screen_lines_real,screen_cols = scr.getmaxyx() |
|
1199 | 1222 | curses.endwin() |
|
1200 | 1223 | screen_lines += screen_lines_real |
|
1201 | 1224 | #print '***Screen size:',screen_lines_real,'lines x',\ |
|
1202 | 1225 | #screen_cols,'columns.' # dbg |
|
1203 | 1226 | else: |
|
1204 | 1227 | screen_lines += screen_lines_def |
|
1205 | 1228 | |
|
1206 | 1229 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
1207 | 1230 | if numlines <= screen_lines : |
|
1208 | 1231 | #print '*** normal print' # dbg |
|
1209 | 1232 | print >>Term.cout, str_toprint |
|
1210 | 1233 | else: |
|
1211 | 1234 | # Try to open pager and default to internal one if that fails. |
|
1212 | 1235 | # All failure modes are tagged as 'retval=1', to match the return |
|
1213 | 1236 | # value of a failed system command. If any intermediate attempt |
|
1214 | 1237 | # sets retval to 1, at the end we resort to our own page_dumb() pager. |
|
1215 | 1238 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1216 | 1239 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1217 | 1240 | if os.name == 'nt': |
|
1218 | 1241 | if pager_cmd.startswith('type'): |
|
1219 | 1242 | # The default WinXP 'type' command is failing on complex strings. |
|
1220 | 1243 | retval = 1 |
|
1221 | 1244 | else: |
|
1222 | 1245 | tmpname = tempfile.mktemp('.txt') |
|
1223 | 1246 | tmpfile = file(tmpname,'wt') |
|
1224 | 1247 | tmpfile.write(strng) |
|
1225 | 1248 | tmpfile.close() |
|
1226 | 1249 | cmd = "%s < %s" % (pager_cmd,tmpname) |
|
1227 | 1250 | if os.system(cmd): |
|
1228 | 1251 | retval = 1 |
|
1229 | 1252 | else: |
|
1230 | 1253 | retval = None |
|
1231 | 1254 | os.remove(tmpname) |
|
1232 | 1255 | else: |
|
1233 | 1256 | try: |
|
1234 | 1257 | retval = None |
|
1235 | 1258 | # if I use popen4, things hang. No idea why. |
|
1236 | 1259 | #pager,shell_out = os.popen4(pager_cmd) |
|
1237 | 1260 | pager = os.popen(pager_cmd,'w') |
|
1238 | 1261 | pager.write(strng) |
|
1239 | 1262 | pager.close() |
|
1240 | 1263 | retval = pager.close() # success returns None |
|
1241 | 1264 | except IOError,msg: # broken pipe when user quits |
|
1242 | 1265 | if msg.args == (32,'Broken pipe'): |
|
1243 | 1266 | retval = None |
|
1244 | 1267 | else: |
|
1245 | 1268 | retval = 1 |
|
1246 | 1269 | except OSError: |
|
1247 | 1270 | # Other strange problems, sometimes seen in Win2k/cygwin |
|
1248 | 1271 | retval = 1 |
|
1249 | 1272 | if retval is not None: |
|
1250 | 1273 | page_dumb(strng,screen_lines=screen_lines) |
|
1251 | 1274 | |
|
1252 | 1275 | #---------------------------------------------------------------------------- |
|
1253 | 1276 | def page_file(fname,start = 0, pager_cmd = None): |
|
1254 | 1277 | """Page a file, using an optional pager command and starting line. |
|
1255 | 1278 | """ |
|
1256 | 1279 | |
|
1257 | 1280 | pager_cmd = get_pager_cmd(pager_cmd) |
|
1258 | 1281 | pager_cmd += ' ' + get_pager_start(pager_cmd,start) |
|
1259 | 1282 | |
|
1260 | 1283 | try: |
|
1261 | 1284 | if os.environ['TERM'] in ['emacs','dumb']: |
|
1262 | 1285 | raise EnvironmentError |
|
1263 | 1286 | xsys(pager_cmd + ' ' + fname) |
|
1264 | 1287 | except: |
|
1265 | 1288 | try: |
|
1266 | 1289 | if start > 0: |
|
1267 | 1290 | start -= 1 |
|
1268 | 1291 | page(open(fname).read(),start) |
|
1269 | 1292 | except: |
|
1270 | 1293 | print 'Unable to show file',`fname` |
|
1271 | 1294 | |
|
1272 | 1295 | #---------------------------------------------------------------------------- |
|
1273 | 1296 | def snip_print(str,width = 75,print_full = 0,header = ''): |
|
1274 | 1297 | """Print a string snipping the midsection to fit in width. |
|
1275 | 1298 | |
|
1276 | 1299 | print_full: mode control: |
|
1277 | 1300 | - 0: only snip long strings |
|
1278 | 1301 | - 1: send to page() directly. |
|
1279 | 1302 | - 2: snip long strings and ask for full length viewing with page() |
|
1280 | 1303 | Return 1 if snipping was necessary, 0 otherwise.""" |
|
1281 | 1304 | |
|
1282 | 1305 | if print_full == 1: |
|
1283 | 1306 | page(header+str) |
|
1284 | 1307 | return 0 |
|
1285 | 1308 | |
|
1286 | 1309 | print header, |
|
1287 | 1310 | if len(str) < width: |
|
1288 | 1311 | print str |
|
1289 | 1312 | snip = 0 |
|
1290 | 1313 | else: |
|
1291 | 1314 | whalf = int((width -5)/2) |
|
1292 | 1315 | print str[:whalf] + ' <...> ' + str[-whalf:] |
|
1293 | 1316 | snip = 1 |
|
1294 | 1317 | if snip and print_full == 2: |
|
1295 | 1318 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
|
1296 | 1319 | page(str) |
|
1297 | 1320 | return snip |
|
1298 | 1321 | |
|
1299 | 1322 | #**************************************************************************** |
|
1300 | 1323 | # lists, dicts and structures |
|
1301 | 1324 | |
|
1302 | 1325 | def belong(candidates,checklist): |
|
1303 | 1326 | """Check whether a list of items appear in a given list of options. |
|
1304 | 1327 | |
|
1305 | 1328 | Returns a list of 1 and 0, one for each candidate given.""" |
|
1306 | 1329 | |
|
1307 | 1330 | return [x in checklist for x in candidates] |
|
1308 | 1331 | |
|
1309 | 1332 | #---------------------------------------------------------------------------- |
|
1310 | 1333 | def uniq_stable(elems): |
|
1311 | 1334 | """uniq_stable(elems) -> list |
|
1312 | 1335 | |
|
1313 | 1336 | Return from an iterable, a list of all the unique elements in the input, |
|
1314 | 1337 | but maintaining the order in which they first appear. |
|
1315 | 1338 | |
|
1316 | 1339 | A naive solution to this problem which just makes a dictionary with the |
|
1317 | 1340 | elements as keys fails to respect the stability condition, since |
|
1318 | 1341 | dictionaries are unsorted by nature. |
|
1319 | 1342 | |
|
1320 | 1343 | Note: All elements in the input must be valid dictionary keys for this |
|
1321 | 1344 | routine to work, as it internally uses a dictionary for efficiency |
|
1322 | 1345 | reasons.""" |
|
1323 | 1346 | |
|
1324 | 1347 | unique = [] |
|
1325 | 1348 | unique_dict = {} |
|
1326 | 1349 | for nn in elems: |
|
1327 | 1350 | if nn not in unique_dict: |
|
1328 | 1351 | unique.append(nn) |
|
1329 | 1352 | unique_dict[nn] = None |
|
1330 | 1353 | return unique |
|
1331 | 1354 | |
|
1332 | 1355 | #---------------------------------------------------------------------------- |
|
1333 | 1356 | class NLprinter: |
|
1334 | 1357 | """Print an arbitrarily nested list, indicating index numbers. |
|
1335 | 1358 | |
|
1336 | 1359 | An instance of this class called nlprint is available and callable as a |
|
1337 | 1360 | function. |
|
1338 | 1361 | |
|
1339 | 1362 | nlprint(list,indent=' ',sep=': ') -> prints indenting each level by 'indent' |
|
1340 | 1363 | and using 'sep' to separate the index from the value. """ |
|
1341 | 1364 | |
|
1342 | 1365 | def __init__(self): |
|
1343 | 1366 | self.depth = 0 |
|
1344 | 1367 | |
|
1345 | 1368 | def __call__(self,lst,pos='',**kw): |
|
1346 | 1369 | """Prints the nested list numbering levels.""" |
|
1347 | 1370 | kw.setdefault('indent',' ') |
|
1348 | 1371 | kw.setdefault('sep',': ') |
|
1349 | 1372 | kw.setdefault('start',0) |
|
1350 | 1373 | kw.setdefault('stop',len(lst)) |
|
1351 | 1374 | # we need to remove start and stop from kw so they don't propagate |
|
1352 | 1375 | # into a recursive call for a nested list. |
|
1353 | 1376 | start = kw['start']; del kw['start'] |
|
1354 | 1377 | stop = kw['stop']; del kw['stop'] |
|
1355 | 1378 | if self.depth == 0 and 'header' in kw.keys(): |
|
1356 | 1379 | print kw['header'] |
|
1357 | 1380 | |
|
1358 | 1381 | for idx in range(start,stop): |
|
1359 | 1382 | elem = lst[idx] |
|
1360 | 1383 | if type(elem)==type([]): |
|
1361 | 1384 | self.depth += 1 |
|
1362 | 1385 | self.__call__(elem,itpl('$pos$idx,'),**kw) |
|
1363 | 1386 | self.depth -= 1 |
|
1364 | 1387 | else: |
|
1365 | 1388 | printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem') |
|
1366 | 1389 | |
|
1367 | 1390 | nlprint = NLprinter() |
|
1368 | 1391 | #---------------------------------------------------------------------------- |
|
1369 | 1392 | def all_belong(candidates,checklist): |
|
1370 | 1393 | """Check whether a list of items ALL appear in a given list of options. |
|
1371 | 1394 | |
|
1372 | 1395 | Returns a single 1 or 0 value.""" |
|
1373 | 1396 | |
|
1374 | 1397 | return 1-(0 in [x in checklist for x in candidates]) |
|
1375 | 1398 | |
|
1376 | 1399 | #---------------------------------------------------------------------------- |
|
1377 | 1400 | def sort_compare(lst1,lst2,inplace = 1): |
|
1378 | 1401 | """Sort and compare two lists. |
|
1379 | 1402 | |
|
1380 | 1403 | By default it does it in place, thus modifying the lists. Use inplace = 0 |
|
1381 | 1404 | to avoid that (at the cost of temporary copy creation).""" |
|
1382 | 1405 | if not inplace: |
|
1383 | 1406 | lst1 = lst1[:] |
|
1384 | 1407 | lst2 = lst2[:] |
|
1385 | 1408 | lst1.sort(); lst2.sort() |
|
1386 | 1409 | return lst1 == lst2 |
|
1387 | 1410 | |
|
1388 | 1411 | #---------------------------------------------------------------------------- |
|
1389 | 1412 | def mkdict(**kwargs): |
|
1390 | 1413 | """Return a dict from a keyword list. |
|
1391 | 1414 | |
|
1392 | 1415 | It's just syntactic sugar for making ditcionary creation more convenient: |
|
1393 | 1416 | # the standard way |
|
1394 | 1417 | >>>data = { 'red' : 1, 'green' : 2, 'blue' : 3 } |
|
1395 | 1418 | # a cleaner way |
|
1396 | 1419 | >>>data = dict(red=1, green=2, blue=3) |
|
1397 | 1420 | |
|
1398 | 1421 | If you need more than this, look at the Struct() class.""" |
|
1399 | 1422 | |
|
1400 | 1423 | return kwargs |
|
1401 | 1424 | |
|
1402 | 1425 | #---------------------------------------------------------------------------- |
|
1403 | 1426 | def list2dict(lst): |
|
1404 | 1427 | """Takes a list of (key,value) pairs and turns it into a dict.""" |
|
1405 | 1428 | |
|
1406 | 1429 | dic = {} |
|
1407 | 1430 | for k,v in lst: dic[k] = v |
|
1408 | 1431 | return dic |
|
1409 | 1432 | |
|
1410 | 1433 | #---------------------------------------------------------------------------- |
|
1411 | 1434 | def list2dict2(lst,default=''): |
|
1412 | 1435 | """Takes a list and turns it into a dict. |
|
1413 | 1436 | Much slower than list2dict, but more versatile. This version can take |
|
1414 | 1437 | lists with sublists of arbitrary length (including sclars).""" |
|
1415 | 1438 | |
|
1416 | 1439 | dic = {} |
|
1417 | 1440 | for elem in lst: |
|
1418 | 1441 | if type(elem) in (types.ListType,types.TupleType): |
|
1419 | 1442 | size = len(elem) |
|
1420 | 1443 | if size == 0: |
|
1421 | 1444 | pass |
|
1422 | 1445 | elif size == 1: |
|
1423 | 1446 | dic[elem] = default |
|
1424 | 1447 | else: |
|
1425 | 1448 | k,v = elem[0], elem[1:] |
|
1426 | 1449 | if len(v) == 1: v = v[0] |
|
1427 | 1450 | dic[k] = v |
|
1428 | 1451 | else: |
|
1429 | 1452 | dic[elem] = default |
|
1430 | 1453 | return dic |
|
1431 | 1454 | |
|
1432 | 1455 | #---------------------------------------------------------------------------- |
|
1433 | 1456 | def flatten(seq): |
|
1434 | 1457 | """Flatten a list of lists (NOT recursive, only works for 2d lists).""" |
|
1435 | 1458 | |
|
1436 | 1459 | # bug in python??? (YES. Fixed in 2.2, let's leave the kludgy fix in). |
|
1437 | 1460 | |
|
1438 | 1461 | # if the x=0 isn't made, a *global* variable x is left over after calling |
|
1439 | 1462 | # this function, with the value of the last element in the return |
|
1440 | 1463 | # list. This does seem like a bug big time to me. |
|
1441 | 1464 | |
|
1442 | 1465 | # the problem is fixed with the x=0, which seems to force the creation of |
|
1443 | 1466 | # a local name |
|
1444 | 1467 | |
|
1445 | 1468 | x = 0 |
|
1446 | 1469 | return [x for subseq in seq for x in subseq] |
|
1447 | 1470 | |
|
1448 | 1471 | #---------------------------------------------------------------------------- |
|
1449 | 1472 | def get_slice(seq,start=0,stop=None,step=1): |
|
1450 | 1473 | """Get a slice of a sequence with variable step. Specify start,stop,step.""" |
|
1451 | 1474 | if stop == None: |
|
1452 | 1475 | stop = len(seq) |
|
1453 | 1476 | item = lambda i: seq[i] |
|
1454 | 1477 | return map(item,xrange(start,stop,step)) |
|
1455 | 1478 | |
|
1456 | 1479 | #---------------------------------------------------------------------------- |
|
1457 | 1480 | def chop(seq,size): |
|
1458 | 1481 | """Chop a sequence into chunks of the given size.""" |
|
1459 | 1482 | chunk = lambda i: seq[i:i+size] |
|
1460 | 1483 | return map(chunk,xrange(0,len(seq),size)) |
|
1461 | 1484 | |
|
1462 | 1485 | #---------------------------------------------------------------------------- |
|
1463 | 1486 | def with(object, **args): |
|
1464 | 1487 | """Set multiple attributes for an object, similar to Pascal's with. |
|
1465 | 1488 | |
|
1466 | 1489 | Example: |
|
1467 | 1490 | with(jim, |
|
1468 | 1491 | born = 1960, |
|
1469 | 1492 | haircolour = 'Brown', |
|
1470 | 1493 | eyecolour = 'Green') |
|
1471 | 1494 | |
|
1472 | 1495 | Credit: Greg Ewing, in |
|
1473 | 1496 | http://mail.python.org/pipermail/python-list/2001-May/040703.html""" |
|
1474 | 1497 | |
|
1475 | 1498 | object.__dict__.update(args) |
|
1476 | 1499 | |
|
1477 | 1500 | #---------------------------------------------------------------------------- |
|
1478 | 1501 | def setattr_list(obj,alist,nspace = None): |
|
1479 | 1502 | """Set a list of attributes for an object taken from a namespace. |
|
1480 | 1503 | |
|
1481 | 1504 | setattr_list(obj,alist,nspace) -> sets in obj all the attributes listed in |
|
1482 | 1505 | alist with their values taken from nspace, which must be a dict (something |
|
1483 | 1506 | like locals() will often do) If nspace isn't given, locals() of the |
|
1484 | 1507 | *caller* is used, so in most cases you can omit it. |
|
1485 | 1508 | |
|
1486 | 1509 | Note that alist can be given as a string, which will be automatically |
|
1487 | 1510 | split into a list on whitespace. If given as a list, it must be a list of |
|
1488 | 1511 | *strings* (the variable names themselves), not of variables.""" |
|
1489 | 1512 | |
|
1490 | 1513 | # this grabs the local variables from the *previous* call frame -- that is |
|
1491 | 1514 | # the locals from the function that called setattr_list(). |
|
1492 | 1515 | # - snipped from weave.inline() |
|
1493 | 1516 | if nspace is None: |
|
1494 | 1517 | call_frame = sys._getframe().f_back |
|
1495 | 1518 | nspace = call_frame.f_locals |
|
1496 | 1519 | |
|
1497 | 1520 | if type(alist) in StringTypes: |
|
1498 | 1521 | alist = alist.split() |
|
1499 | 1522 | for attr in alist: |
|
1500 | 1523 | val = eval(attr,nspace) |
|
1501 | 1524 | setattr(obj,attr,val) |
|
1502 | 1525 | |
|
1503 | 1526 | #---------------------------------------------------------------------------- |
|
1504 | 1527 | def getattr_list(obj,alist,*args): |
|
1505 | 1528 | """getattr_list(obj,alist[, default]) -> attribute list. |
|
1506 | 1529 | |
|
1507 | 1530 | Get a list of named attributes for an object. When a default argument is |
|
1508 | 1531 | given, it is returned when the attribute doesn't exist; without it, an |
|
1509 | 1532 | exception is raised in that case. |
|
1510 | 1533 | |
|
1511 | 1534 | Note that alist can be given as a string, which will be automatically |
|
1512 | 1535 | split into a list on whitespace. If given as a list, it must be a list of |
|
1513 | 1536 | *strings* (the variable names themselves), not of variables.""" |
|
1514 | 1537 | |
|
1515 | 1538 | if type(alist) in StringTypes: |
|
1516 | 1539 | alist = alist.split() |
|
1517 | 1540 | if args: |
|
1518 | 1541 | if len(args)==1: |
|
1519 | 1542 | default = args[0] |
|
1520 | 1543 | return map(lambda attr: getattr(obj,attr,default),alist) |
|
1521 | 1544 | else: |
|
1522 | 1545 | raise ValueError,'getattr_list() takes only one optional argument' |
|
1523 | 1546 | else: |
|
1524 | 1547 | return map(lambda attr: getattr(obj,attr),alist) |
|
1525 | 1548 | |
|
1526 | 1549 | #---------------------------------------------------------------------------- |
|
1527 | 1550 | def map_method(method,object_list,*argseq,**kw): |
|
1528 | 1551 | """map_method(method,object_list,*args,**kw) -> list |
|
1529 | 1552 | |
|
1530 | 1553 | Return a list of the results of applying the methods to the items of the |
|
1531 | 1554 | argument sequence(s). If more than one sequence is given, the method is |
|
1532 | 1555 | called with an argument list consisting of the corresponding item of each |
|
1533 | 1556 | sequence. All sequences must be of the same length. |
|
1534 | 1557 | |
|
1535 | 1558 | Keyword arguments are passed verbatim to all objects called. |
|
1536 | 1559 | |
|
1537 | 1560 | This is Python code, so it's not nearly as fast as the builtin map().""" |
|
1538 | 1561 | |
|
1539 | 1562 | out_list = [] |
|
1540 | 1563 | idx = 0 |
|
1541 | 1564 | for object in object_list: |
|
1542 | 1565 | try: |
|
1543 | 1566 | handler = getattr(object, method) |
|
1544 | 1567 | except AttributeError: |
|
1545 | 1568 | out_list.append(None) |
|
1546 | 1569 | else: |
|
1547 | 1570 | if argseq: |
|
1548 | 1571 | args = map(lambda lst:lst[idx],argseq) |
|
1549 | 1572 | #print 'ob',object,'hand',handler,'ar',args # dbg |
|
1550 | 1573 | out_list.append(handler(args,**kw)) |
|
1551 | 1574 | else: |
|
1552 | 1575 | out_list.append(handler(**kw)) |
|
1553 | 1576 | idx += 1 |
|
1554 | 1577 | return out_list |
|
1555 | 1578 | |
|
1556 | 1579 | #---------------------------------------------------------------------------- |
|
1557 | 1580 | # Proposed popitem() extension, written as a method |
|
1558 | 1581 | |
|
1559 | 1582 | class NotGiven: pass |
|
1560 | 1583 | |
|
1561 | 1584 | def popkey(dct,key,default=NotGiven): |
|
1562 | 1585 | """Return dct[key] and delete dct[key]. |
|
1563 | 1586 | |
|
1564 | 1587 | If default is given, return it if dct[key] doesn't exist, otherwise raise |
|
1565 | 1588 | KeyError. """ |
|
1566 | 1589 | |
|
1567 | 1590 | try: |
|
1568 | 1591 | val = dct[key] |
|
1569 | 1592 | except KeyError: |
|
1570 | 1593 | if default is NotGiven: |
|
1571 | 1594 | raise |
|
1572 | 1595 | else: |
|
1573 | 1596 | return default |
|
1574 | 1597 | else: |
|
1575 | 1598 | del dct[key] |
|
1576 | 1599 | return val |
|
1577 | 1600 | #*************************** end of file <genutils.py> ********************** |
|
1578 | 1601 |
@@ -1,2047 +1,2052 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | IPython -- An enhanced Interactive Python |
|
4 | 4 | |
|
5 | 5 | Requires Python 2.1 or newer. |
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py |
|
|
9 | $Id: iplib.py 908 2005-09-26 16:05:48Z fperez $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
|
13 | 13 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
14 | 14 | # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu> |
|
15 | 15 | # |
|
16 | 16 | # Distributed under the terms of the BSD License. The full license is in |
|
17 | 17 | # the file COPYING, distributed as part of this software. |
|
18 | 18 | # |
|
19 | 19 | # Note: this code originally subclassed code.InteractiveConsole from the |
|
20 | 20 | # Python standard library. Over time, much of that class has been copied |
|
21 | 21 | # verbatim here for modifications which could not be accomplished by |
|
22 | 22 | # subclassing. The Python License (sec. 2) allows for this, but it's always |
|
23 | 23 | # nice to acknowledge credit where credit is due. |
|
24 | 24 | #***************************************************************************** |
|
25 | 25 | |
|
26 | 26 | #**************************************************************************** |
|
27 | 27 | # Modules and globals |
|
28 | 28 | |
|
29 | 29 | from __future__ import generators # for 2.2 backwards-compatibility |
|
30 | 30 | |
|
31 | 31 | from IPython import Release |
|
32 | 32 | __author__ = '%s <%s>\n%s <%s>' % \ |
|
33 | 33 | ( Release.authors['Janko'] + Release.authors['Fernando'] ) |
|
34 | 34 | __license__ = Release.license |
|
35 | 35 | __version__ = Release.version |
|
36 | 36 | |
|
37 | 37 | # Python standard modules |
|
38 | 38 | import __main__ |
|
39 | 39 | import __builtin__ |
|
40 | 40 | import exceptions |
|
41 | 41 | import keyword |
|
42 | 42 | import new |
|
43 | 43 | import os, sys, shutil |
|
44 | 44 | import code, glob, types, re |
|
45 | 45 | import string, StringIO |
|
46 | 46 | import inspect, pydoc |
|
47 | 47 | import bdb, pdb |
|
48 | 48 | import UserList # don't subclass list so this works with Python2.1 |
|
49 | 49 | from pprint import pprint, pformat |
|
50 | 50 | import cPickle as pickle |
|
51 | 51 | import traceback |
|
52 | 52 | |
|
53 | 53 | # IPython's own modules |
|
54 | 54 | import IPython |
|
55 | 55 | from IPython import OInspect,PyColorize,ultraTB |
|
56 | 56 | from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names |
|
57 | 57 | from IPython.Logger import Logger |
|
58 | 58 | from IPython.Magic import Magic,magic2python,shlex_split |
|
59 | 59 | from IPython.usage import cmd_line_usage,interactive_usage |
|
60 | 60 | from IPython.Struct import Struct |
|
61 | 61 | from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns |
|
62 | 62 | from IPython.FakeModule import FakeModule |
|
63 | 63 | from IPython.background_jobs import BackgroundJobManager |
|
64 | from IPython.PyColorize import Parser | |
|
64 | 65 | from IPython.genutils import * |
|
65 | 66 | |
|
66 | 67 | # Global pointer to the running |
|
67 | 68 | |
|
68 | 69 | # store the builtin raw_input globally, and use this always, in case user code |
|
69 | 70 | # overwrites it (like wx.py.PyShell does) |
|
70 | 71 | raw_input_original = raw_input |
|
71 | 72 | |
|
72 | 73 | #**************************************************************************** |
|
73 | 74 | # Some utility function definitions |
|
74 | 75 | |
|
75 | 76 | class Bunch: pass |
|
76 | 77 | |
|
77 | 78 | def esc_quotes(strng): |
|
78 | 79 | """Return the input string with single and double quotes escaped out""" |
|
79 | 80 | |
|
80 | 81 | return strng.replace('"','\\"').replace("'","\\'") |
|
81 | 82 | |
|
82 | 83 | def import_fail_info(mod_name,fns=None): |
|
83 | 84 | """Inform load failure for a module.""" |
|
84 | 85 | |
|
85 | 86 | if fns == None: |
|
86 | 87 | warn("Loading of %s failed.\n" % (mod_name,)) |
|
87 | 88 | else: |
|
88 | 89 | warn("Loading of %s from %s failed.\n" % (fns,mod_name)) |
|
89 | 90 | |
|
90 | 91 | def qw_lol(indata): |
|
91 | 92 | """qw_lol('a b') -> [['a','b']], |
|
92 | 93 | otherwise it's just a call to qw(). |
|
93 | 94 | |
|
94 | 95 | We need this to make sure the modules_some keys *always* end up as a |
|
95 | 96 | list of lists.""" |
|
96 | 97 | |
|
97 | 98 | if type(indata) in StringTypes: |
|
98 | 99 | return [qw(indata)] |
|
99 | 100 | else: |
|
100 | 101 | return qw(indata) |
|
101 | 102 | |
|
102 | 103 | def ipmagic(arg_s): |
|
103 | 104 | """Call a magic function by name. |
|
104 | 105 | |
|
105 | 106 | Input: a string containing the name of the magic function to call and any |
|
106 | 107 | additional arguments to be passed to the magic. |
|
107 | 108 | |
|
108 | 109 | ipmagic('name -opt foo bar') is equivalent to typing at the ipython |
|
109 | 110 | prompt: |
|
110 | 111 | |
|
111 | 112 | In[1]: %name -opt foo bar |
|
112 | 113 | |
|
113 | 114 | To call a magic without arguments, simply use ipmagic('name'). |
|
114 | 115 | |
|
115 | 116 | This provides a proper Python function to call IPython's magics in any |
|
116 | 117 | valid Python code you can type at the interpreter, including loops and |
|
117 | 118 | compound statements. It is added by IPython to the Python builtin |
|
118 | 119 | namespace upon initialization.""" |
|
119 | 120 | |
|
120 | 121 | args = arg_s.split(' ',1) |
|
121 | 122 | magic_name = args[0] |
|
122 | 123 | if magic_name.startswith(__IPYTHON__.ESC_MAGIC): |
|
123 | 124 | magic_name = magic_name[1:] |
|
124 | 125 | try: |
|
125 | 126 | magic_args = args[1] |
|
126 | 127 | except IndexError: |
|
127 | 128 | magic_args = '' |
|
128 | 129 | fn = getattr(__IPYTHON__,'magic_'+magic_name,None) |
|
129 | 130 | if fn is None: |
|
130 | 131 | error("Magic function `%s` not found." % magic_name) |
|
131 | 132 | else: |
|
132 | 133 | magic_args = __IPYTHON__.var_expand(magic_args) |
|
133 | 134 | return fn(magic_args) |
|
134 | 135 | |
|
135 | 136 | def ipalias(arg_s): |
|
136 | 137 | """Call an alias by name. |
|
137 | 138 | |
|
138 | 139 | Input: a string containing the name of the alias to call and any |
|
139 | 140 | additional arguments to be passed to the magic. |
|
140 | 141 | |
|
141 | 142 | ipalias('name -opt foo bar') is equivalent to typing at the ipython |
|
142 | 143 | prompt: |
|
143 | 144 | |
|
144 | 145 | In[1]: name -opt foo bar |
|
145 | 146 | |
|
146 | 147 | To call an alias without arguments, simply use ipalias('name'). |
|
147 | 148 | |
|
148 | 149 | This provides a proper Python function to call IPython's aliases in any |
|
149 | 150 | valid Python code you can type at the interpreter, including loops and |
|
150 | 151 | compound statements. It is added by IPython to the Python builtin |
|
151 | 152 | namespace upon initialization.""" |
|
152 | 153 | |
|
153 | 154 | args = arg_s.split(' ',1) |
|
154 | 155 | alias_name = args[0] |
|
155 | 156 | try: |
|
156 | 157 | alias_args = args[1] |
|
157 | 158 | except IndexError: |
|
158 | 159 | alias_args = '' |
|
159 | 160 | if alias_name in __IPYTHON__.alias_table: |
|
160 | 161 | __IPYTHON__.call_alias(alias_name,alias_args) |
|
161 | 162 | else: |
|
162 | 163 | error("Alias `%s` not found." % alias_name) |
|
163 | 164 | |
|
164 | 165 | #----------------------------------------------------------------------------- |
|
165 | 166 | # Local use classes |
|
166 | 167 | try: |
|
167 | 168 | from IPython import FlexCompleter |
|
168 | 169 | |
|
169 | 170 | class MagicCompleter(FlexCompleter.Completer): |
|
170 | 171 | """Extension of the completer class to work on %-prefixed lines.""" |
|
171 | 172 | |
|
172 | 173 | def __init__(self,shell,namespace=None,omit__names=0,alias_table=None): |
|
173 | 174 | """MagicCompleter() -> completer |
|
174 | 175 | |
|
175 | 176 | Return a completer object suitable for use by the readline library |
|
176 | 177 | via readline.set_completer(). |
|
177 | 178 | |
|
178 | 179 | Inputs: |
|
179 | 180 | |
|
180 | 181 | - shell: a pointer to the ipython shell itself. This is needed |
|
181 | 182 | because this completer knows about magic functions, and those can |
|
182 | 183 | only be accessed via the ipython instance. |
|
183 | 184 | |
|
184 | 185 | - namespace: an optional dict where completions are performed. |
|
185 | 186 | |
|
186 | 187 | - The optional omit__names parameter sets the completer to omit the |
|
187 | 188 | 'magic' names (__magicname__) for python objects unless the text |
|
188 | 189 | to be completed explicitly starts with one or more underscores. |
|
189 | 190 | |
|
190 | 191 | - If alias_table is supplied, it should be a dictionary of aliases |
|
191 | 192 | to complete. """ |
|
192 | 193 | |
|
193 | 194 | FlexCompleter.Completer.__init__(self,namespace) |
|
194 | 195 | self.magic_prefix = shell.name+'.magic_' |
|
195 | 196 | self.magic_escape = shell.ESC_MAGIC |
|
196 | 197 | self.readline = FlexCompleter.readline |
|
197 | 198 | delims = self.readline.get_completer_delims() |
|
198 | 199 | delims = delims.replace(self.magic_escape,'') |
|
199 | 200 | self.readline.set_completer_delims(delims) |
|
200 | 201 | self.get_line_buffer = self.readline.get_line_buffer |
|
201 | 202 | self.omit__names = omit__names |
|
202 | 203 | self.merge_completions = shell.rc.readline_merge_completions |
|
203 | 204 | |
|
204 | 205 | if alias_table is None: |
|
205 | 206 | alias_table = {} |
|
206 | 207 | self.alias_table = alias_table |
|
207 | 208 | # Regexp to split filenames with spaces in them |
|
208 | 209 | self.space_name_re = re.compile(r'([^\\] )') |
|
209 | 210 | # Hold a local ref. to glob.glob for speed |
|
210 | 211 | self.glob = glob.glob |
|
211 | 212 | # Special handling of backslashes needed in win32 platforms |
|
212 | 213 | if sys.platform == "win32": |
|
213 | 214 | self.clean_glob = self._clean_glob_win32 |
|
214 | 215 | else: |
|
215 | 216 | self.clean_glob = self._clean_glob |
|
216 | 217 | self.matchers = [self.python_matches, |
|
217 | 218 | self.file_matches, |
|
218 | 219 | self.alias_matches, |
|
219 | 220 | self.python_func_kw_matches] |
|
220 | 221 | |
|
221 | 222 | # Code contributed by Alex Schmolck, for ipython/emacs integration |
|
222 | 223 | def all_completions(self, text): |
|
223 | 224 | """Return all possible completions for the benefit of emacs.""" |
|
224 | 225 | |
|
225 | 226 | completions = [] |
|
226 | 227 | try: |
|
227 | 228 | for i in xrange(sys.maxint): |
|
228 | 229 | res = self.complete(text, i) |
|
229 | 230 | |
|
230 | 231 | if not res: break |
|
231 | 232 | |
|
232 | 233 | completions.append(res) |
|
233 | 234 | #XXX workaround for ``notDefined.<tab>`` |
|
234 | 235 | except NameError: |
|
235 | 236 | pass |
|
236 | 237 | return completions |
|
237 | 238 | # /end Alex Schmolck code. |
|
238 | 239 | |
|
239 | 240 | def _clean_glob(self,text): |
|
240 | 241 | return self.glob("%s*" % text) |
|
241 | 242 | |
|
242 | 243 | def _clean_glob_win32(self,text): |
|
243 | 244 | return [f.replace("\\","/") |
|
244 | 245 | for f in self.glob("%s*" % text)] |
|
245 | 246 | |
|
246 | 247 | def file_matches(self, text): |
|
247 | 248 | """Match filneames, expanding ~USER type strings. |
|
248 | 249 | |
|
249 | 250 | Most of the seemingly convoluted logic in this completer is an |
|
250 | 251 | attempt to handle filenames with spaces in them. And yet it's not |
|
251 | 252 | quite perfect, because Python's readline doesn't expose all of the |
|
252 | 253 | GNU readline details needed for this to be done correctly. |
|
253 | 254 | |
|
254 | 255 | For a filename with a space in it, the printed completions will be |
|
255 | 256 | only the parts after what's already been typed (instead of the |
|
256 | 257 | full completions, as is normally done). I don't think with the |
|
257 | 258 | current (as of Python 2.3) Python readline it's possible to do |
|
258 | 259 | better.""" |
|
259 | 260 | |
|
260 | 261 | #print 'Completer->file_matches: <%s>' % text # dbg |
|
261 | 262 | |
|
262 | 263 | # chars that require escaping with backslash - i.e. chars |
|
263 | 264 | # that readline treats incorrectly as delimiters, but we |
|
264 | 265 | # don't want to treat as delimiters in filename matching |
|
265 | 266 | # when escaped with backslash |
|
266 | 267 | |
|
267 | 268 | protectables = ' ()[]{}' |
|
268 | 269 | |
|
269 | 270 | def protect_filename(s): |
|
270 | 271 | return "".join([(ch in protectables and '\\' + ch or ch) |
|
271 | 272 | for ch in s]) |
|
272 | 273 | |
|
273 | 274 | lbuf = self.get_line_buffer()[:self.readline.get_endidx()] |
|
274 | 275 | open_quotes = 0 # track strings with open quotes |
|
275 | 276 | try: |
|
276 | 277 | lsplit = shlex_split(lbuf)[-1] |
|
277 | 278 | except ValueError: |
|
278 | 279 | # typically an unmatched ", or backslash without escaped char. |
|
279 | 280 | if lbuf.count('"')==1: |
|
280 | 281 | open_quotes = 1 |
|
281 | 282 | lsplit = lbuf.split('"')[-1] |
|
282 | 283 | elif lbuf.count("'")==1: |
|
283 | 284 | open_quotes = 1 |
|
284 | 285 | lsplit = lbuf.split("'")[-1] |
|
285 | 286 | else: |
|
286 | 287 | return None |
|
287 | 288 | except IndexError: |
|
288 | 289 | # tab pressed on empty line |
|
289 | 290 | lsplit = "" |
|
290 | 291 | |
|
291 | 292 | if lsplit != protect_filename(lsplit): |
|
292 | 293 | # if protectables are found, do matching on the whole escaped |
|
293 | 294 | # name |
|
294 | 295 | has_protectables = 1 |
|
295 | 296 | text0,text = text,lsplit |
|
296 | 297 | else: |
|
297 | 298 | has_protectables = 0 |
|
298 | 299 | text = os.path.expanduser(text) |
|
299 | 300 | |
|
300 | 301 | if text == "": |
|
301 | 302 | return [protect_filename(f) for f in self.glob("*")] |
|
302 | 303 | |
|
303 | 304 | m0 = self.clean_glob(text.replace('\\','')) |
|
304 | 305 | if has_protectables: |
|
305 | 306 | # If we had protectables, we need to revert our changes to the |
|
306 | 307 | # beginning of filename so that we don't double-write the part |
|
307 | 308 | # of the filename we have so far |
|
308 | 309 | len_lsplit = len(lsplit) |
|
309 | 310 | matches = [text0 + protect_filename(f[len_lsplit:]) for f in m0] |
|
310 | 311 | else: |
|
311 | 312 | if open_quotes: |
|
312 | 313 | # if we have a string with an open quote, we don't need to |
|
313 | 314 | # protect the names at all (and we _shouldn't_, as it |
|
314 | 315 | # would cause bugs when the filesystem call is made). |
|
315 | 316 | matches = m0 |
|
316 | 317 | else: |
|
317 | 318 | matches = [protect_filename(f) for f in m0] |
|
318 | 319 | if len(matches) == 1 and os.path.isdir(matches[0]): |
|
319 | 320 | # Takes care of links to directories also. Use '/' |
|
320 | 321 | # explicitly, even under Windows, so that name completions |
|
321 | 322 | # don't end up escaped. |
|
322 | 323 | matches[0] += '/' |
|
323 | 324 | return matches |
|
324 | 325 | |
|
325 | 326 | def alias_matches(self, text): |
|
326 | 327 | """Match internal system aliases""" |
|
327 | 328 | #print 'Completer->alias_matches:',text # dbg |
|
328 | 329 | text = os.path.expanduser(text) |
|
329 | 330 | aliases = self.alias_table.keys() |
|
330 | 331 | if text == "": |
|
331 | 332 | return aliases |
|
332 | 333 | else: |
|
333 | 334 | return [alias for alias in aliases if alias.startswith(text)] |
|
334 | 335 | |
|
335 | 336 | def python_matches(self,text): |
|
336 | 337 | """Match attributes or global python names""" |
|
337 | 338 | #print 'Completer->python_matches' # dbg |
|
338 | 339 | if "." in text: |
|
339 | 340 | try: |
|
340 | 341 | matches = self.attr_matches(text) |
|
341 | 342 | if text.endswith('.') and self.omit__names: |
|
342 | 343 | if self.omit__names == 1: |
|
343 | 344 | # true if txt is _not_ a __ name, false otherwise: |
|
344 | 345 | no__name = (lambda txt: |
|
345 | 346 | re.match(r'.*\.__.*?__',txt) is None) |
|
346 | 347 | else: |
|
347 | 348 | # true if txt is _not_ a _ name, false otherwise: |
|
348 | 349 | no__name = (lambda txt: |
|
349 | 350 | re.match(r'.*\._.*?',txt) is None) |
|
350 | 351 | matches = filter(no__name, matches) |
|
351 | 352 | except NameError: |
|
352 | 353 | # catches <undefined attributes>.<tab> |
|
353 | 354 | matches = [] |
|
354 | 355 | else: |
|
355 | 356 | matches = self.global_matches(text) |
|
356 | 357 | # this is so completion finds magics when automagic is on: |
|
357 | 358 | if matches == [] and not text.startswith(os.sep): |
|
358 | 359 | matches = self.attr_matches(self.magic_prefix+text) |
|
359 | 360 | return matches |
|
360 | 361 | |
|
361 | 362 | def _default_arguments(self, obj): |
|
362 | 363 | """Return the list of default arguments of obj if it is callable, |
|
363 | 364 | or empty list otherwise.""" |
|
364 | 365 | |
|
365 | 366 | if not (inspect.isfunction(obj) or inspect.ismethod(obj)): |
|
366 | 367 | # for classes, check for __init__,__new__ |
|
367 | 368 | if inspect.isclass(obj): |
|
368 | 369 | obj = (getattr(obj,'__init__',None) or |
|
369 | 370 | getattr(obj,'__new__',None)) |
|
370 | 371 | # for all others, check if they are __call__able |
|
371 | 372 | elif hasattr(obj, '__call__'): |
|
372 | 373 | obj = obj.__call__ |
|
373 | 374 | # XXX: is there a way to handle the builtins ? |
|
374 | 375 | try: |
|
375 | 376 | args,_,_1,defaults = inspect.getargspec(obj) |
|
376 | 377 | if defaults: |
|
377 | 378 | return args[-len(defaults):] |
|
378 | 379 | except TypeError: pass |
|
379 | 380 | return [] |
|
380 | 381 | |
|
381 | 382 | def python_func_kw_matches(self,text): |
|
382 | 383 | """Match named parameters (kwargs) of the last open function""" |
|
383 | 384 | |
|
384 | 385 | if "." in text: # a parameter cannot be dotted |
|
385 | 386 | return [] |
|
386 | 387 | try: regexp = self.__funcParamsRegex |
|
387 | 388 | except AttributeError: |
|
388 | 389 | regexp = self.__funcParamsRegex = re.compile(r''' |
|
389 | 390 | '.*?' | # single quoted strings or |
|
390 | 391 | ".*?" | # double quoted strings or |
|
391 | 392 | \w+ | # identifier |
|
392 | 393 | \S # other characters |
|
393 | 394 | ''', re.VERBOSE | re.DOTALL) |
|
394 | 395 | # 1. find the nearest identifier that comes before an unclosed |
|
395 | 396 | # parenthesis e.g. for "foo (1+bar(x), pa", the candidate is "foo" |
|
396 | 397 | tokens = regexp.findall(self.get_line_buffer()) |
|
397 | 398 | tokens.reverse() |
|
398 | 399 | iterTokens = iter(tokens); openPar = 0 |
|
399 | 400 | for token in iterTokens: |
|
400 | 401 | if token == ')': |
|
401 | 402 | openPar -= 1 |
|
402 | 403 | elif token == '(': |
|
403 | 404 | openPar += 1 |
|
404 | 405 | if openPar > 0: |
|
405 | 406 | # found the last unclosed parenthesis |
|
406 | 407 | break |
|
407 | 408 | else: |
|
408 | 409 | return [] |
|
409 | 410 | # 2. Concatenate any dotted names (e.g. "foo.bar" for "foo.bar(x, pa" ) |
|
410 | 411 | ids = [] |
|
411 | 412 | isId = re.compile(r'\w+$').match |
|
412 | 413 | while True: |
|
413 | 414 | try: |
|
414 | 415 | ids.append(iterTokens.next()) |
|
415 | 416 | if not isId(ids[-1]): |
|
416 | 417 | ids.pop(); break |
|
417 | 418 | if not iterTokens.next() == '.': |
|
418 | 419 | break |
|
419 | 420 | except StopIteration: |
|
420 | 421 | break |
|
421 | 422 | # lookup the candidate callable matches either using global_matches |
|
422 | 423 | # or attr_matches for dotted names |
|
423 | 424 | if len(ids) == 1: |
|
424 | 425 | callableMatches = self.global_matches(ids[0]) |
|
425 | 426 | else: |
|
426 | 427 | callableMatches = self.attr_matches('.'.join(ids[::-1])) |
|
427 | 428 | argMatches = [] |
|
428 | 429 | for callableMatch in callableMatches: |
|
429 | 430 | try: namedArgs = self._default_arguments(eval(callableMatch, |
|
430 | 431 | self.namespace)) |
|
431 | 432 | except: continue |
|
432 | 433 | for namedArg in namedArgs: |
|
433 | 434 | if namedArg.startswith(text): |
|
434 | 435 | argMatches.append("%s=" %namedArg) |
|
435 | 436 | return argMatches |
|
436 | 437 | |
|
437 | 438 | def complete(self, text, state): |
|
438 | 439 | """Return the next possible completion for 'text'. |
|
439 | 440 | |
|
440 | 441 | This is called successively with state == 0, 1, 2, ... until it |
|
441 | 442 | returns None. The completion should begin with 'text'. """ |
|
442 | 443 | |
|
443 | 444 | #print '\n*** COMPLETE: <%s> (%s)' % (text,state) # dbg |
|
444 | 445 | magic_escape = self.magic_escape |
|
445 | 446 | magic_prefix = self.magic_prefix |
|
446 | 447 | |
|
447 | 448 | try: |
|
448 | 449 | if text.startswith(magic_escape): |
|
449 | 450 | text = text.replace(magic_escape,magic_prefix) |
|
450 | 451 | elif text.startswith('~'): |
|
451 | 452 | text = os.path.expanduser(text) |
|
452 | 453 | if state == 0: |
|
453 | 454 | # Extend the list of completions with the results of each |
|
454 | 455 | # matcher, so we return results to the user from all |
|
455 | 456 | # namespaces. |
|
456 | 457 | if self.merge_completions: |
|
457 | 458 | self.matches = [] |
|
458 | 459 | for matcher in self.matchers: |
|
459 | 460 | self.matches.extend(matcher(text)) |
|
460 | 461 | else: |
|
461 | 462 | for matcher in self.matchers: |
|
462 | 463 | self.matches = matcher(text) |
|
463 | 464 | if self.matches: |
|
464 | 465 | break |
|
465 | 466 | |
|
466 | 467 | try: |
|
467 | 468 | return self.matches[state].replace(magic_prefix,magic_escape) |
|
468 | 469 | except IndexError: |
|
469 | 470 | return None |
|
470 | 471 | except: |
|
471 | 472 | # If completion fails, don't annoy the user. |
|
472 | 473 | pass |
|
473 | 474 | |
|
474 | 475 | except ImportError: |
|
475 | 476 | pass # no readline support |
|
476 | 477 | |
|
477 | 478 | except KeyError: |
|
478 | 479 | pass # Windows doesn't set TERM, it doesn't matter |
|
479 | 480 | |
|
480 | 481 | |
|
481 | 482 | class InputList(UserList.UserList): |
|
482 | 483 | """Class to store user input. |
|
483 | 484 | |
|
484 | 485 | It's basically a list, but slices return a string instead of a list, thus |
|
485 | 486 | allowing things like (assuming 'In' is an instance): |
|
486 | 487 | |
|
487 | 488 | exec In[4:7] |
|
488 | 489 | |
|
489 | 490 | or |
|
490 | 491 | |
|
491 | 492 | exec In[5:9] + In[14] + In[21:25]""" |
|
492 | 493 | |
|
493 | 494 | def __getslice__(self,i,j): |
|
494 | 495 | return ''.join(UserList.UserList.__getslice__(self,i,j)) |
|
495 | 496 | |
|
496 | 497 | #**************************************************************************** |
|
497 | 498 | # Local use exceptions |
|
498 | 499 | class SpaceInInput(exceptions.Exception): |
|
499 | 500 | pass |
|
500 | 501 | |
|
501 | 502 | #**************************************************************************** |
|
502 | 503 | # Main IPython class |
|
503 | 504 | |
|
504 | 505 | class InteractiveShell(code.InteractiveConsole, Logger, Magic): |
|
505 | 506 | """An enhanced console for Python.""" |
|
506 | 507 | |
|
507 | 508 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
508 | 509 | user_ns = None,banner2='', |
|
509 | 510 | custom_exceptions=((),None)): |
|
510 | 511 | |
|
511 | 512 | # Put a reference to self in builtins so that any form of embedded or |
|
512 | 513 | # imported code can test for being inside IPython. |
|
513 | 514 | __builtin__.__IPYTHON__ = self |
|
514 | 515 | |
|
515 | 516 | # And load into builtins ipmagic/ipalias as well |
|
516 | 517 | __builtin__.ipmagic = ipmagic |
|
517 | 518 | __builtin__.ipalias = ipalias |
|
518 | 519 | |
|
519 | 520 | # Add to __builtin__ other parts of IPython's public API |
|
520 | 521 | __builtin__.ip_set_hook = self.set_hook |
|
521 | 522 | |
|
522 | 523 | # Keep in the builtins a flag for when IPython is active. We set it |
|
523 | 524 | # with setdefault so that multiple nested IPythons don't clobber one |
|
524 | 525 | # another. Each will increase its value by one upon being activated, |
|
525 | 526 | # which also gives us a way to determine the nesting level. |
|
526 | 527 | __builtin__.__dict__.setdefault('__IPYTHON__active',0) |
|
527 | 528 | |
|
528 | 529 | # Inform the user of ipython's fast exit magics. |
|
529 | 530 | _exit = ' Use %Exit or %Quit to exit without confirmation.' |
|
530 | 531 | __builtin__.exit += _exit |
|
531 | 532 | __builtin__.quit += _exit |
|
532 | 533 | |
|
533 | 534 | # Create the namespace where the user will operate: |
|
534 | 535 | |
|
535 | 536 | # FIXME. For some strange reason, __builtins__ is showing up at user |
|
536 | 537 | # level as a dict instead of a module. This is a manual fix, but I |
|
537 | 538 | # should really track down where the problem is coming from. Alex |
|
538 | 539 | # Schmolck reported this problem first. |
|
539 | 540 | |
|
540 | 541 | # A useful post by Alex Martelli on this topic: |
|
541 | 542 | # Re: inconsistent value from __builtins__ |
|
542 | 543 | # Von: Alex Martelli <aleaxit@yahoo.com> |
|
543 | 544 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends |
|
544 | 545 | # Gruppen: comp.lang.python |
|
545 | 546 | # Referenzen: 1 |
|
546 | 547 | |
|
547 | 548 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: |
|
548 | 549 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) |
|
549 | 550 | # > <type 'dict'> |
|
550 | 551 | # > >>> print type(__builtins__) |
|
551 | 552 | # > <type 'module'> |
|
552 | 553 | # > Is this difference in return value intentional? |
|
553 | 554 | |
|
554 | 555 | # Well, it's documented that '__builtins__' can be either a dictionary |
|
555 | 556 | # or a module, and it's been that way for a long time. Whether it's |
|
556 | 557 | # intentional (or sensible), I don't know. In any case, the idea is that |
|
557 | 558 | # if you need to access the built-in namespace directly, you should start |
|
558 | 559 | # with "import __builtin__" (note, no 's') which will definitely give you |
|
559 | 560 | # a module. Yeah, it's somewhat confusing:-(. |
|
560 | 561 | |
|
561 | 562 | if user_ns is None: |
|
562 | 563 | # Set __name__ to __main__ to better match the behavior of the |
|
563 | 564 | # normal interpreter. |
|
564 | 565 | self.user_ns = {'__name__' :'__main__', |
|
565 | 566 | '__builtins__' : __builtin__, |
|
566 | 567 | } |
|
567 | 568 | else: |
|
568 | 569 | self.user_ns = user_ns |
|
569 | 570 | |
|
570 | 571 | # The user namespace MUST have a pointer to the shell itself. |
|
571 | 572 | self.user_ns[name] = self |
|
572 | 573 | |
|
573 | 574 | # We need to insert into sys.modules something that looks like a |
|
574 | 575 | # module but which accesses the IPython namespace, for shelve and |
|
575 | 576 | # pickle to work interactively. Normally they rely on getting |
|
576 | 577 | # everything out of __main__, but for embedding purposes each IPython |
|
577 | 578 | # instance has its own private namespace, so we can't go shoving |
|
578 | 579 | # everything into __main__. |
|
579 | 580 | |
|
580 | 581 | try: |
|
581 | 582 | main_name = self.user_ns['__name__'] |
|
582 | 583 | except KeyError: |
|
583 | 584 | raise KeyError,'user_ns dictionary MUST have a "__name__" key' |
|
584 | 585 | else: |
|
585 | 586 | #print "pickle hack in place" # dbg |
|
586 | 587 | sys.modules[main_name] = FakeModule(self.user_ns) |
|
587 | 588 | |
|
588 | 589 | # List of input with multi-line handling. |
|
589 | 590 | # Fill its zero entry, user counter starts at 1 |
|
590 | 591 | self.input_hist = InputList(['\n']) |
|
591 | 592 | |
|
592 | 593 | # list of visited directories |
|
593 | 594 | try: |
|
594 | 595 | self.dir_hist = [os.getcwd()] |
|
595 | 596 | except IOError, e: |
|
596 | 597 | self.dir_hist = [] |
|
597 | 598 | |
|
598 | 599 | # dict of output history |
|
599 | 600 | self.output_hist = {} |
|
600 | 601 | |
|
601 | 602 | # dict of names to be treated as system aliases. Each entry in the |
|
602 | 603 | # alias table must be a 2-tuple of the form (N,name), where N is the |
|
603 | 604 | # number of positional arguments of the alias. |
|
604 | 605 | self.alias_table = {} |
|
605 | 606 | |
|
606 | 607 | # dict of things NOT to alias (keywords, builtins and some special magics) |
|
607 | 608 | no_alias = {} |
|
608 | 609 | no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias'] |
|
609 | 610 | for key in keyword.kwlist + no_alias_magics: |
|
610 | 611 | no_alias[key] = 1 |
|
611 | 612 | no_alias.update(__builtin__.__dict__) |
|
612 | 613 | self.no_alias = no_alias |
|
613 | 614 | |
|
614 | 615 | |
|
615 | 616 | # make global variables for user access to these |
|
616 | 617 | self.user_ns['_ih'] = self.input_hist |
|
617 | 618 | self.user_ns['_oh'] = self.output_hist |
|
618 | 619 | self.user_ns['_dh'] = self.dir_hist |
|
619 | 620 | |
|
620 | 621 | # user aliases to input and output histories |
|
621 | 622 | self.user_ns['In'] = self.input_hist |
|
622 | 623 | self.user_ns['Out'] = self.output_hist |
|
623 | 624 | |
|
624 | 625 | # Store the actual shell's name |
|
625 | 626 | self.name = name |
|
626 | 627 | |
|
627 | 628 | # Object variable to store code object waiting execution. This is |
|
628 | 629 | # used mainly by the multithreaded shells, but it can come in handy in |
|
629 | 630 | # other situations. No need to use a Queue here, since it's a single |
|
630 | 631 | # item which gets cleared once run. |
|
631 | 632 | self.code_to_run = None |
|
632 | 633 | |
|
633 | 634 | # Job manager (for jobs run as background threads) |
|
634 | 635 | self.jobs = BackgroundJobManager() |
|
635 | 636 | # Put the job manager into builtins so it's always there. |
|
636 | 637 | __builtin__.jobs = self.jobs |
|
637 | 638 | |
|
638 | 639 | # escapes for automatic behavior on the command line |
|
639 | 640 | self.ESC_SHELL = '!' |
|
640 | 641 | self.ESC_HELP = '?' |
|
641 | 642 | self.ESC_MAGIC = '%' |
|
642 | 643 | self.ESC_QUOTE = ',' |
|
643 | 644 | self.ESC_QUOTE2 = ';' |
|
644 | 645 | self.ESC_PAREN = '/' |
|
645 | 646 | |
|
646 | 647 | # And their associated handlers |
|
647 | 648 | self.esc_handlers = {self.ESC_PAREN:self.handle_auto, |
|
648 | 649 | self.ESC_QUOTE:self.handle_auto, |
|
649 | 650 | self.ESC_QUOTE2:self.handle_auto, |
|
650 | 651 | self.ESC_MAGIC:self.handle_magic, |
|
651 | 652 | self.ESC_HELP:self.handle_help, |
|
652 | 653 | self.ESC_SHELL:self.handle_shell_escape, |
|
653 | 654 | } |
|
654 | 655 | |
|
655 | 656 | # class initializations |
|
656 | 657 | code.InteractiveConsole.__init__(self,locals = self.user_ns) |
|
657 | 658 | Logger.__init__(self,log_ns = self.user_ns) |
|
658 | 659 | Magic.__init__(self,self) |
|
659 | 660 | |
|
660 | 661 | # an ugly hack to get a pointer to the shell, so I can start writing |
|
661 | 662 | # magic code via this pointer instead of the current mixin salad. |
|
662 | 663 | Magic.set_shell(self,self) |
|
663 | 664 | |
|
665 | # Python source parser/formatter for syntax highlighting | |
|
666 | pyformat = Parser().format | |
|
667 | self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors']) | |
|
668 | ||
|
664 | 669 | # hooks holds pointers used for user-side customizations |
|
665 | 670 | self.hooks = Struct() |
|
666 | 671 | |
|
667 | 672 | # Set all default hooks, defined in the IPython.hooks module. |
|
668 | 673 | hooks = IPython.hooks |
|
669 | 674 | for hook_name in hooks.__all__: |
|
670 | 675 | self.set_hook(hook_name,getattr(hooks,hook_name)) |
|
671 | 676 | |
|
672 | 677 | # Flag to mark unconditional exit |
|
673 | 678 | self.exit_now = False |
|
674 | 679 | |
|
675 | 680 | self.usage_min = """\ |
|
676 | 681 | An enhanced console for Python. |
|
677 | 682 | Some of its features are: |
|
678 | 683 | - Readline support if the readline library is present. |
|
679 | 684 | - Tab completion in the local namespace. |
|
680 | 685 | - Logging of input, see command-line options. |
|
681 | 686 | - System shell escape via ! , eg !ls. |
|
682 | 687 | - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.) |
|
683 | 688 | - Keeps track of locally defined variables via %who, %whos. |
|
684 | 689 | - Show object information with a ? eg ?x or x? (use ?? for more info). |
|
685 | 690 | """ |
|
686 | 691 | if usage: self.usage = usage |
|
687 | 692 | else: self.usage = self.usage_min |
|
688 | 693 | |
|
689 | 694 | # Storage |
|
690 | 695 | self.rc = rc # This will hold all configuration information |
|
691 | 696 | self.inputcache = [] |
|
692 | 697 | self._boundcache = [] |
|
693 | 698 | self.pager = 'less' |
|
694 | 699 | # temporary files used for various purposes. Deleted at exit. |
|
695 | 700 | self.tempfiles = [] |
|
696 | 701 | |
|
697 | 702 | # Keep track of readline usage (later set by init_readline) |
|
698 | 703 | self.has_readline = 0 |
|
699 | 704 | |
|
700 | 705 | # for pushd/popd management |
|
701 | 706 | try: |
|
702 | 707 | self.home_dir = get_home_dir() |
|
703 | 708 | except HomeDirError,msg: |
|
704 | 709 | fatal(msg) |
|
705 | 710 | |
|
706 | 711 | self.dir_stack = [os.getcwd().replace(self.home_dir,'~')] |
|
707 | 712 | |
|
708 | 713 | # Functions to call the underlying shell. |
|
709 | 714 | |
|
710 | 715 | # utility to expand user variables via Itpl |
|
711 | 716 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), |
|
712 | 717 | self.user_ns)) |
|
713 | 718 | # The first is similar to os.system, but it doesn't return a value, |
|
714 | 719 | # and it allows interpolation of variables in the user's namespace. |
|
715 | 720 | self.system = lambda cmd: shell(self.var_expand(cmd), |
|
716 | 721 | header='IPython system call: ', |
|
717 | 722 | verbose=self.rc.system_verbose) |
|
718 | 723 | # These are for getoutput and getoutputerror: |
|
719 | 724 | self.getoutput = lambda cmd: \ |
|
720 | 725 | getoutput(self.var_expand(cmd), |
|
721 | 726 | header='IPython system call: ', |
|
722 | 727 | verbose=self.rc.system_verbose) |
|
723 | 728 | self.getoutputerror = lambda cmd: \ |
|
724 | 729 | getoutputerror(str(ItplNS(cmd.replace('#','\#'), |
|
725 | 730 | self.user_ns)), |
|
726 | 731 | header='IPython system call: ', |
|
727 | 732 | verbose=self.rc.system_verbose) |
|
728 | 733 | |
|
729 | 734 | # RegExp for splitting line contents into pre-char//first |
|
730 | 735 | # word-method//rest. For clarity, each group in on one line. |
|
731 | 736 | |
|
732 | 737 | # WARNING: update the regexp if the above escapes are changed, as they |
|
733 | 738 | # are hardwired in. |
|
734 | 739 | |
|
735 | 740 | # Don't get carried away with trying to make the autocalling catch too |
|
736 | 741 | # much: it's better to be conservative rather than to trigger hidden |
|
737 | 742 | # evals() somewhere and end up causing side effects. |
|
738 | 743 | |
|
739 | 744 | self.line_split = re.compile(r'^([\s*,;/])' |
|
740 | 745 | r'([\?\w\.]+\w*\s*)' |
|
741 | 746 | r'(\(?.*$)') |
|
742 | 747 | |
|
743 | 748 | # Original re, keep around for a while in case changes break something |
|
744 | 749 | #self.line_split = re.compile(r'(^[\s*!\?%,/]?)' |
|
745 | 750 | # r'(\s*[\?\w\.]+\w*\s*)' |
|
746 | 751 | # r'(\(?.*$)') |
|
747 | 752 | |
|
748 | 753 | # RegExp to identify potential function names |
|
749 | 754 | self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') |
|
750 | 755 | # RegExp to exclude strings with this start from autocalling |
|
751 | 756 | self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ') |
|
752 | 757 | # try to catch also methods for stuff in lists/tuples/dicts: off |
|
753 | 758 | # (experimental). For this to work, the line_split regexp would need |
|
754 | 759 | # to be modified so it wouldn't break things at '['. That line is |
|
755 | 760 | # nasty enough that I shouldn't change it until I can test it _well_. |
|
756 | 761 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') |
|
757 | 762 | |
|
758 | 763 | # keep track of where we started running (mainly for crash post-mortem) |
|
759 | 764 | self.starting_dir = os.getcwd() |
|
760 | 765 | |
|
761 | 766 | # Attributes for Logger mixin class, make defaults here |
|
762 | 767 | self._dolog = 0 |
|
763 | 768 | self.LOG = '' |
|
764 | 769 | self.LOGDEF = '.InteractiveShell.log' |
|
765 | 770 | self.LOGMODE = 'over' |
|
766 | 771 | self.LOGHEAD = Itpl( |
|
767 | 772 | """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE *** |
|
768 | 773 | #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW |
|
769 | 774 | #log# opts = $self.rc.opts |
|
770 | 775 | #log# args = $self.rc.args |
|
771 | 776 | #log# It is safe to make manual edits below here. |
|
772 | 777 | #log#----------------------------------------------------------------------- |
|
773 | 778 | """) |
|
774 | 779 | # Various switches which can be set |
|
775 | 780 | self.CACHELENGTH = 5000 # this is cheap, it's just text |
|
776 | 781 | self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__ |
|
777 | 782 | self.banner2 = banner2 |
|
778 | 783 | |
|
779 | 784 | # TraceBack handlers: |
|
780 | 785 | # Need two, one for syntax errors and one for other exceptions. |
|
781 | 786 | self.SyntaxTB = ultraTB.ListTB(color_scheme='NoColor') |
|
782 | 787 | # This one is initialized with an offset, meaning we always want to |
|
783 | 788 | # remove the topmost item in the traceback, which is our own internal |
|
784 | 789 | # code. Valid modes: ['Plain','Context','Verbose'] |
|
785 | 790 | self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain', |
|
786 | 791 | color_scheme='NoColor', |
|
787 | 792 | tb_offset = 1) |
|
788 | 793 | # and add any custom exception handlers the user may have specified |
|
789 | 794 | self.set_custom_exc(*custom_exceptions) |
|
790 | 795 | |
|
791 | 796 | # Object inspector |
|
792 | 797 | ins_colors = OInspect.InspectColors |
|
793 | 798 | code_colors = PyColorize.ANSICodeColors |
|
794 | 799 | self.inspector = OInspect.Inspector(ins_colors,code_colors,'NoColor') |
|
795 | 800 | self.autoindent = 0 |
|
796 | 801 | |
|
797 | 802 | # Make some aliases automatically |
|
798 | 803 | # Prepare list of shell aliases to auto-define |
|
799 | 804 | if os.name == 'posix': |
|
800 | 805 | auto_alias = ('mkdir mkdir', 'rmdir rmdir', |
|
801 | 806 | 'mv mv -i','rm rm -i','cp cp -i', |
|
802 | 807 | 'cat cat','less less','clear clear', |
|
803 | 808 | # a better ls |
|
804 | 809 | 'ls ls -F', |
|
805 | 810 | # long ls |
|
806 | 811 | 'll ls -lF', |
|
807 | 812 | # color ls |
|
808 | 813 | 'lc ls -F -o --color', |
|
809 | 814 | # ls normal files only |
|
810 | 815 | 'lf ls -F -o --color %l | grep ^-', |
|
811 | 816 | # ls symbolic links |
|
812 | 817 | 'lk ls -F -o --color %l | grep ^l', |
|
813 | 818 | # directories or links to directories, |
|
814 | 819 | 'ldir ls -F -o --color %l | grep /$', |
|
815 | 820 | # things which are executable |
|
816 | 821 | 'lx ls -F -o --color %l | grep ^-..x', |
|
817 | 822 | ) |
|
818 | 823 | elif os.name in ['nt','dos']: |
|
819 | 824 | auto_alias = ('dir dir /on', 'ls dir /on', |
|
820 | 825 | 'ddir dir /ad /on', 'ldir dir /ad /on', |
|
821 | 826 | 'mkdir mkdir','rmdir rmdir','echo echo', |
|
822 | 827 | 'ren ren','cls cls','copy copy') |
|
823 | 828 | else: |
|
824 | 829 | auto_alias = () |
|
825 | 830 | self.auto_alias = map(lambda s:s.split(None,1),auto_alias) |
|
826 | 831 | # Call the actual (public) initializer |
|
827 | 832 | self.init_auto_alias() |
|
828 | 833 | # end __init__ |
|
829 | 834 | |
|
830 | 835 | def set_hook(self,name,hook): |
|
831 | 836 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
832 | 837 | |
|
833 | 838 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
834 | 839 | resetting one of these hooks, you can modify IPython's behavior to |
|
835 | 840 | call at runtime your own routines.""" |
|
836 | 841 | |
|
837 | 842 | # At some point in the future, this should validate the hook before it |
|
838 | 843 | # accepts it. Probably at least check that the hook takes the number |
|
839 | 844 | # of args it's supposed to. |
|
840 | 845 | setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__)) |
|
841 | 846 | |
|
842 | 847 | def set_custom_exc(self,exc_tuple,handler): |
|
843 | 848 | """set_custom_exc(exc_tuple,handler) |
|
844 | 849 | |
|
845 | 850 | Set a custom exception handler, which will be called if any of the |
|
846 | 851 | exceptions in exc_tuple occur in the mainloop (specifically, in the |
|
847 | 852 | runcode() method. |
|
848 | 853 | |
|
849 | 854 | Inputs: |
|
850 | 855 | |
|
851 | 856 | - exc_tuple: a *tuple* of valid exceptions to call the defined |
|
852 | 857 | handler for. It is very important that you use a tuple, and NOT A |
|
853 | 858 | LIST here, because of the way Python's except statement works. If |
|
854 | 859 | you only want to trap a single exception, use a singleton tuple: |
|
855 | 860 | |
|
856 | 861 | exc_tuple == (MyCustomException,) |
|
857 | 862 | |
|
858 | 863 | - handler: this must be defined as a function with the following |
|
859 | 864 | basic interface: def my_handler(self,etype,value,tb). |
|
860 | 865 | |
|
861 | 866 | This will be made into an instance method (via new.instancemethod) |
|
862 | 867 | of IPython itself, and it will be called if any of the exceptions |
|
863 | 868 | listed in the exc_tuple are caught. If the handler is None, an |
|
864 | 869 | internal basic one is used, which just prints basic info. |
|
865 | 870 | |
|
866 | 871 | WARNING: by putting in your own exception handler into IPython's main |
|
867 | 872 | execution loop, you run a very good chance of nasty crashes. This |
|
868 | 873 | facility should only be used if you really know what you are doing.""" |
|
869 | 874 | |
|
870 | 875 | assert type(exc_tuple)==type(()) , \ |
|
871 | 876 | "The custom exceptions must be given AS A TUPLE." |
|
872 | 877 | |
|
873 | 878 | def dummy_handler(self,etype,value,tb): |
|
874 | 879 | print '*** Simple custom exception handler ***' |
|
875 | 880 | print 'Exception type :',etype |
|
876 | 881 | print 'Exception value:',value |
|
877 | 882 | print 'Traceback :',tb |
|
878 | 883 | print 'Source code :','\n'.join(self.buffer) |
|
879 | 884 | |
|
880 | 885 | if handler is None: handler = dummy_handler |
|
881 | 886 | |
|
882 | 887 | self.CustomTB = new.instancemethod(handler,self,self.__class__) |
|
883 | 888 | self.custom_exceptions = exc_tuple |
|
884 | 889 | |
|
885 | 890 | def set_custom_completer(self,completer,pos=0): |
|
886 | 891 | """set_custom_completer(completer,pos=0) |
|
887 | 892 | |
|
888 | 893 | Adds a new custom completer function. |
|
889 | 894 | |
|
890 | 895 | The position argument (defaults to 0) is the index in the completers |
|
891 | 896 | list where you want the completer to be inserted.""" |
|
892 | 897 | |
|
893 | 898 | newcomp = new.instancemethod(completer,self.Completer, |
|
894 | 899 | self.Completer.__class__) |
|
895 | 900 | self.Completer.matchers.insert(pos,newcomp) |
|
896 | 901 | |
|
897 | 902 | def complete(self,text): |
|
898 | 903 | """Return a sorted list of all possible completions on text. |
|
899 | 904 | |
|
900 | 905 | Inputs: |
|
901 | 906 | |
|
902 | 907 | - text: a string of text to be completed on. |
|
903 | 908 | |
|
904 | 909 | This is a wrapper around the completion mechanism, similar to what |
|
905 | 910 | readline does at the command line when the TAB key is hit. By |
|
906 | 911 | exposing it as a method, it can be used by other non-readline |
|
907 | 912 | environments (such as GUIs) for text completion. |
|
908 | 913 | |
|
909 | 914 | Simple usage example: |
|
910 | 915 | |
|
911 | 916 | In [1]: x = 'hello' |
|
912 | 917 | |
|
913 | 918 | In [2]: __IP.complete('x.l') |
|
914 | 919 | Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']""" |
|
915 | 920 | |
|
916 | 921 | complete = self.Completer.complete |
|
917 | 922 | state = 0 |
|
918 | 923 | # use a dict so we get unique keys, since ipyhton's multiple |
|
919 | 924 | # completers can return duplicates. |
|
920 | 925 | comps = {} |
|
921 | 926 | while True: |
|
922 | 927 | newcomp = complete(text,state) |
|
923 | 928 | if newcomp is None: |
|
924 | 929 | break |
|
925 | 930 | comps[newcomp] = 1 |
|
926 | 931 | state += 1 |
|
927 | 932 | outcomps = comps.keys() |
|
928 | 933 | outcomps.sort() |
|
929 | 934 | return outcomps |
|
930 | 935 | |
|
931 | 936 | def post_config_initialization(self): |
|
932 | 937 | """Post configuration init method |
|
933 | 938 | |
|
934 | 939 | This is called after the configuration files have been processed to |
|
935 | 940 | 'finalize' the initialization.""" |
|
936 | 941 | |
|
937 | 942 | # dynamic data that survives through sessions |
|
938 | 943 | # XXX make the filename a config option? |
|
939 | 944 | persist_base = 'persist' |
|
940 | 945 | if self.rc.profile: |
|
941 | 946 | persist_base += '_%s' % self.rc.profile |
|
942 | 947 | self.persist_fname = os.path.join(self.rc.ipythondir,persist_base) |
|
943 | 948 | |
|
944 | 949 | try: |
|
945 | 950 | self.persist = pickle.load(file(self.persist_fname)) |
|
946 | 951 | except: |
|
947 | 952 | self.persist = {} |
|
948 | 953 | |
|
949 | 954 | def init_auto_alias(self): |
|
950 | 955 | """Define some aliases automatically. |
|
951 | 956 | |
|
952 | 957 | These are ALL parameter-less aliases""" |
|
953 | 958 | for alias,cmd in self.auto_alias: |
|
954 | 959 | self.alias_table[alias] = (0,cmd) |
|
955 | 960 | |
|
956 | 961 | def alias_table_validate(self,verbose=0): |
|
957 | 962 | """Update information about the alias table. |
|
958 | 963 | |
|
959 | 964 | In particular, make sure no Python keywords/builtins are in it.""" |
|
960 | 965 | |
|
961 | 966 | no_alias = self.no_alias |
|
962 | 967 | for k in self.alias_table.keys(): |
|
963 | 968 | if k in no_alias: |
|
964 | 969 | del self.alias_table[k] |
|
965 | 970 | if verbose: |
|
966 | 971 | print ("Deleting alias <%s>, it's a Python " |
|
967 | 972 | "keyword or builtin." % k) |
|
968 | 973 | |
|
969 | 974 | def set_autoindent(self,value=None): |
|
970 | 975 | """Set the autoindent flag, checking for readline support. |
|
971 | 976 | |
|
972 | 977 | If called with no arguments, it acts as a toggle.""" |
|
973 | 978 | |
|
974 | 979 | if not self.has_readline: |
|
975 | 980 | if os.name == 'posix': |
|
976 | 981 | warn("The auto-indent feature requires the readline library") |
|
977 | 982 | self.autoindent = 0 |
|
978 | 983 | return |
|
979 | 984 | if value is None: |
|
980 | 985 | self.autoindent = not self.autoindent |
|
981 | 986 | else: |
|
982 | 987 | self.autoindent = value |
|
983 | 988 | |
|
984 | 989 | def rc_set_toggle(self,rc_field,value=None): |
|
985 | 990 | """Set or toggle a field in IPython's rc config. structure. |
|
986 | 991 | |
|
987 | 992 | If called with no arguments, it acts as a toggle. |
|
988 | 993 | |
|
989 | 994 | If called with a non-existent field, the resulting AttributeError |
|
990 | 995 | exception will propagate out.""" |
|
991 | 996 | |
|
992 | 997 | rc_val = getattr(self.rc,rc_field) |
|
993 | 998 | if value is None: |
|
994 | 999 | value = not rc_val |
|
995 | 1000 | setattr(self.rc,rc_field,value) |
|
996 | 1001 | |
|
997 | 1002 | def user_setup(self,ipythondir,rc_suffix,mode='install'): |
|
998 | 1003 | """Install the user configuration directory. |
|
999 | 1004 | |
|
1000 | 1005 | Can be called when running for the first time or to upgrade the user's |
|
1001 | 1006 | .ipython/ directory with the mode parameter. Valid modes are 'install' |
|
1002 | 1007 | and 'upgrade'.""" |
|
1003 | 1008 | |
|
1004 | 1009 | def wait(): |
|
1005 | 1010 | try: |
|
1006 | 1011 | raw_input("Please press <RETURN> to start IPython.") |
|
1007 | 1012 | except EOFError: |
|
1008 | 1013 | print >> Term.cout |
|
1009 | 1014 | print '*'*70 |
|
1010 | 1015 | |
|
1011 | 1016 | cwd = os.getcwd() # remember where we started |
|
1012 | 1017 | glb = glob.glob |
|
1013 | 1018 | print '*'*70 |
|
1014 | 1019 | if mode == 'install': |
|
1015 | 1020 | print \ |
|
1016 | 1021 | """Welcome to IPython. I will try to create a personal configuration directory |
|
1017 | 1022 | where you can customize many aspects of IPython's functionality in:\n""" |
|
1018 | 1023 | else: |
|
1019 | 1024 | print 'I am going to upgrade your configuration in:' |
|
1020 | 1025 | |
|
1021 | 1026 | print ipythondir |
|
1022 | 1027 | |
|
1023 | 1028 | rcdirend = os.path.join('IPython','UserConfig') |
|
1024 | 1029 | cfg = lambda d: os.path.join(d,rcdirend) |
|
1025 | 1030 | try: |
|
1026 | 1031 | rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] |
|
1027 | 1032 | except IOError: |
|
1028 | 1033 | warning = """ |
|
1029 | 1034 | Installation error. IPython's directory was not found. |
|
1030 | 1035 | |
|
1031 | 1036 | Check the following: |
|
1032 | 1037 | |
|
1033 | 1038 | The ipython/IPython directory should be in a directory belonging to your |
|
1034 | 1039 | PYTHONPATH environment variable (that is, it should be in a directory |
|
1035 | 1040 | belonging to sys.path). You can copy it explicitly there or just link to it. |
|
1036 | 1041 | |
|
1037 | 1042 | IPython will proceed with builtin defaults. |
|
1038 | 1043 | """ |
|
1039 | 1044 | warn(warning) |
|
1040 | 1045 | wait() |
|
1041 | 1046 | return |
|
1042 | 1047 | |
|
1043 | 1048 | if mode == 'install': |
|
1044 | 1049 | try: |
|
1045 | 1050 | shutil.copytree(rcdir,ipythondir) |
|
1046 | 1051 | os.chdir(ipythondir) |
|
1047 | 1052 | rc_files = glb("ipythonrc*") |
|
1048 | 1053 | for rc_file in rc_files: |
|
1049 | 1054 | os.rename(rc_file,rc_file+rc_suffix) |
|
1050 | 1055 | except: |
|
1051 | 1056 | warning = """ |
|
1052 | 1057 | |
|
1053 | 1058 | There was a problem with the installation: |
|
1054 | 1059 | %s |
|
1055 | 1060 | Try to correct it or contact the developers if you think it's a bug. |
|
1056 | 1061 | IPython will proceed with builtin defaults.""" % sys.exc_info()[1] |
|
1057 | 1062 | warn(warning) |
|
1058 | 1063 | wait() |
|
1059 | 1064 | return |
|
1060 | 1065 | |
|
1061 | 1066 | elif mode == 'upgrade': |
|
1062 | 1067 | try: |
|
1063 | 1068 | os.chdir(ipythondir) |
|
1064 | 1069 | except: |
|
1065 | 1070 | print """ |
|
1066 | 1071 | Can not upgrade: changing to directory %s failed. Details: |
|
1067 | 1072 | %s |
|
1068 | 1073 | """ % (ipythondir,sys.exc_info()[1]) |
|
1069 | 1074 | wait() |
|
1070 | 1075 | return |
|
1071 | 1076 | else: |
|
1072 | 1077 | sources = glb(os.path.join(rcdir,'[A-Za-z]*')) |
|
1073 | 1078 | for new_full_path in sources: |
|
1074 | 1079 | new_filename = os.path.basename(new_full_path) |
|
1075 | 1080 | if new_filename.startswith('ipythonrc'): |
|
1076 | 1081 | new_filename = new_filename + rc_suffix |
|
1077 | 1082 | # The config directory should only contain files, skip any |
|
1078 | 1083 | # directories which may be there (like CVS) |
|
1079 | 1084 | if os.path.isdir(new_full_path): |
|
1080 | 1085 | continue |
|
1081 | 1086 | if os.path.exists(new_filename): |
|
1082 | 1087 | old_file = new_filename+'.old' |
|
1083 | 1088 | if os.path.exists(old_file): |
|
1084 | 1089 | os.remove(old_file) |
|
1085 | 1090 | os.rename(new_filename,old_file) |
|
1086 | 1091 | shutil.copy(new_full_path,new_filename) |
|
1087 | 1092 | else: |
|
1088 | 1093 | raise ValueError,'unrecognized mode for install:',`mode` |
|
1089 | 1094 | |
|
1090 | 1095 | # Fix line-endings to those native to each platform in the config |
|
1091 | 1096 | # directory. |
|
1092 | 1097 | try: |
|
1093 | 1098 | os.chdir(ipythondir) |
|
1094 | 1099 | except: |
|
1095 | 1100 | print """ |
|
1096 | 1101 | Problem: changing to directory %s failed. |
|
1097 | 1102 | Details: |
|
1098 | 1103 | %s |
|
1099 | 1104 | |
|
1100 | 1105 | Some configuration files may have incorrect line endings. This should not |
|
1101 | 1106 | cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) |
|
1102 | 1107 | wait() |
|
1103 | 1108 | else: |
|
1104 | 1109 | for fname in glb('ipythonrc*'): |
|
1105 | 1110 | try: |
|
1106 | 1111 | native_line_ends(fname,backup=0) |
|
1107 | 1112 | except IOError: |
|
1108 | 1113 | pass |
|
1109 | 1114 | |
|
1110 | 1115 | if mode == 'install': |
|
1111 | 1116 | print """ |
|
1112 | 1117 | Successful installation! |
|
1113 | 1118 | |
|
1114 | 1119 | Please read the sections 'Initial Configuration' and 'Quick Tips' in the |
|
1115 | 1120 | IPython manual (there are both HTML and PDF versions supplied with the |
|
1116 | 1121 | distribution) to make sure that your system environment is properly configured |
|
1117 | 1122 | to take advantage of IPython's features.""" |
|
1118 | 1123 | else: |
|
1119 | 1124 | print """ |
|
1120 | 1125 | Successful upgrade! |
|
1121 | 1126 | |
|
1122 | 1127 | All files in your directory: |
|
1123 | 1128 | %(ipythondir)s |
|
1124 | 1129 | which would have been overwritten by the upgrade were backed up with a .old |
|
1125 | 1130 | extension. If you had made particular customizations in those files you may |
|
1126 | 1131 | want to merge them back into the new files.""" % locals() |
|
1127 | 1132 | wait() |
|
1128 | 1133 | os.chdir(cwd) |
|
1129 | 1134 | # end user_setup() |
|
1130 | 1135 | |
|
1131 | 1136 | def atexit_operations(self): |
|
1132 | 1137 | """This will be executed at the time of exit. |
|
1133 | 1138 | |
|
1134 | 1139 | Saving of persistent data should be performed here. """ |
|
1135 | 1140 | |
|
1136 | 1141 | # input history |
|
1137 | 1142 | self.savehist() |
|
1138 | 1143 | |
|
1139 | 1144 | # Cleanup all tempfiles left around |
|
1140 | 1145 | for tfile in self.tempfiles: |
|
1141 | 1146 | try: |
|
1142 | 1147 | os.unlink(tfile) |
|
1143 | 1148 | except OSError: |
|
1144 | 1149 | pass |
|
1145 | 1150 | |
|
1146 | 1151 | # save the "persistent data" catch-all dictionary |
|
1147 | 1152 | try: |
|
1148 | 1153 | pickle.dump(self.persist, open(self.persist_fname,"w")) |
|
1149 | 1154 | except: |
|
1150 | 1155 | print "*** ERROR *** persistent data saving failed." |
|
1151 | 1156 | |
|
1152 | 1157 | def savehist(self): |
|
1153 | 1158 | """Save input history to a file (via readline library).""" |
|
1154 | 1159 | try: |
|
1155 | 1160 | self.readline.write_history_file(self.histfile) |
|
1156 | 1161 | except: |
|
1157 | 1162 | print 'Unable to save IPython command history to file: ' + \ |
|
1158 | 1163 | `self.histfile` |
|
1159 | 1164 | |
|
1160 | 1165 | def pre_readline(self): |
|
1161 | 1166 | """readline hook to be used at the start of each line. |
|
1162 | 1167 | |
|
1163 | 1168 | Currently it handles auto-indent only.""" |
|
1164 | 1169 | |
|
1165 | 1170 | self.readline.insert_text(' '* self.readline_indent) |
|
1166 | 1171 | |
|
1167 | 1172 | def init_readline(self): |
|
1168 | 1173 | """Command history completion/saving/reloading.""" |
|
1169 | 1174 | try: |
|
1170 | 1175 | import readline |
|
1171 | 1176 | self.Completer = MagicCompleter(self, |
|
1172 | 1177 | self.user_ns, |
|
1173 | 1178 | self.rc.readline_omit__names, |
|
1174 | 1179 | self.alias_table) |
|
1175 | 1180 | except ImportError,NameError: |
|
1176 | 1181 | # If FlexCompleter failed to import, MagicCompleter won't be |
|
1177 | 1182 | # defined. This can happen because of a problem with readline |
|
1178 | 1183 | self.has_readline = 0 |
|
1179 | 1184 | # no point in bugging windows users with this every time: |
|
1180 | 1185 | if os.name == 'posix': |
|
1181 | 1186 | warn('Readline services not available on this platform.') |
|
1182 | 1187 | else: |
|
1183 | 1188 | import atexit |
|
1184 | 1189 | |
|
1185 | 1190 | # Platform-specific configuration |
|
1186 | 1191 | if os.name == 'nt': |
|
1187 | 1192 | # readline under Windows modifies the default exit behavior |
|
1188 | 1193 | # from being Ctrl-Z/Return to the Unix Ctrl-D one. |
|
1189 | 1194 | __builtin__.exit = __builtin__.quit = \ |
|
1190 | 1195 | ('Use Ctrl-D (i.e. EOF) to exit. ' |
|
1191 | 1196 | 'Use %Exit or %Quit to exit without confirmation.') |
|
1192 | 1197 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1193 | 1198 | else: |
|
1194 | 1199 | self.readline_startup_hook = readline.set_startup_hook |
|
1195 | 1200 | |
|
1196 | 1201 | # Load user's initrc file (readline config) |
|
1197 | 1202 | inputrc_name = os.environ.get('INPUTRC') |
|
1198 | 1203 | if inputrc_name is None: |
|
1199 | 1204 | home_dir = get_home_dir() |
|
1200 | 1205 | if home_dir is not None: |
|
1201 | 1206 | inputrc_name = os.path.join(home_dir,'.inputrc') |
|
1202 | 1207 | if os.path.isfile(inputrc_name): |
|
1203 | 1208 | try: |
|
1204 | 1209 | readline.read_init_file(inputrc_name) |
|
1205 | 1210 | except: |
|
1206 | 1211 | warn('Problems reading readline initialization file <%s>' |
|
1207 | 1212 | % inputrc_name) |
|
1208 | 1213 | |
|
1209 | 1214 | self.has_readline = 1 |
|
1210 | 1215 | self.readline = readline |
|
1211 | 1216 | self.readline_indent = 0 # for auto-indenting via readline |
|
1212 | 1217 | # save this in sys so embedded copies can restore it properly |
|
1213 | 1218 | sys.ipcompleter = self.Completer.complete |
|
1214 | 1219 | readline.set_completer(self.Completer.complete) |
|
1215 | 1220 | |
|
1216 | 1221 | # Configure readline according to user's prefs |
|
1217 | 1222 | for rlcommand in self.rc.readline_parse_and_bind: |
|
1218 | 1223 | readline.parse_and_bind(rlcommand) |
|
1219 | 1224 | |
|
1220 | 1225 | # remove some chars from the delimiters list |
|
1221 | 1226 | delims = readline.get_completer_delims() |
|
1222 | 1227 | delims = delims.translate(string._idmap, |
|
1223 | 1228 | self.rc.readline_remove_delims) |
|
1224 | 1229 | readline.set_completer_delims(delims) |
|
1225 | 1230 | # otherwise we end up with a monster history after a while: |
|
1226 | 1231 | readline.set_history_length(1000) |
|
1227 | 1232 | try: |
|
1228 | 1233 | #print '*** Reading readline history' # dbg |
|
1229 | 1234 | readline.read_history_file(self.histfile) |
|
1230 | 1235 | except IOError: |
|
1231 | 1236 | pass # It doesn't exist yet. |
|
1232 | 1237 | |
|
1233 | 1238 | atexit.register(self.atexit_operations) |
|
1234 | 1239 | del atexit |
|
1235 | 1240 | |
|
1236 | 1241 | # Configure auto-indent for all platforms |
|
1237 | 1242 | self.set_autoindent(self.rc.autoindent) |
|
1238 | 1243 | |
|
1239 | 1244 | def showsyntaxerror(self, filename=None): |
|
1240 | 1245 | """Display the syntax error that just occurred. |
|
1241 | 1246 | |
|
1242 | 1247 | This doesn't display a stack trace because there isn't one. |
|
1243 | 1248 | |
|
1244 | 1249 | If a filename is given, it is stuffed in the exception instead |
|
1245 | 1250 | of what was there before (because Python's parser always uses |
|
1246 | 1251 | "<string>" when reading from a string). |
|
1247 | 1252 | """ |
|
1248 | 1253 | type, value, sys.last_traceback = sys.exc_info() |
|
1249 | 1254 | sys.last_type = type |
|
1250 | 1255 | sys.last_value = value |
|
1251 | 1256 | if filename and type is SyntaxError: |
|
1252 | 1257 | # Work hard to stuff the correct filename in the exception |
|
1253 | 1258 | try: |
|
1254 | 1259 | msg, (dummy_filename, lineno, offset, line) = value |
|
1255 | 1260 | except: |
|
1256 | 1261 | # Not the format we expect; leave it alone |
|
1257 | 1262 | pass |
|
1258 | 1263 | else: |
|
1259 | 1264 | # Stuff in the right filename |
|
1260 | 1265 | try: |
|
1261 | 1266 | # Assume SyntaxError is a class exception |
|
1262 | 1267 | value = SyntaxError(msg, (filename, lineno, offset, line)) |
|
1263 | 1268 | except: |
|
1264 | 1269 | # If that failed, assume SyntaxError is a string |
|
1265 | 1270 | value = msg, (filename, lineno, offset, line) |
|
1266 | 1271 | self.SyntaxTB(type,value,[]) |
|
1267 | 1272 | |
|
1268 | 1273 | def debugger(self): |
|
1269 | 1274 | """Call the pdb debugger.""" |
|
1270 | 1275 | |
|
1271 | 1276 | if not self.rc.pdb: |
|
1272 | 1277 | return |
|
1273 | 1278 | pdb.pm() |
|
1274 | 1279 | |
|
1275 | 1280 | def showtraceback(self,exc_tuple = None,filename=None): |
|
1276 | 1281 | """Display the exception that just occurred.""" |
|
1277 | 1282 | |
|
1278 | 1283 | # Though this won't be called by syntax errors in the input line, |
|
1279 | 1284 | # there may be SyntaxError cases whith imported code. |
|
1280 | 1285 | if exc_tuple is None: |
|
1281 | 1286 | type, value, tb = sys.exc_info() |
|
1282 | 1287 | else: |
|
1283 | 1288 | type, value, tb = exc_tuple |
|
1284 | 1289 | if type is SyntaxError: |
|
1285 | 1290 | self.showsyntaxerror(filename) |
|
1286 | 1291 | else: |
|
1287 | 1292 | sys.last_type = type |
|
1288 | 1293 | sys.last_value = value |
|
1289 | 1294 | sys.last_traceback = tb |
|
1290 | 1295 | self.InteractiveTB() |
|
1291 | 1296 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1292 | 1297 | # pdb mucks up readline, fix it back |
|
1293 | 1298 | self.readline.set_completer(self.Completer.complete) |
|
1294 | 1299 | |
|
1295 | 1300 | def update_cache(self, line): |
|
1296 | 1301 | """puts line into cache""" |
|
1297 | 1302 | self.inputcache.insert(0, line) # This copies the cache every time ... :-( |
|
1298 | 1303 | if len(self.inputcache) >= self.CACHELENGTH: |
|
1299 | 1304 | self.inputcache.pop() # This not :-) |
|
1300 | 1305 | |
|
1301 | 1306 | def name_space_init(self): |
|
1302 | 1307 | """Create local namespace.""" |
|
1303 | 1308 | # We want this to be a method to facilitate embedded initialization. |
|
1304 | 1309 | code.InteractiveConsole.__init__(self,self.user_ns) |
|
1305 | 1310 | |
|
1306 | 1311 | def mainloop(self,banner=None): |
|
1307 | 1312 | """Creates the local namespace and starts the mainloop. |
|
1308 | 1313 | |
|
1309 | 1314 | If an optional banner argument is given, it will override the |
|
1310 | 1315 | internally created default banner.""" |
|
1311 | 1316 | |
|
1312 | 1317 | self.name_space_init() |
|
1313 | 1318 | if self.rc.c: # Emulate Python's -c option |
|
1314 | 1319 | self.exec_init_cmd() |
|
1315 | 1320 | if banner is None: |
|
1316 | 1321 | if self.rc.banner: |
|
1317 | 1322 | banner = self.BANNER+self.banner2 |
|
1318 | 1323 | else: |
|
1319 | 1324 | banner = '' |
|
1320 | 1325 | self.interact(banner) |
|
1321 | 1326 | |
|
1322 | 1327 | def exec_init_cmd(self): |
|
1323 | 1328 | """Execute a command given at the command line. |
|
1324 | 1329 | |
|
1325 | 1330 | This emulates Python's -c option.""" |
|
1326 | 1331 | |
|
1327 | 1332 | sys.argv = ['-c'] |
|
1328 | 1333 | self.push(self.rc.c) |
|
1329 | 1334 | |
|
1330 | 1335 | def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0): |
|
1331 | 1336 | """Embeds IPython into a running python program. |
|
1332 | 1337 | |
|
1333 | 1338 | Input: |
|
1334 | 1339 | |
|
1335 | 1340 | - header: An optional header message can be specified. |
|
1336 | 1341 | |
|
1337 | 1342 | - local_ns, global_ns: working namespaces. If given as None, the |
|
1338 | 1343 | IPython-initialized one is updated with __main__.__dict__, so that |
|
1339 | 1344 | program variables become visible but user-specific configuration |
|
1340 | 1345 | remains possible. |
|
1341 | 1346 | |
|
1342 | 1347 | - stack_depth: specifies how many levels in the stack to go to |
|
1343 | 1348 | looking for namespaces (when local_ns and global_ns are None). This |
|
1344 | 1349 | allows an intermediate caller to make sure that this function gets |
|
1345 | 1350 | the namespace from the intended level in the stack. By default (0) |
|
1346 | 1351 | it will get its locals and globals from the immediate caller. |
|
1347 | 1352 | |
|
1348 | 1353 | Warning: it's possible to use this in a program which is being run by |
|
1349 | 1354 | IPython itself (via %run), but some funny things will happen (a few |
|
1350 | 1355 | globals get overwritten). In the future this will be cleaned up, as |
|
1351 | 1356 | there is no fundamental reason why it can't work perfectly.""" |
|
1352 | 1357 | |
|
1353 | 1358 | # Patch for global embedding to make sure that things don't overwrite |
|
1354 | 1359 | # user globals accidentally. Thanks to Richard <rxe@renre-europe.com> |
|
1355 | 1360 | # FIXME. Test this a bit more carefully (the if.. is new) |
|
1356 | 1361 | if local_ns is None and global_ns is None: |
|
1357 | 1362 | self.user_ns.update(__main__.__dict__) |
|
1358 | 1363 | |
|
1359 | 1364 | # Get locals and globals from caller |
|
1360 | 1365 | if local_ns is None or global_ns is None: |
|
1361 | 1366 | call_frame = sys._getframe(stack_depth).f_back |
|
1362 | 1367 | |
|
1363 | 1368 | if local_ns is None: |
|
1364 | 1369 | local_ns = call_frame.f_locals |
|
1365 | 1370 | if global_ns is None: |
|
1366 | 1371 | global_ns = call_frame.f_globals |
|
1367 | 1372 | |
|
1368 | 1373 | # Update namespaces and fire up interpreter |
|
1369 | 1374 | self.user_ns.update(local_ns) |
|
1370 | 1375 | self.interact(header) |
|
1371 | 1376 | |
|
1372 | 1377 | # Remove locals from namespace |
|
1373 | 1378 | for k in local_ns: |
|
1374 | 1379 | del self.user_ns[k] |
|
1375 | 1380 | |
|
1376 | 1381 | def interact(self, banner=None): |
|
1377 | 1382 | """Closely emulate the interactive Python console. |
|
1378 | 1383 | |
|
1379 | 1384 | The optional banner argument specify the banner to print |
|
1380 | 1385 | before the first interaction; by default it prints a banner |
|
1381 | 1386 | similar to the one printed by the real Python interpreter, |
|
1382 | 1387 | followed by the current class name in parentheses (so as not |
|
1383 | 1388 | to confuse this with the real interpreter -- since it's so |
|
1384 | 1389 | close!). |
|
1385 | 1390 | |
|
1386 | 1391 | """ |
|
1387 | 1392 | cprt = 'Type "copyright", "credits" or "license" for more information.' |
|
1388 | 1393 | if banner is None: |
|
1389 | 1394 | self.write("Python %s on %s\n%s\n(%s)\n" % |
|
1390 | 1395 | (sys.version, sys.platform, cprt, |
|
1391 | 1396 | self.__class__.__name__)) |
|
1392 | 1397 | else: |
|
1393 | 1398 | self.write(banner) |
|
1394 | 1399 | |
|
1395 | 1400 | more = 0 |
|
1396 | 1401 | |
|
1397 | 1402 | # Mark activity in the builtins |
|
1398 | 1403 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
1399 | 1404 | |
|
1400 | 1405 | # exit_now is set by a call to %Exit or %Quit |
|
1401 | 1406 | while not self.exit_now: |
|
1402 | 1407 | try: |
|
1403 | 1408 | if more: |
|
1404 | 1409 | prompt = self.outputcache.prompt2 |
|
1405 | 1410 | if self.autoindent: |
|
1406 | 1411 | self.readline_startup_hook(self.pre_readline) |
|
1407 | 1412 | else: |
|
1408 | 1413 | prompt = self.outputcache.prompt1 |
|
1409 | 1414 | try: |
|
1410 | 1415 | line = self.raw_input(prompt) |
|
1411 | 1416 | if self.autoindent: |
|
1412 | 1417 | self.readline_startup_hook(None) |
|
1413 | 1418 | except EOFError: |
|
1414 | 1419 | if self.autoindent: |
|
1415 | 1420 | self.readline_startup_hook(None) |
|
1416 | 1421 | self.write("\n") |
|
1417 | 1422 | if self.rc.confirm_exit: |
|
1418 | 1423 | if ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
1419 | 1424 | break |
|
1420 | 1425 | else: |
|
1421 | 1426 | break |
|
1422 | 1427 | else: |
|
1423 | 1428 | more = self.push(line) |
|
1424 | 1429 | # Auto-indent management |
|
1425 | 1430 | if self.autoindent: |
|
1426 | 1431 | if line: |
|
1427 | 1432 | ini_spaces = re.match('^(\s+)',line) |
|
1428 | 1433 | if ini_spaces: |
|
1429 | 1434 | nspaces = ini_spaces.end() |
|
1430 | 1435 | else: |
|
1431 | 1436 | nspaces = 0 |
|
1432 | 1437 | self.readline_indent = nspaces |
|
1433 | 1438 | |
|
1434 | 1439 | if line[-1] == ':': |
|
1435 | 1440 | self.readline_indent += 4 |
|
1436 | 1441 | elif re.match(r'^\s+raise|^\s+return',line): |
|
1437 | 1442 | self.readline_indent -= 4 |
|
1438 | 1443 | else: |
|
1439 | 1444 | self.readline_indent = 0 |
|
1440 | 1445 | |
|
1441 | 1446 | except KeyboardInterrupt: |
|
1442 | 1447 | self.write("\nKeyboardInterrupt\n") |
|
1443 | 1448 | self.resetbuffer() |
|
1444 | 1449 | more = 0 |
|
1445 | 1450 | # keep cache in sync with the prompt counter: |
|
1446 | 1451 | self.outputcache.prompt_count -= 1 |
|
1447 | 1452 | |
|
1448 | 1453 | if self.autoindent: |
|
1449 | 1454 | self.readline_indent = 0 |
|
1450 | 1455 | |
|
1451 | 1456 | except bdb.BdbQuit: |
|
1452 | 1457 | warn("The Python debugger has exited with a BdbQuit exception.\n" |
|
1453 | 1458 | "Because of how pdb handles the stack, it is impossible\n" |
|
1454 | 1459 | "for IPython to properly format this particular exception.\n" |
|
1455 | 1460 | "IPython will resume normal operation.") |
|
1456 | 1461 | |
|
1457 | 1462 | # We are off again... |
|
1458 | 1463 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
|
1459 | 1464 | |
|
1460 | 1465 | def excepthook(self, type, value, tb): |
|
1461 | 1466 | """One more defense for GUI apps that call sys.excepthook. |
|
1462 | 1467 | |
|
1463 | 1468 | GUI frameworks like wxPython trap exceptions and call |
|
1464 | 1469 | sys.excepthook themselves. I guess this is a feature that |
|
1465 | 1470 | enables them to keep running after exceptions that would |
|
1466 | 1471 | otherwise kill their mainloop. This is a bother for IPython |
|
1467 | 1472 | which excepts to catch all of the program exceptions with a try: |
|
1468 | 1473 | except: statement. |
|
1469 | 1474 | |
|
1470 | 1475 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if |
|
1471 | 1476 | any app directly invokes sys.excepthook, it will look to the user like |
|
1472 | 1477 | IPython crashed. In order to work around this, we can disable the |
|
1473 | 1478 | CrashHandler and replace it with this excepthook instead, which prints a |
|
1474 | 1479 | regular traceback using our InteractiveTB. In this fashion, apps which |
|
1475 | 1480 | call sys.excepthook will generate a regular-looking exception from |
|
1476 | 1481 | IPython, and the CrashHandler will only be triggered by real IPython |
|
1477 | 1482 | crashes. |
|
1478 | 1483 | |
|
1479 | 1484 | This hook should be used sparingly, only in places which are not likely |
|
1480 | 1485 | to be true IPython errors. |
|
1481 | 1486 | """ |
|
1482 | 1487 | |
|
1483 | 1488 | self.InteractiveTB(type, value, tb, tb_offset=0) |
|
1484 | 1489 | if self.InteractiveTB.call_pdb and self.has_readline: |
|
1485 | 1490 | self.readline.set_completer(self.Completer.complete) |
|
1486 | 1491 | |
|
1487 | 1492 | def call_alias(self,alias,rest=''): |
|
1488 | 1493 | """Call an alias given its name and the rest of the line. |
|
1489 | 1494 | |
|
1490 | 1495 | This function MUST be given a proper alias, because it doesn't make |
|
1491 | 1496 | any checks when looking up into the alias table. The caller is |
|
1492 | 1497 | responsible for invoking it only with a valid alias.""" |
|
1493 | 1498 | |
|
1494 | 1499 | #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg |
|
1495 | 1500 | nargs,cmd = self.alias_table[alias] |
|
1496 | 1501 | # Expand the %l special to be the user's input line |
|
1497 | 1502 | if cmd.find('%l') >= 0: |
|
1498 | 1503 | cmd = cmd.replace('%l',rest) |
|
1499 | 1504 | rest = '' |
|
1500 | 1505 | if nargs==0: |
|
1501 | 1506 | # Simple, argument-less aliases |
|
1502 | 1507 | cmd = '%s %s' % (cmd,rest) |
|
1503 | 1508 | else: |
|
1504 | 1509 | # Handle aliases with positional arguments |
|
1505 | 1510 | args = rest.split(None,nargs) |
|
1506 | 1511 | if len(args)< nargs: |
|
1507 | 1512 | error('Alias <%s> requires %s arguments, %s given.' % |
|
1508 | 1513 | (alias,nargs,len(args))) |
|
1509 | 1514 | return |
|
1510 | 1515 | cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:])) |
|
1511 | 1516 | # Now call the macro, evaluating in the user's namespace |
|
1512 | 1517 | try: |
|
1513 | 1518 | self.system(cmd) |
|
1514 | 1519 | except: |
|
1515 | 1520 | self.showtraceback() |
|
1516 | 1521 | |
|
1517 | 1522 | def runlines(self,lines): |
|
1518 | 1523 | """Run a string of one or more lines of source. |
|
1519 | 1524 | |
|
1520 | 1525 | This method is capable of running a string containing multiple source |
|
1521 | 1526 | lines, as if they had been entered at the IPython prompt. Since it |
|
1522 | 1527 | exposes IPython's processing machinery, the given strings can contain |
|
1523 | 1528 | magic calls (%magic), special shell access (!cmd), etc.""" |
|
1524 | 1529 | |
|
1525 | 1530 | # We must start with a clean buffer, in case this is run from an |
|
1526 | 1531 | # interactive IPython session (via a magic, for example). |
|
1527 | 1532 | self.resetbuffer() |
|
1528 | 1533 | lines = lines.split('\n') |
|
1529 | 1534 | more = 0 |
|
1530 | 1535 | for line in lines: |
|
1531 | 1536 | # skip blank lines so we don't mess up the prompt counter, but do |
|
1532 | 1537 | # NOT skip even a blank line if we are in a code block (more is |
|
1533 | 1538 | # true) |
|
1534 | 1539 | if line or more: |
|
1535 | 1540 | more = self.push((self.prefilter(line,more))) |
|
1536 | 1541 | # IPython's runsource returns None if there was an error |
|
1537 | 1542 | # compiling the code. This allows us to stop processing right |
|
1538 | 1543 | # away, so the user gets the error message at the right place. |
|
1539 | 1544 | if more is None: |
|
1540 | 1545 | break |
|
1541 | 1546 | # final newline in case the input didn't have it, so that the code |
|
1542 | 1547 | # actually does get executed |
|
1543 | 1548 | if more: |
|
1544 | 1549 | self.push('\n') |
|
1545 | 1550 | |
|
1546 | 1551 | def runsource(self, source, filename="<input>", symbol="single"): |
|
1547 | 1552 | """Compile and run some source in the interpreter. |
|
1548 | 1553 | |
|
1549 | 1554 | Arguments are as for compile_command(). |
|
1550 | 1555 | |
|
1551 | 1556 | One several things can happen: |
|
1552 | 1557 | |
|
1553 | 1558 | 1) The input is incorrect; compile_command() raised an |
|
1554 | 1559 | exception (SyntaxError or OverflowError). A syntax traceback |
|
1555 | 1560 | will be printed by calling the showsyntaxerror() method. |
|
1556 | 1561 | |
|
1557 | 1562 | 2) The input is incomplete, and more input is required; |
|
1558 | 1563 | compile_command() returned None. Nothing happens. |
|
1559 | 1564 | |
|
1560 | 1565 | 3) The input is complete; compile_command() returned a code |
|
1561 | 1566 | object. The code is executed by calling self.runcode() (which |
|
1562 | 1567 | also handles run-time exceptions, except for SystemExit). |
|
1563 | 1568 | |
|
1564 | 1569 | The return value is: |
|
1565 | 1570 | |
|
1566 | 1571 | - True in case 2 |
|
1567 | 1572 | |
|
1568 | 1573 | - False in the other cases, unless an exception is raised, where |
|
1569 | 1574 | None is returned instead. This can be used by external callers to |
|
1570 | 1575 | know whether to continue feeding input or not. |
|
1571 | 1576 | |
|
1572 | 1577 | The return value can be used to decide whether to use sys.ps1 or |
|
1573 | 1578 | sys.ps2 to prompt the next line.""" |
|
1574 | 1579 | |
|
1575 | 1580 | try: |
|
1576 | 1581 | code = self.compile(source, filename, symbol) |
|
1577 | 1582 | except (OverflowError, SyntaxError, ValueError): |
|
1578 | 1583 | # Case 1 |
|
1579 | 1584 | self.showsyntaxerror(filename) |
|
1580 | 1585 | return None |
|
1581 | 1586 | |
|
1582 | 1587 | if code is None: |
|
1583 | 1588 | # Case 2 |
|
1584 | 1589 | return True |
|
1585 | 1590 | |
|
1586 | 1591 | # Case 3 |
|
1587 | 1592 | # We store the code object so that threaded shells and |
|
1588 | 1593 | # custom exception handlers can access all this info if needed. |
|
1589 | 1594 | # The source corresponding to this can be obtained from the |
|
1590 | 1595 | # buffer attribute as '\n'.join(self.buffer). |
|
1591 | 1596 | self.code_to_run = code |
|
1592 | 1597 | # now actually execute the code object |
|
1593 | 1598 | if self.runcode(code) == 0: |
|
1594 | 1599 | return False |
|
1595 | 1600 | else: |
|
1596 | 1601 | return None |
|
1597 | 1602 | |
|
1598 | 1603 | def runcode(self,code_obj): |
|
1599 | 1604 | """Execute a code object. |
|
1600 | 1605 | |
|
1601 | 1606 | When an exception occurs, self.showtraceback() is called to display a |
|
1602 | 1607 | traceback. |
|
1603 | 1608 | |
|
1604 | 1609 | Return value: a flag indicating whether the code to be run completed |
|
1605 | 1610 | successfully: |
|
1606 | 1611 | |
|
1607 | 1612 | - 0: successful execution. |
|
1608 | 1613 | - 1: an error occurred. |
|
1609 | 1614 | """ |
|
1610 | 1615 | |
|
1611 | 1616 | # Set our own excepthook in case the user code tries to call it |
|
1612 | 1617 | # directly, so that the IPython crash handler doesn't get triggered |
|
1613 | 1618 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
1614 | 1619 | outflag = 1 # happens in more places, so it's easier as default |
|
1615 | 1620 | try: |
|
1616 | 1621 | try: |
|
1617 | 1622 | exec code_obj in self.locals |
|
1618 | 1623 | finally: |
|
1619 | 1624 | # Reset our crash handler in place |
|
1620 | 1625 | sys.excepthook = old_excepthook |
|
1621 | 1626 | except SystemExit: |
|
1622 | 1627 | self.resetbuffer() |
|
1623 | 1628 | self.showtraceback() |
|
1624 | 1629 | warn( __builtin__.exit,level=1) |
|
1625 | 1630 | except self.custom_exceptions: |
|
1626 | 1631 | etype,value,tb = sys.exc_info() |
|
1627 | 1632 | self.CustomTB(etype,value,tb) |
|
1628 | 1633 | except: |
|
1629 | 1634 | self.showtraceback() |
|
1630 | 1635 | else: |
|
1631 | 1636 | outflag = 0 |
|
1632 | 1637 | if code.softspace(sys.stdout, 0): |
|
1633 | 1638 | |
|
1634 | 1639 | # Flush out code object which has been run (and source) |
|
1635 | 1640 | self.code_to_run = None |
|
1636 | 1641 | return outflag |
|
1637 | 1642 | |
|
1638 | 1643 | def raw_input(self, prompt=""): |
|
1639 | 1644 | """Write a prompt and read a line. |
|
1640 | 1645 | |
|
1641 | 1646 | The returned line does not include the trailing newline. |
|
1642 | 1647 | When the user enters the EOF key sequence, EOFError is raised. |
|
1643 | 1648 | |
|
1644 | 1649 | The base implementation uses the built-in function |
|
1645 | 1650 | raw_input(); a subclass may replace this with a different |
|
1646 | 1651 | implementation. |
|
1647 | 1652 | """ |
|
1648 | 1653 | return self.prefilter(raw_input_original(prompt), |
|
1649 | 1654 | prompt==self.outputcache.prompt2) |
|
1650 | 1655 | |
|
1651 | 1656 | def split_user_input(self,line): |
|
1652 | 1657 | """Split user input into pre-char, function part and rest.""" |
|
1653 | 1658 | |
|
1654 | 1659 | lsplit = self.line_split.match(line) |
|
1655 | 1660 | if lsplit is None: # no regexp match returns None |
|
1656 | 1661 | try: |
|
1657 | 1662 | iFun,theRest = line.split(None,1) |
|
1658 | 1663 | except ValueError: |
|
1659 | 1664 | iFun,theRest = line,'' |
|
1660 | 1665 | pre = re.match('^(\s*)(.*)',line).groups()[0] |
|
1661 | 1666 | else: |
|
1662 | 1667 | pre,iFun,theRest = lsplit.groups() |
|
1663 | 1668 | |
|
1664 | 1669 | #print 'line:<%s>' % line # dbg |
|
1665 | 1670 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg |
|
1666 | 1671 | return pre,iFun.strip(),theRest |
|
1667 | 1672 | |
|
1668 | 1673 | def _prefilter(self, line, continue_prompt): |
|
1669 | 1674 | """Calls different preprocessors, depending on the form of line.""" |
|
1670 | 1675 | |
|
1671 | 1676 | # All handlers *must* return a value, even if it's blank (''). |
|
1672 | 1677 | |
|
1673 | 1678 | # Lines are NOT logged here. Handlers should process the line as |
|
1674 | 1679 | # needed, update the cache AND log it (so that the input cache array |
|
1675 | 1680 | # stays synced). |
|
1676 | 1681 | |
|
1677 | 1682 | # This function is _very_ delicate, and since it's also the one which |
|
1678 | 1683 | # determines IPython's response to user input, it must be as efficient |
|
1679 | 1684 | # as possible. For this reason it has _many_ returns in it, trying |
|
1680 | 1685 | # always to exit as quickly as it can figure out what it needs to do. |
|
1681 | 1686 | |
|
1682 | 1687 | # This function is the main responsible for maintaining IPython's |
|
1683 | 1688 | # behavior respectful of Python's semantics. So be _very_ careful if |
|
1684 | 1689 | # making changes to anything here. |
|
1685 | 1690 | |
|
1686 | 1691 | #..................................................................... |
|
1687 | 1692 | # Code begins |
|
1688 | 1693 | |
|
1689 | 1694 | #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg |
|
1690 | 1695 | |
|
1691 | 1696 | # save the line away in case we crash, so the post-mortem handler can |
|
1692 | 1697 | # record it |
|
1693 | 1698 | self._last_input_line = line |
|
1694 | 1699 | |
|
1695 | 1700 | #print '***line: <%s>' % line # dbg |
|
1696 | 1701 | |
|
1697 | 1702 | # the input history needs to track even empty lines |
|
1698 | 1703 | if not line.strip(): |
|
1699 | 1704 | if not continue_prompt: |
|
1700 | 1705 | self.outputcache.prompt_count -= 1 |
|
1701 | 1706 | return self.handle_normal('',continue_prompt) |
|
1702 | 1707 | |
|
1703 | 1708 | # print '***cont',continue_prompt # dbg |
|
1704 | 1709 | # special handlers are only allowed for single line statements |
|
1705 | 1710 | if continue_prompt and not self.rc.multi_line_specials: |
|
1706 | 1711 | return self.handle_normal(line,continue_prompt) |
|
1707 | 1712 | |
|
1708 | 1713 | # For the rest, we need the structure of the input |
|
1709 | 1714 | pre,iFun,theRest = self.split_user_input(line) |
|
1710 | 1715 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1711 | 1716 | |
|
1712 | 1717 | # First check for explicit escapes in the last/first character |
|
1713 | 1718 | handler = None |
|
1714 | 1719 | if line[-1] == self.ESC_HELP: |
|
1715 | 1720 | handler = self.esc_handlers.get(line[-1]) # the ? can be at the end |
|
1716 | 1721 | if handler is None: |
|
1717 | 1722 | # look at the first character of iFun, NOT of line, so we skip |
|
1718 | 1723 | # leading whitespace in multiline input |
|
1719 | 1724 | handler = self.esc_handlers.get(iFun[0:1]) |
|
1720 | 1725 | if handler is not None: |
|
1721 | 1726 | return handler(line,continue_prompt,pre,iFun,theRest) |
|
1722 | 1727 | # Emacs ipython-mode tags certain input lines |
|
1723 | 1728 | if line.endswith('# PYTHON-MODE'): |
|
1724 | 1729 | return self.handle_emacs(line,continue_prompt) |
|
1725 | 1730 | |
|
1726 | 1731 | # Next, check if we can automatically execute this thing |
|
1727 | 1732 | |
|
1728 | 1733 | # Allow ! in multi-line statements if multi_line_specials is on: |
|
1729 | 1734 | if continue_prompt and self.rc.multi_line_specials and \ |
|
1730 | 1735 | iFun.startswith(self.ESC_SHELL): |
|
1731 | 1736 | return self.handle_shell_escape(line,continue_prompt, |
|
1732 | 1737 | pre=pre,iFun=iFun, |
|
1733 | 1738 | theRest=theRest) |
|
1734 | 1739 | |
|
1735 | 1740 | # Let's try to find if the input line is a magic fn |
|
1736 | 1741 | oinfo = None |
|
1737 | 1742 | if hasattr(self,'magic_'+iFun): |
|
1738 | 1743 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1739 | 1744 | if oinfo['ismagic']: |
|
1740 | 1745 | # Be careful not to call magics when a variable assignment is |
|
1741 | 1746 | # being made (ls='hi', for example) |
|
1742 | 1747 | if self.rc.automagic and \ |
|
1743 | 1748 | (len(theRest)==0 or theRest[0] not in '!=()<>,') and \ |
|
1744 | 1749 | (self.rc.multi_line_specials or not continue_prompt): |
|
1745 | 1750 | return self.handle_magic(line,continue_prompt, |
|
1746 | 1751 | pre,iFun,theRest) |
|
1747 | 1752 | else: |
|
1748 | 1753 | return self.handle_normal(line,continue_prompt) |
|
1749 | 1754 | |
|
1750 | 1755 | # If the rest of the line begins with an (in)equality, assginment or |
|
1751 | 1756 | # function call, we should not call _ofind but simply execute it. |
|
1752 | 1757 | # This avoids spurious geattr() accesses on objects upon assignment. |
|
1753 | 1758 | # |
|
1754 | 1759 | # It also allows users to assign to either alias or magic names true |
|
1755 | 1760 | # python variables (the magic/alias systems always take second seat to |
|
1756 | 1761 | # true python code). |
|
1757 | 1762 | if theRest and theRest[0] in '!=()': |
|
1758 | 1763 | return self.handle_normal(line,continue_prompt) |
|
1759 | 1764 | |
|
1760 | 1765 | if oinfo is None: |
|
1761 | 1766 | oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic |
|
1762 | 1767 | |
|
1763 | 1768 | if not oinfo['found']: |
|
1764 | 1769 | return self.handle_normal(line,continue_prompt) |
|
1765 | 1770 | else: |
|
1766 | 1771 | #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg |
|
1767 | 1772 | if oinfo['isalias']: |
|
1768 | 1773 | return self.handle_alias(line,continue_prompt, |
|
1769 | 1774 | pre,iFun,theRest) |
|
1770 | 1775 | |
|
1771 | 1776 | if self.rc.autocall and \ |
|
1772 | 1777 | not self.re_exclude_auto.match(theRest) and \ |
|
1773 | 1778 | self.re_fun_name.match(iFun) and \ |
|
1774 | 1779 | callable(oinfo['obj']) : |
|
1775 | 1780 | #print 'going auto' # dbg |
|
1776 | 1781 | return self.handle_auto(line,continue_prompt,pre,iFun,theRest) |
|
1777 | 1782 | else: |
|
1778 | 1783 | #print 'was callable?', callable(oinfo['obj']) # dbg |
|
1779 | 1784 | return self.handle_normal(line,continue_prompt) |
|
1780 | 1785 | |
|
1781 | 1786 | # If we get here, we have a normal Python line. Log and return. |
|
1782 | 1787 | return self.handle_normal(line,continue_prompt) |
|
1783 | 1788 | |
|
1784 | 1789 | def _prefilter_dumb(self, line, continue_prompt): |
|
1785 | 1790 | """simple prefilter function, for debugging""" |
|
1786 | 1791 | return self.handle_normal(line,continue_prompt) |
|
1787 | 1792 | |
|
1788 | 1793 | # Set the default prefilter() function (this can be user-overridden) |
|
1789 | 1794 | prefilter = _prefilter |
|
1790 | 1795 | |
|
1791 | 1796 | def handle_normal(self,line,continue_prompt=None, |
|
1792 | 1797 | pre=None,iFun=None,theRest=None): |
|
1793 | 1798 | """Handle normal input lines. Use as a template for handlers.""" |
|
1794 | 1799 | |
|
1795 | 1800 | self.log(line,continue_prompt) |
|
1796 | 1801 | self.update_cache(line) |
|
1797 | 1802 | return line |
|
1798 | 1803 | |
|
1799 | 1804 | def handle_alias(self,line,continue_prompt=None, |
|
1800 | 1805 | pre=None,iFun=None,theRest=None): |
|
1801 | 1806 | """Handle alias input lines. """ |
|
1802 | 1807 | |
|
1803 | 1808 | theRest = esc_quotes(theRest) |
|
1804 | 1809 | line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest) |
|
1805 | 1810 | self.log(line_out,continue_prompt) |
|
1806 | 1811 | self.update_cache(line_out) |
|
1807 | 1812 | return line_out |
|
1808 | 1813 | |
|
1809 | 1814 | def handle_shell_escape(self, line, continue_prompt=None, |
|
1810 | 1815 | pre=None,iFun=None,theRest=None): |
|
1811 | 1816 | """Execute the line in a shell, empty return value""" |
|
1812 | 1817 | |
|
1813 | 1818 | #print 'line in :', `line` # dbg |
|
1814 | 1819 | # Example of a special handler. Others follow a similar pattern. |
|
1815 | 1820 | if continue_prompt: # multi-line statements |
|
1816 | 1821 | if iFun.startswith('!!'): |
|
1817 | 1822 | print 'SyntaxError: !! is not allowed in multiline statements' |
|
1818 | 1823 | return pre |
|
1819 | 1824 | else: |
|
1820 | 1825 | cmd = ("%s %s" % (iFun[1:],theRest)).replace('"','\\"') |
|
1821 | 1826 | line_out = '%s%s.system("%s")' % (pre,self.name,cmd) |
|
1822 | 1827 | #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')' |
|
1823 | 1828 | else: # single-line input |
|
1824 | 1829 | if line.startswith('!!'): |
|
1825 | 1830 | # rewrite iFun/theRest to properly hold the call to %sx and |
|
1826 | 1831 | # the actual command to be executed, so handle_magic can work |
|
1827 | 1832 | # correctly |
|
1828 | 1833 | theRest = '%s %s' % (iFun[2:],theRest) |
|
1829 | 1834 | iFun = 'sx' |
|
1830 | 1835 | return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]), |
|
1831 | 1836 | continue_prompt,pre,iFun,theRest) |
|
1832 | 1837 | else: |
|
1833 | 1838 | cmd = esc_quotes(line[1:]) |
|
1834 | 1839 | line_out = '%s.system("%s")' % (self.name,cmd) |
|
1835 | 1840 | #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')' |
|
1836 | 1841 | # update cache/log and return |
|
1837 | 1842 | self.log(line_out,continue_prompt) |
|
1838 | 1843 | self.update_cache(line_out) # readline cache gets normal line |
|
1839 | 1844 | #print 'line out r:', `line_out` # dbg |
|
1840 | 1845 | #print 'line out s:', line_out # dbg |
|
1841 | 1846 | return line_out |
|
1842 | 1847 | |
|
1843 | 1848 | def handle_magic(self, line, continue_prompt=None, |
|
1844 | 1849 | pre=None,iFun=None,theRest=None): |
|
1845 | 1850 | """Execute magic functions. |
|
1846 | 1851 | |
|
1847 | 1852 | Also log them with a prepended # so the log is clean Python.""" |
|
1848 | 1853 | |
|
1849 | 1854 | cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest))) |
|
1850 | 1855 | self.log(cmd,continue_prompt) |
|
1851 | 1856 | self.update_cache(line) |
|
1852 | 1857 | #print 'in handle_magic, cmd=<%s>' % cmd # dbg |
|
1853 | 1858 | return cmd |
|
1854 | 1859 | |
|
1855 | 1860 | def handle_auto(self, line, continue_prompt=None, |
|
1856 | 1861 | pre=None,iFun=None,theRest=None): |
|
1857 | 1862 | """Hande lines which can be auto-executed, quoting if requested.""" |
|
1858 | 1863 | |
|
1859 | 1864 | #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg |
|
1860 | 1865 | |
|
1861 | 1866 | # This should only be active for single-line input! |
|
1862 | 1867 | if continue_prompt: |
|
1863 | 1868 | return line |
|
1864 | 1869 | |
|
1865 | 1870 | if pre == self.ESC_QUOTE: |
|
1866 | 1871 | # Auto-quote splitting on whitespace |
|
1867 | 1872 | newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) ) |
|
1868 | 1873 | elif pre == self.ESC_QUOTE2: |
|
1869 | 1874 | # Auto-quote whole string |
|
1870 | 1875 | newcmd = '%s("%s")' % (iFun,theRest) |
|
1871 | 1876 | else: |
|
1872 | 1877 | # Auto-paren |
|
1873 | 1878 | if theRest[0:1] in ('=','['): |
|
1874 | 1879 | # Don't autocall in these cases. They can be either |
|
1875 | 1880 | # rebindings of an existing callable's name, or item access |
|
1876 | 1881 | # for an object which is BOTH callable and implements |
|
1877 | 1882 | # __getitem__. |
|
1878 | 1883 | return '%s %s' % (iFun,theRest) |
|
1879 | 1884 | if theRest.endswith(';'): |
|
1880 | 1885 | newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1]) |
|
1881 | 1886 | else: |
|
1882 | 1887 | newcmd = '%s(%s)' % (iFun.rstrip(),theRest) |
|
1883 | 1888 | |
|
1884 | 1889 | print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd |
|
1885 | 1890 | # log what is now valid Python, not the actual user input (without the |
|
1886 | 1891 | # final newline) |
|
1887 | 1892 | self.log(newcmd,continue_prompt) |
|
1888 | 1893 | return newcmd |
|
1889 | 1894 | |
|
1890 | 1895 | def handle_help(self, line, continue_prompt=None, |
|
1891 | 1896 | pre=None,iFun=None,theRest=None): |
|
1892 | 1897 | """Try to get some help for the object. |
|
1893 | 1898 | |
|
1894 | 1899 | obj? or ?obj -> basic information. |
|
1895 | 1900 | obj?? or ??obj -> more details. |
|
1896 | 1901 | """ |
|
1897 | 1902 | |
|
1898 | 1903 | # We need to make sure that we don't process lines which would be |
|
1899 | 1904 | # otherwise valid python, such as "x=1 # what?" |
|
1900 | 1905 | try: |
|
1901 | 1906 | code.compile_command(line) |
|
1902 | 1907 | except SyntaxError: |
|
1903 | 1908 | # We should only handle as help stuff which is NOT valid syntax |
|
1904 | 1909 | if line[0]==self.ESC_HELP: |
|
1905 | 1910 | line = line[1:] |
|
1906 | 1911 | elif line[-1]==self.ESC_HELP: |
|
1907 | 1912 | line = line[:-1] |
|
1908 | 1913 | self.log('#?'+line) |
|
1909 | 1914 | self.update_cache(line) |
|
1910 | 1915 | if line: |
|
1911 | 1916 | self.magic_pinfo(line) |
|
1912 | 1917 | else: |
|
1913 | 1918 | page(self.usage,screen_lines=self.rc.screen_length) |
|
1914 | 1919 | return '' # Empty string is needed here! |
|
1915 | 1920 | except: |
|
1916 | 1921 | # Pass any other exceptions through to the normal handler |
|
1917 | 1922 | return self.handle_normal(line,continue_prompt) |
|
1918 | 1923 | else: |
|
1919 | 1924 | # If the code compiles ok, we should handle it normally |
|
1920 | 1925 | return self.handle_normal(line,continue_prompt) |
|
1921 | 1926 | |
|
1922 | 1927 | def handle_emacs(self,line,continue_prompt=None, |
|
1923 | 1928 | pre=None,iFun=None,theRest=None): |
|
1924 | 1929 | """Handle input lines marked by python-mode.""" |
|
1925 | 1930 | |
|
1926 | 1931 | # Currently, nothing is done. Later more functionality can be added |
|
1927 | 1932 | # here if needed. |
|
1928 | 1933 | |
|
1929 | 1934 | # The input cache shouldn't be updated |
|
1930 | 1935 | |
|
1931 | 1936 | return line |
|
1932 | 1937 | |
|
1933 | 1938 | def write(self,data): |
|
1934 | 1939 | """Write a string to the default output""" |
|
1935 | 1940 | Term.cout.write(data) |
|
1936 | 1941 | |
|
1937 | 1942 | def write_err(self,data): |
|
1938 | 1943 | """Write a string to the default error output""" |
|
1939 | 1944 | Term.cerr.write(data) |
|
1940 | 1945 | |
|
1941 | 1946 | def safe_execfile(self,fname,*where,**kw): |
|
1942 | 1947 | fname = os.path.expanduser(fname) |
|
1943 | 1948 | |
|
1944 | 1949 | # find things also in current directory |
|
1945 | 1950 | dname = os.path.dirname(fname) |
|
1946 | 1951 | if not sys.path.count(dname): |
|
1947 | 1952 | sys.path.append(dname) |
|
1948 | 1953 | |
|
1949 | 1954 | try: |
|
1950 | 1955 | xfile = open(fname) |
|
1951 | 1956 | except: |
|
1952 | 1957 | print >> Term.cerr, \ |
|
1953 | 1958 | 'Could not open file <%s> for safe execution.' % fname |
|
1954 | 1959 | return None |
|
1955 | 1960 | |
|
1956 | 1961 | kw.setdefault('islog',0) |
|
1957 | 1962 | kw.setdefault('quiet',1) |
|
1958 | 1963 | kw.setdefault('exit_ignore',0) |
|
1959 | 1964 | first = xfile.readline() |
|
1960 | 1965 | _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip() |
|
1961 | 1966 | xfile.close() |
|
1962 | 1967 | # line by line execution |
|
1963 | 1968 | if first.startswith(_LOGHEAD) or kw['islog']: |
|
1964 | 1969 | print 'Loading log file <%s> one line at a time...' % fname |
|
1965 | 1970 | if kw['quiet']: |
|
1966 | 1971 | stdout_save = sys.stdout |
|
1967 | 1972 | sys.stdout = StringIO.StringIO() |
|
1968 | 1973 | try: |
|
1969 | 1974 | globs,locs = where[0:2] |
|
1970 | 1975 | except: |
|
1971 | 1976 | try: |
|
1972 | 1977 | globs = locs = where[0] |
|
1973 | 1978 | except: |
|
1974 | 1979 | globs = locs = globals() |
|
1975 | 1980 | badblocks = [] |
|
1976 | 1981 | |
|
1977 | 1982 | # we also need to identify indented blocks of code when replaying |
|
1978 | 1983 | # logs and put them together before passing them to an exec |
|
1979 | 1984 | # statement. This takes a bit of regexp and look-ahead work in the |
|
1980 | 1985 | # file. It's easiest if we swallow the whole thing in memory |
|
1981 | 1986 | # first, and manually walk through the lines list moving the |
|
1982 | 1987 | # counter ourselves. |
|
1983 | 1988 | indent_re = re.compile('\s+\S') |
|
1984 | 1989 | xfile = open(fname) |
|
1985 | 1990 | filelines = xfile.readlines() |
|
1986 | 1991 | xfile.close() |
|
1987 | 1992 | nlines = len(filelines) |
|
1988 | 1993 | lnum = 0 |
|
1989 | 1994 | while lnum < nlines: |
|
1990 | 1995 | line = filelines[lnum] |
|
1991 | 1996 | lnum += 1 |
|
1992 | 1997 | # don't re-insert logger status info into cache |
|
1993 | 1998 | if line.startswith('#log#'): |
|
1994 | 1999 | continue |
|
1995 | 2000 | elif line.startswith('#%s'% self.ESC_MAGIC): |
|
1996 | 2001 | self.update_cache(line[1:]) |
|
1997 | 2002 | line = magic2python(line) |
|
1998 | 2003 | elif line.startswith('#!'): |
|
1999 | 2004 | self.update_cache(line[1:]) |
|
2000 | 2005 | else: |
|
2001 | 2006 | # build a block of code (maybe a single line) for execution |
|
2002 | 2007 | block = line |
|
2003 | 2008 | try: |
|
2004 | 2009 | next = filelines[lnum] # lnum has already incremented |
|
2005 | 2010 | except: |
|
2006 | 2011 | next = None |
|
2007 | 2012 | while next and indent_re.match(next): |
|
2008 | 2013 | block += next |
|
2009 | 2014 | lnum += 1 |
|
2010 | 2015 | try: |
|
2011 | 2016 | next = filelines[lnum] |
|
2012 | 2017 | except: |
|
2013 | 2018 | next = None |
|
2014 | 2019 | # now execute the block of one or more lines |
|
2015 | 2020 | try: |
|
2016 | 2021 | exec block in globs,locs |
|
2017 | 2022 | self.update_cache(block.rstrip()) |
|
2018 | 2023 | except SystemExit: |
|
2019 | 2024 | pass |
|
2020 | 2025 | except: |
|
2021 | 2026 | badblocks.append(block.rstrip()) |
|
2022 | 2027 | if kw['quiet']: # restore stdout |
|
2023 | 2028 | sys.stdout.close() |
|
2024 | 2029 | sys.stdout = stdout_save |
|
2025 | 2030 | print 'Finished replaying log file <%s>' % fname |
|
2026 | 2031 | if badblocks: |
|
2027 | 2032 | print >> sys.stderr, \ |
|
2028 | 2033 | '\nThe following lines/blocks in file <%s> reported errors:' \ |
|
2029 | 2034 | % fname |
|
2030 | 2035 | for badline in badblocks: |
|
2031 | 2036 | print >> sys.stderr, badline |
|
2032 | 2037 | else: # regular file execution |
|
2033 | 2038 | try: |
|
2034 | 2039 | execfile(fname,*where) |
|
2035 | 2040 | except SyntaxError: |
|
2036 | 2041 | etype, evalue = sys.exc_info()[0:2] |
|
2037 | 2042 | self.SyntaxTB(etype,evalue,[]) |
|
2038 | 2043 | warn('Failure executing file: <%s>' % fname) |
|
2039 | 2044 | except SystemExit,status: |
|
2040 | 2045 | if not kw['exit_ignore']: |
|
2041 | 2046 | self.InteractiveTB() |
|
2042 | 2047 | warn('Failure executing file: <%s>' % fname) |
|
2043 | 2048 | except: |
|
2044 | 2049 | self.InteractiveTB() |
|
2045 | 2050 | warn('Failure executing file: <%s>' % fname) |
|
2046 | 2051 | |
|
2047 | 2052 | #************************* end of file <iplib.py> ***************************** |
@@ -1,4399 +1,4406 b'' | |||
|
1 | 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu> | |
|
2 | ||
|
3 | * IPython/demo.py: finish demo module, fully documented now. | |
|
4 | ||
|
5 | * IPython/genutils.py (file_read): simple little utility to read a | |
|
6 | file and ensure it's closed afterwards. | |
|
7 | ||
|
1 | 8 | 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 9 | |
|
3 | 10 | * IPython/demo.py (Demo.__init__): added support for individually |
|
4 | 11 | tagging blocks for automatic execution. |
|
5 | 12 | |
|
6 | 13 | * IPython/Magic.py (magic_pycat): new %pycat magic for showing |
|
7 | 14 | syntax-highlighted python sources, requested by John. |
|
8 | 15 | |
|
9 | 16 | 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu> |
|
10 | 17 | |
|
11 | 18 | * IPython/demo.py (Demo.again): fix bug where again() blocks after |
|
12 | 19 | finishing. |
|
13 | 20 | |
|
14 | 21 | * IPython/genutils.py (shlex_split): moved from Magic to here, |
|
15 | 22 | where all 2.2 compatibility stuff lives. I needed it for demo.py. |
|
16 | 23 | |
|
17 | 24 | * IPython/demo.py (Demo.__init__): added support for silent |
|
18 | 25 | blocks, improved marks as regexps, docstrings written. |
|
19 | 26 | (Demo.__init__): better docstring, added support for sys.argv. |
|
20 | 27 | |
|
21 | 28 | * IPython/genutils.py (marquee): little utility used by the demo |
|
22 | 29 | code, handy in general. |
|
23 | 30 | |
|
24 | 31 | * IPython/demo.py (Demo.__init__): new class for interactive |
|
25 | 32 | demos. Not documented yet, I just wrote it in a hurry for |
|
26 | 33 | scipy'05. Will docstring later. |
|
27 | 34 | |
|
28 | 35 | 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu> |
|
29 | 36 | |
|
30 | 37 | * IPython/Shell.py (sigint_handler): Drastic simplification which |
|
31 | 38 | also seems to make Ctrl-C work correctly across threads! This is |
|
32 | 39 | so simple, that I can't beleive I'd missed it before. Needs more |
|
33 | 40 | testing, though. |
|
34 | 41 | (KBINT): Never mind, revert changes. I'm sure I'd tried something |
|
35 | 42 | like this before... |
|
36 | 43 | |
|
37 | 44 | * IPython/genutils.py (get_home_dir): add protection against |
|
38 | 45 | non-dirs in win32 registry. |
|
39 | 46 | |
|
40 | 47 | * IPython/iplib.py (InteractiveShell.alias_table_validate): fix |
|
41 | 48 | bug where dict was mutated while iterating (pysh crash). |
|
42 | 49 | |
|
43 | 50 | 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu> |
|
44 | 51 | |
|
45 | 52 | * IPython/iplib.py (handle_auto): Fix inconsistency arising from |
|
46 | 53 | spurious newlines added by this routine. After a report by |
|
47 | 54 | F. Mantegazza. |
|
48 | 55 | |
|
49 | 56 | 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu> |
|
50 | 57 | |
|
51 | 58 | * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0") |
|
52 | 59 | calls. These were a leftover from the GTK 1.x days, and can cause |
|
53 | 60 | problems in certain cases (after a report by John Hunter). |
|
54 | 61 | |
|
55 | 62 | * IPython/iplib.py (InteractiveShell.__init__): Trap exception if |
|
56 | 63 | os.getcwd() fails at init time. Thanks to patch from David Remahl |
|
57 | 64 | <chmod007 AT mac.com>. |
|
58 | 65 | (InteractiveShell.__init__): prevent certain special magics from |
|
59 | 66 | being shadowed by aliases. Closes |
|
60 | 67 | http://www.scipy.net/roundup/ipython/issue41. |
|
61 | 68 | |
|
62 | 69 | 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu> |
|
63 | 70 | |
|
64 | 71 | * IPython/iplib.py (InteractiveShell.complete): Added new |
|
65 | 72 | top-level completion method to expose the completion mechanism |
|
66 | 73 | beyond readline-based environments. |
|
67 | 74 | |
|
68 | 75 | 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu> |
|
69 | 76 | |
|
70 | 77 | * tools/ipsvnc (svnversion): fix svnversion capture. |
|
71 | 78 | |
|
72 | 79 | * IPython/iplib.py (InteractiveShell.__init__): Add has_readline |
|
73 | 80 | attribute to self, which was missing. Before, it was set by a |
|
74 | 81 | routine which in certain cases wasn't being called, so the |
|
75 | 82 | instance could end up missing the attribute. This caused a crash. |
|
76 | 83 | Closes http://www.scipy.net/roundup/ipython/issue40. |
|
77 | 84 | |
|
78 | 85 | 2005-08-16 Fernando Perez <fperez@colorado.edu> |
|
79 | 86 | |
|
80 | 87 | * IPython/ultraTB.py (VerboseTB.text): don't crash if object |
|
81 | 88 | contains non-string attribute. Closes |
|
82 | 89 | http://www.scipy.net/roundup/ipython/issue38. |
|
83 | 90 | |
|
84 | 91 | 2005-08-14 Fernando Perez <fperez@colorado.edu> |
|
85 | 92 | |
|
86 | 93 | * tools/ipsvnc: Minor improvements, to add changeset info. |
|
87 | 94 | |
|
88 | 95 | 2005-08-12 Fernando Perez <fperez@colorado.edu> |
|
89 | 96 | |
|
90 | 97 | * IPython/iplib.py (runsource): remove self.code_to_run_src |
|
91 | 98 | attribute. I realized this is nothing more than |
|
92 | 99 | '\n'.join(self.buffer), and having the same data in two different |
|
93 | 100 | places is just asking for synchronization bugs. This may impact |
|
94 | 101 | people who have custom exception handlers, so I need to warn |
|
95 | 102 | ipython-dev about it (F. Mantegazza may use them). |
|
96 | 103 | |
|
97 | 104 | 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu> |
|
98 | 105 | |
|
99 | 106 | * IPython/genutils.py: fix 2.2 compatibility (generators) |
|
100 | 107 | |
|
101 | 108 | 2005-07-18 Fernando Perez <fperez@colorado.edu> |
|
102 | 109 | |
|
103 | 110 | * IPython/genutils.py (get_home_dir): fix to help users with |
|
104 | 111 | invalid $HOME under win32. |
|
105 | 112 | |
|
106 | 113 | 2005-07-17 Fernando Perez <fperez@colorado.edu> |
|
107 | 114 | |
|
108 | 115 | * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove |
|
109 | 116 | some old hacks and clean up a bit other routines; code should be |
|
110 | 117 | simpler and a bit faster. |
|
111 | 118 | |
|
112 | 119 | * IPython/iplib.py (interact): removed some last-resort attempts |
|
113 | 120 | to survive broken stdout/stderr. That code was only making it |
|
114 | 121 | harder to abstract out the i/o (necessary for gui integration), |
|
115 | 122 | and the crashes it could prevent were extremely rare in practice |
|
116 | 123 | (besides being fully user-induced in a pretty violent manner). |
|
117 | 124 | |
|
118 | 125 | * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff. |
|
119 | 126 | Nothing major yet, but the code is simpler to read; this should |
|
120 | 127 | make it easier to do more serious modifications in the future. |
|
121 | 128 | |
|
122 | 129 | * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh, |
|
123 | 130 | which broke in .15 (thanks to a report by Ville). |
|
124 | 131 | |
|
125 | 132 | * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not |
|
126 | 133 | be quite correct, I know next to nothing about unicode). This |
|
127 | 134 | will allow unicode strings to be used in prompts, amongst other |
|
128 | 135 | cases. It also will prevent ipython from crashing when unicode |
|
129 | 136 | shows up unexpectedly in many places. If ascii encoding fails, we |
|
130 | 137 | assume utf_8. Currently the encoding is not a user-visible |
|
131 | 138 | setting, though it could be made so if there is demand for it. |
|
132 | 139 | |
|
133 | 140 | * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack. |
|
134 | 141 | |
|
135 | 142 | * IPython/Struct.py (Struct.merge): switch keys() to iterator. |
|
136 | 143 | |
|
137 | 144 | * IPython/background_jobs.py: moved 2.2 compatibility to genutils. |
|
138 | 145 | |
|
139 | 146 | * IPython/genutils.py: Add 2.2 compatibility here, so all other |
|
140 | 147 | code can work transparently for 2.2/2.3. |
|
141 | 148 | |
|
142 | 149 | 2005-07-16 Fernando Perez <fperez@colorado.edu> |
|
143 | 150 | |
|
144 | 151 | * IPython/ultraTB.py (ExceptionColors): Make a global variable |
|
145 | 152 | out of the color scheme table used for coloring exception |
|
146 | 153 | tracebacks. This allows user code to add new schemes at runtime. |
|
147 | 154 | This is a minimally modified version of the patch at |
|
148 | 155 | http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw |
|
149 | 156 | for the contribution. |
|
150 | 157 | |
|
151 | 158 | * IPython/FlexCompleter.py (Completer.attr_matches): Add a |
|
152 | 159 | slightly modified version of the patch in |
|
153 | 160 | http://www.scipy.net/roundup/ipython/issue34, which also allows me |
|
154 | 161 | to remove the previous try/except solution (which was costlier). |
|
155 | 162 | Thanks to Gaetan Lehmann <gaetan.lehmann AT jouy.inra.fr> for the fix. |
|
156 | 163 | |
|
157 | 164 | 2005-06-08 Fernando Perez <fperez@colorado.edu> |
|
158 | 165 | |
|
159 | 166 | * IPython/iplib.py (write/write_err): Add methods to abstract all |
|
160 | 167 | I/O a bit more. |
|
161 | 168 | |
|
162 | 169 | * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation |
|
163 | 170 | warning, reported by Aric Hagberg, fix by JD Hunter. |
|
164 | 171 | |
|
165 | 172 | 2005-06-02 *** Released version 0.6.15 |
|
166 | 173 | |
|
167 | 174 | 2005-06-01 Fernando Perez <fperez@colorado.edu> |
|
168 | 175 | |
|
169 | 176 | * IPython/iplib.py (MagicCompleter.file_matches): Fix |
|
170 | 177 | tab-completion of filenames within open-quoted strings. Note that |
|
171 | 178 | this requires that in ~/.ipython/ipythonrc, users change the |
|
172 | 179 | readline delimiters configuration to read: |
|
173 | 180 | |
|
174 | 181 | readline_remove_delims -/~ |
|
175 | 182 | |
|
176 | 183 | |
|
177 | 184 | 2005-05-31 *** Released version 0.6.14 |
|
178 | 185 | |
|
179 | 186 | 2005-05-29 Fernando Perez <fperez@colorado.edu> |
|
180 | 187 | |
|
181 | 188 | * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks |
|
182 | 189 | with files not on the filesystem. Reported by Eliyahu Sandler |
|
183 | 190 | <eli@gondolin.net> |
|
184 | 191 | |
|
185 | 192 | 2005-05-22 Fernando Perez <fperez@colorado.edu> |
|
186 | 193 | |
|
187 | 194 | * IPython/iplib.py: Fix a few crashes in the --upgrade option. |
|
188 | 195 | After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>. |
|
189 | 196 | |
|
190 | 197 | 2005-05-19 Fernando Perez <fperez@colorado.edu> |
|
191 | 198 | |
|
192 | 199 | * IPython/iplib.py (safe_execfile): close a file which could be |
|
193 | 200 | left open (causing problems in win32, which locks open files). |
|
194 | 201 | Thanks to a bug report by D Brown <dbrown2@yahoo.com>. |
|
195 | 202 | |
|
196 | 203 | 2005-05-18 Fernando Perez <fperez@colorado.edu> |
|
197 | 204 | |
|
198 | 205 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all |
|
199 | 206 | keyword arguments correctly to safe_execfile(). |
|
200 | 207 | |
|
201 | 208 | 2005-05-13 Fernando Perez <fperez@colorado.edu> |
|
202 | 209 | |
|
203 | 210 | * ipython.1: Added info about Qt to manpage, and threads warning |
|
204 | 211 | to usage page (invoked with --help). |
|
205 | 212 | |
|
206 | 213 | * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added |
|
207 | 214 | new matcher (it goes at the end of the priority list) to do |
|
208 | 215 | tab-completion on named function arguments. Submitted by George |
|
209 | 216 | Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at |
|
210 | 217 | http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html |
|
211 | 218 | for more details. |
|
212 | 219 | |
|
213 | 220 | * IPython/Magic.py (magic_run): Added new -e flag to ignore |
|
214 | 221 | SystemExit exceptions in the script being run. Thanks to a report |
|
215 | 222 | by danny shevitz <danny_shevitz-AT-yahoo.com>, about this |
|
216 | 223 | producing very annoying behavior when running unit tests. |
|
217 | 224 | |
|
218 | 225 | 2005-05-12 Fernando Perez <fperez@colorado.edu> |
|
219 | 226 | |
|
220 | 227 | * IPython/iplib.py (handle_auto): fixed auto-quoting and parens, |
|
221 | 228 | which I'd broken (again) due to a changed regexp. In the process, |
|
222 | 229 | added ';' as an escape to auto-quote the whole line without |
|
223 | 230 | splitting its arguments. Thanks to a report by Jerry McRae |
|
224 | 231 | <qrs0xyc02-AT-sneakemail.com>. |
|
225 | 232 | |
|
226 | 233 | * IPython/ultraTB.py (VerboseTB.text): protect against rare but |
|
227 | 234 | possible crashes caused by a TokenError. Reported by Ed Schofield |
|
228 | 235 | <schofield-AT-ftw.at>. |
|
229 | 236 | |
|
230 | 237 | 2005-05-06 Fernando Perez <fperez@colorado.edu> |
|
231 | 238 | |
|
232 | 239 | * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6. |
|
233 | 240 | |
|
234 | 241 | 2005-04-29 Fernando Perez <fperez@colorado.edu> |
|
235 | 242 | |
|
236 | 243 | * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière |
|
237 | 244 | <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin |
|
238 | 245 | Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option |
|
239 | 246 | which provides support for Qt interactive usage (similar to the |
|
240 | 247 | existing one for WX and GTK). This had been often requested. |
|
241 | 248 | |
|
242 | 249 | 2005-04-14 *** Released version 0.6.13 |
|
243 | 250 | |
|
244 | 251 | 2005-04-08 Fernando Perez <fperez@colorado.edu> |
|
245 | 252 | |
|
246 | 253 | * IPython/Magic.py (Magic._ofind): remove docstring evaluation |
|
247 | 254 | from _ofind, which gets called on almost every input line. Now, |
|
248 | 255 | we only try to get docstrings if they are actually going to be |
|
249 | 256 | used (the overhead of fetching unnecessary docstrings can be |
|
250 | 257 | noticeable for certain objects, such as Pyro proxies). |
|
251 | 258 | |
|
252 | 259 | * IPython/iplib.py (MagicCompleter.python_matches): Change the API |
|
253 | 260 | for completers. For some reason I had been passing them the state |
|
254 | 261 | variable, which completers never actually need, and was in |
|
255 | 262 | conflict with the rlcompleter API. Custom completers ONLY need to |
|
256 | 263 | take the text parameter. |
|
257 | 264 | |
|
258 | 265 | * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics |
|
259 | 266 | work correctly in pysh. I've also moved all the logic which used |
|
260 | 267 | to be in pysh.py here, which will prevent problems with future |
|
261 | 268 | upgrades. However, this time I must warn users to update their |
|
262 | 269 | pysh profile to include the line |
|
263 | 270 | |
|
264 | 271 | import_all IPython.Extensions.InterpreterExec |
|
265 | 272 | |
|
266 | 273 | because otherwise things won't work for them. They MUST also |
|
267 | 274 | delete pysh.py and the line |
|
268 | 275 | |
|
269 | 276 | execfile pysh.py |
|
270 | 277 | |
|
271 | 278 | from their ipythonrc-pysh. |
|
272 | 279 | |
|
273 | 280 | * IPython/FlexCompleter.py (Completer.attr_matches): Make more |
|
274 | 281 | robust in the face of objects whose dir() returns non-strings |
|
275 | 282 | (which it shouldn't, but some broken libs like ITK do). Thanks to |
|
276 | 283 | a patch by John Hunter (implemented differently, though). Also |
|
277 | 284 | minor improvements by using .extend instead of + on lists. |
|
278 | 285 | |
|
279 | 286 | * pysh.py: |
|
280 | 287 | |
|
281 | 288 | 2005-04-06 Fernando Perez <fperez@colorado.edu> |
|
282 | 289 | |
|
283 | 290 | * IPython/ipmaker.py (make_IPython): Make multi_line_specials on |
|
284 | 291 | by default, so that all users benefit from it. Those who don't |
|
285 | 292 | want it can still turn it off. |
|
286 | 293 | |
|
287 | 294 | * IPython/UserConfig/ipythonrc: Add multi_line_specials to the |
|
288 | 295 | config file, I'd forgotten about this, so users were getting it |
|
289 | 296 | off by default. |
|
290 | 297 | |
|
291 | 298 | * IPython/iplib.py (ipmagic): big overhaul of the magic system for |
|
292 | 299 | consistency. Now magics can be called in multiline statements, |
|
293 | 300 | and python variables can be expanded in magic calls via $var. |
|
294 | 301 | This makes the magic system behave just like aliases or !system |
|
295 | 302 | calls. |
|
296 | 303 | |
|
297 | 304 | 2005-03-28 Fernando Perez <fperez@colorado.edu> |
|
298 | 305 | |
|
299 | 306 | * IPython/iplib.py (handle_auto): cleanup to use %s instead of |
|
300 | 307 | expensive string additions for building command. Add support for |
|
301 | 308 | trailing ';' when autocall is used. |
|
302 | 309 | |
|
303 | 310 | 2005-03-26 Fernando Perez <fperez@colorado.edu> |
|
304 | 311 | |
|
305 | 312 | * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31. |
|
306 | 313 | Bugfix by A. Schmolck, the ipython.el maintainer. Also make |
|
307 | 314 | ipython.el robust against prompts with any number of spaces |
|
308 | 315 | (including 0) after the ':' character. |
|
309 | 316 | |
|
310 | 317 | * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in |
|
311 | 318 | continuation prompt, which misled users to think the line was |
|
312 | 319 | already indented. Closes debian Bug#300847, reported to me by |
|
313 | 320 | Norbert Tretkowski <tretkowski-AT-inittab.de>. |
|
314 | 321 | |
|
315 | 322 | 2005-03-23 Fernando Perez <fperez@colorado.edu> |
|
316 | 323 | |
|
317 | 324 | * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are |
|
318 | 325 | properly aligned if they have embedded newlines. |
|
319 | 326 | |
|
320 | 327 | * IPython/iplib.py (runlines): Add a public method to expose |
|
321 | 328 | IPython's code execution machinery, so that users can run strings |
|
322 | 329 | as if they had been typed at the prompt interactively. |
|
323 | 330 | (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__ |
|
324 | 331 | methods which can call the system shell, but with python variable |
|
325 | 332 | expansion. The three such methods are: __IPYTHON__.system, |
|
326 | 333 | .getoutput and .getoutputerror. These need to be documented in a |
|
327 | 334 | 'public API' section (to be written) of the manual. |
|
328 | 335 | |
|
329 | 336 | 2005-03-20 Fernando Perez <fperez@colorado.edu> |
|
330 | 337 | |
|
331 | 338 | * IPython/iplib.py (InteractiveShell.set_custom_exc): new system |
|
332 | 339 | for custom exception handling. This is quite powerful, and it |
|
333 | 340 | allows for user-installable exception handlers which can trap |
|
334 | 341 | custom exceptions at runtime and treat them separately from |
|
335 | 342 | IPython's default mechanisms. At the request of Frédéric |
|
336 | 343 | Mantegazza <mantegazza-AT-ill.fr>. |
|
337 | 344 | (InteractiveShell.set_custom_completer): public API function to |
|
338 | 345 | add new completers at runtime. |
|
339 | 346 | |
|
340 | 347 | 2005-03-19 Fernando Perez <fperez@colorado.edu> |
|
341 | 348 | |
|
342 | 349 | * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to |
|
343 | 350 | allow objects which provide their docstrings via non-standard |
|
344 | 351 | mechanisms (like Pyro proxies) to still be inspected by ipython's |
|
345 | 352 | ? system. |
|
346 | 353 | |
|
347 | 354 | * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e |
|
348 | 355 | automatic capture system. I tried quite hard to make it work |
|
349 | 356 | reliably, and simply failed. I tried many combinations with the |
|
350 | 357 | subprocess module, but eventually nothing worked in all needed |
|
351 | 358 | cases (not blocking stdin for the child, duplicating stdout |
|
352 | 359 | without blocking, etc). The new %sc/%sx still do capture to these |
|
353 | 360 | magical list/string objects which make shell use much more |
|
354 | 361 | conveninent, so not all is lost. |
|
355 | 362 | |
|
356 | 363 | XXX - FIX MANUAL for the change above! |
|
357 | 364 | |
|
358 | 365 | (runsource): I copied code.py's runsource() into ipython to modify |
|
359 | 366 | it a bit. Now the code object and source to be executed are |
|
360 | 367 | stored in ipython. This makes this info accessible to third-party |
|
361 | 368 | tools, like custom exception handlers. After a request by Frédéric |
|
362 | 369 | Mantegazza <mantegazza-AT-ill.fr>. |
|
363 | 370 | |
|
364 | 371 | * IPython/UserConfig/ipythonrc: Add up/down arrow keys to |
|
365 | 372 | history-search via readline (like C-p/C-n). I'd wanted this for a |
|
366 | 373 | long time, but only recently found out how to do it. For users |
|
367 | 374 | who already have their ipythonrc files made and want this, just |
|
368 | 375 | add: |
|
369 | 376 | |
|
370 | 377 | readline_parse_and_bind "\e[A": history-search-backward |
|
371 | 378 | readline_parse_and_bind "\e[B": history-search-forward |
|
372 | 379 | |
|
373 | 380 | 2005-03-18 Fernando Perez <fperez@colorado.edu> |
|
374 | 381 | |
|
375 | 382 | * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy |
|
376 | 383 | LSString and SList classes which allow transparent conversions |
|
377 | 384 | between list mode and whitespace-separated string. |
|
378 | 385 | (magic_r): Fix recursion problem in %r. |
|
379 | 386 | |
|
380 | 387 | * IPython/genutils.py (LSString): New class to be used for |
|
381 | 388 | automatic storage of the results of all alias/system calls in _o |
|
382 | 389 | and _e (stdout/err). These provide a .l/.list attribute which |
|
383 | 390 | does automatic splitting on newlines. This means that for most |
|
384 | 391 | uses, you'll never need to do capturing of output with %sc/%sx |
|
385 | 392 | anymore, since ipython keeps this always done for you. Note that |
|
386 | 393 | only the LAST results are stored, the _o/e variables are |
|
387 | 394 | overwritten on each call. If you need to save their contents |
|
388 | 395 | further, simply bind them to any other name. |
|
389 | 396 | |
|
390 | 397 | 2005-03-17 Fernando Perez <fperez@colorado.edu> |
|
391 | 398 | |
|
392 | 399 | * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for |
|
393 | 400 | prompt namespace handling. |
|
394 | 401 | |
|
395 | 402 | 2005-03-16 Fernando Perez <fperez@colorado.edu> |
|
396 | 403 | |
|
397 | 404 | * IPython/Prompts.py (CachedOutput.__init__): Fix default and |
|
398 | 405 | classic prompts to be '>>> ' (final space was missing, and it |
|
399 | 406 | trips the emacs python mode). |
|
400 | 407 | (BasePrompt.__str__): Added safe support for dynamic prompt |
|
401 | 408 | strings. Now you can set your prompt string to be '$x', and the |
|
402 | 409 | value of x will be printed from your interactive namespace. The |
|
403 | 410 | interpolation syntax includes the full Itpl support, so |
|
404 | 411 | ${foo()+x+bar()} is a valid prompt string now, and the function |
|
405 | 412 | calls will be made at runtime. |
|
406 | 413 | |
|
407 | 414 | 2005-03-15 Fernando Perez <fperez@colorado.edu> |
|
408 | 415 | |
|
409 | 416 | * IPython/Magic.py (magic_history): renamed %hist to %history, to |
|
410 | 417 | avoid name clashes in pylab. %hist still works, it just forwards |
|
411 | 418 | the call to %history. |
|
412 | 419 | |
|
413 | 420 | 2005-03-02 *** Released version 0.6.12 |
|
414 | 421 | |
|
415 | 422 | 2005-03-02 Fernando Perez <fperez@colorado.edu> |
|
416 | 423 | |
|
417 | 424 | * IPython/iplib.py (handle_magic): log magic calls properly as |
|
418 | 425 | ipmagic() function calls. |
|
419 | 426 | |
|
420 | 427 | * IPython/Magic.py (magic_time): Improved %time to support |
|
421 | 428 | statements and provide wall-clock as well as CPU time. |
|
422 | 429 | |
|
423 | 430 | 2005-02-27 Fernando Perez <fperez@colorado.edu> |
|
424 | 431 | |
|
425 | 432 | * IPython/hooks.py: New hooks module, to expose user-modifiable |
|
426 | 433 | IPython functionality in a clean manner. For now only the editor |
|
427 | 434 | hook is actually written, and other thigns which I intend to turn |
|
428 | 435 | into proper hooks aren't yet there. The display and prefilter |
|
429 | 436 | stuff, for example, should be hooks. But at least now the |
|
430 | 437 | framework is in place, and the rest can be moved here with more |
|
431 | 438 | time later. IPython had had a .hooks variable for a long time for |
|
432 | 439 | this purpose, but I'd never actually used it for anything. |
|
433 | 440 | |
|
434 | 441 | 2005-02-26 Fernando Perez <fperez@colorado.edu> |
|
435 | 442 | |
|
436 | 443 | * IPython/ipmaker.py (make_IPython): make the default ipython |
|
437 | 444 | directory be called _ipython under win32, to follow more the |
|
438 | 445 | naming peculiarities of that platform (where buggy software like |
|
439 | 446 | Visual Sourcesafe breaks with .named directories). Reported by |
|
440 | 447 | Ville Vainio. |
|
441 | 448 | |
|
442 | 449 | 2005-02-23 Fernando Perez <fperez@colorado.edu> |
|
443 | 450 | |
|
444 | 451 | * IPython/iplib.py (InteractiveShell.__init__): removed a few |
|
445 | 452 | auto_aliases for win32 which were causing problems. Users can |
|
446 | 453 | define the ones they personally like. |
|
447 | 454 | |
|
448 | 455 | 2005-02-21 Fernando Perez <fperez@colorado.edu> |
|
449 | 456 | |
|
450 | 457 | * IPython/Magic.py (magic_time): new magic to time execution of |
|
451 | 458 | expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>. |
|
452 | 459 | |
|
453 | 460 | 2005-02-19 Fernando Perez <fperez@colorado.edu> |
|
454 | 461 | |
|
455 | 462 | * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings |
|
456 | 463 | into keys (for prompts, for example). |
|
457 | 464 | |
|
458 | 465 | * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty |
|
459 | 466 | prompts in case users want them. This introduces a small behavior |
|
460 | 467 | change: ipython does not automatically add a space to all prompts |
|
461 | 468 | anymore. To get the old prompts with a space, users should add it |
|
462 | 469 | manually to their ipythonrc file, so for example prompt_in1 should |
|
463 | 470 | now read 'In [\#]: ' instead of 'In [\#]:'. |
|
464 | 471 | (BasePrompt.__init__): New option prompts_pad_left (only in rc |
|
465 | 472 | file) to control left-padding of secondary prompts. |
|
466 | 473 | |
|
467 | 474 | * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if |
|
468 | 475 | the profiler can't be imported. Fix for Debian, which removed |
|
469 | 476 | profile.py because of License issues. I applied a slightly |
|
470 | 477 | modified version of the original Debian patch at |
|
471 | 478 | http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500. |
|
472 | 479 | |
|
473 | 480 | 2005-02-17 Fernando Perez <fperez@colorado.edu> |
|
474 | 481 | |
|
475 | 482 | * IPython/genutils.py (native_line_ends): Fix bug which would |
|
476 | 483 | cause improper line-ends under win32 b/c I was not opening files |
|
477 | 484 | in binary mode. Bug report and fix thanks to Ville. |
|
478 | 485 | |
|
479 | 486 | * IPython/iplib.py (handle_auto): Fix bug which I introduced when |
|
480 | 487 | trying to catch spurious foo[1] autocalls. My fix actually broke |
|
481 | 488 | ',/' autoquote/call with explicit escape (bad regexp). |
|
482 | 489 | |
|
483 | 490 | 2005-02-15 *** Released version 0.6.11 |
|
484 | 491 | |
|
485 | 492 | 2005-02-14 Fernando Perez <fperez@colorado.edu> |
|
486 | 493 | |
|
487 | 494 | * IPython/background_jobs.py: New background job management |
|
488 | 495 | subsystem. This is implemented via a new set of classes, and |
|
489 | 496 | IPython now provides a builtin 'jobs' object for background job |
|
490 | 497 | execution. A convenience %bg magic serves as a lightweight |
|
491 | 498 | frontend for starting the more common type of calls. This was |
|
492 | 499 | inspired by discussions with B. Granger and the BackgroundCommand |
|
493 | 500 | class described in the book Python Scripting for Computational |
|
494 | 501 | Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting |
|
495 | 502 | (although ultimately no code from this text was used, as IPython's |
|
496 | 503 | system is a separate implementation). |
|
497 | 504 | |
|
498 | 505 | * IPython/iplib.py (MagicCompleter.python_matches): add new option |
|
499 | 506 | to control the completion of single/double underscore names |
|
500 | 507 | separately. As documented in the example ipytonrc file, the |
|
501 | 508 | readline_omit__names variable can now be set to 2, to omit even |
|
502 | 509 | single underscore names. Thanks to a patch by Brian Wong |
|
503 | 510 | <BrianWong-AT-AirgoNetworks.Com>. |
|
504 | 511 | (InteractiveShell.__init__): Fix bug which would cause foo[1] to |
|
505 | 512 | be autocalled as foo([1]) if foo were callable. A problem for |
|
506 | 513 | things which are both callable and implement __getitem__. |
|
507 | 514 | (init_readline): Fix autoindentation for win32. Thanks to a patch |
|
508 | 515 | by Vivian De Smedt <vivian-AT-vdesmedt.com>. |
|
509 | 516 | |
|
510 | 517 | 2005-02-12 Fernando Perez <fperez@colorado.edu> |
|
511 | 518 | |
|
512 | 519 | * IPython/ipmaker.py (make_IPython): Disabled the stout traps |
|
513 | 520 | which I had written long ago to sort out user error messages which |
|
514 | 521 | may occur during startup. This seemed like a good idea initially, |
|
515 | 522 | but it has proven a disaster in retrospect. I don't want to |
|
516 | 523 | change much code for now, so my fix is to set the internal 'debug' |
|
517 | 524 | flag to true everywhere, whose only job was precisely to control |
|
518 | 525 | this subsystem. This closes issue 28 (as well as avoiding all |
|
519 | 526 | sorts of strange hangups which occur from time to time). |
|
520 | 527 | |
|
521 | 528 | 2005-02-07 Fernando Perez <fperez@colorado.edu> |
|
522 | 529 | |
|
523 | 530 | * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the |
|
524 | 531 | previous call produced a syntax error. |
|
525 | 532 | |
|
526 | 533 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
527 | 534 | classes without constructor. |
|
528 | 535 | |
|
529 | 536 | 2005-02-06 Fernando Perez <fperez@colorado.edu> |
|
530 | 537 | |
|
531 | 538 | * IPython/iplib.py (MagicCompleter.complete): Extend the list of |
|
532 | 539 | completions with the results of each matcher, so we return results |
|
533 | 540 | to the user from all namespaces. This breaks with ipython |
|
534 | 541 | tradition, but I think it's a nicer behavior. Now you get all |
|
535 | 542 | possible completions listed, from all possible namespaces (python, |
|
536 | 543 | filesystem, magics...) After a request by John Hunter |
|
537 | 544 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
538 | 545 | |
|
539 | 546 | 2005-02-05 Fernando Perez <fperez@colorado.edu> |
|
540 | 547 | |
|
541 | 548 | * IPython/Magic.py (magic_prun): Fix bug where prun would fail if |
|
542 | 549 | the call had quote characters in it (the quotes were stripped). |
|
543 | 550 | |
|
544 | 551 | 2005-01-31 Fernando Perez <fperez@colorado.edu> |
|
545 | 552 | |
|
546 | 553 | * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on |
|
547 | 554 | Itpl.itpl() to make the code more robust against psyco |
|
548 | 555 | optimizations. |
|
549 | 556 | |
|
550 | 557 | * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead |
|
551 | 558 | of causing an exception. Quicker, cleaner. |
|
552 | 559 | |
|
553 | 560 | 2005-01-28 Fernando Perez <fperez@colorado.edu> |
|
554 | 561 | |
|
555 | 562 | * scripts/ipython_win_post_install.py (install): hardcode |
|
556 | 563 | sys.prefix+'python.exe' as the executable path. It turns out that |
|
557 | 564 | during the post-installation run, sys.executable resolves to the |
|
558 | 565 | name of the binary installer! I should report this as a distutils |
|
559 | 566 | bug, I think. I updated the .10 release with this tiny fix, to |
|
560 | 567 | avoid annoying the lists further. |
|
561 | 568 | |
|
562 | 569 | 2005-01-27 *** Released version 0.6.10 |
|
563 | 570 | |
|
564 | 571 | 2005-01-27 Fernando Perez <fperez@colorado.edu> |
|
565 | 572 | |
|
566 | 573 | * IPython/numutils.py (norm): Added 'inf' as optional name for |
|
567 | 574 | L-infinity norm, included references to mathworld.com for vector |
|
568 | 575 | norm definitions. |
|
569 | 576 | (amin/amax): added amin/amax for array min/max. Similar to what |
|
570 | 577 | pylab ships with after the recent reorganization of names. |
|
571 | 578 | (spike/spike_odd): removed deprecated spike/spike_odd functions. |
|
572 | 579 | |
|
573 | 580 | * ipython.el: committed Alex's recent fixes and improvements. |
|
574 | 581 | Tested with python-mode from CVS, and it looks excellent. Since |
|
575 | 582 | python-mode hasn't released anything in a while, I'm temporarily |
|
576 | 583 | putting a copy of today's CVS (v 4.70) of python-mode in: |
|
577 | 584 | http://ipython.scipy.org/tmp/python-mode.el |
|
578 | 585 | |
|
579 | 586 | * scripts/ipython_win_post_install.py (install): Win32 fix to use |
|
580 | 587 | sys.executable for the executable name, instead of assuming it's |
|
581 | 588 | called 'python.exe' (the post-installer would have produced broken |
|
582 | 589 | setups on systems with a differently named python binary). |
|
583 | 590 | |
|
584 | 591 | * IPython/PyColorize.py (Parser.__call__): change explicit '\n' |
|
585 | 592 | references to os.linesep, to make the code more |
|
586 | 593 | platform-independent. This is also part of the win32 coloring |
|
587 | 594 | fixes. |
|
588 | 595 | |
|
589 | 596 | * IPython/genutils.py (page_dumb): Remove attempts to chop long |
|
590 | 597 | lines, which actually cause coloring bugs because the length of |
|
591 | 598 | the line is very difficult to correctly compute with embedded |
|
592 | 599 | escapes. This was the source of all the coloring problems under |
|
593 | 600 | Win32. I think that _finally_, Win32 users have a properly |
|
594 | 601 | working ipython in all respects. This would never have happened |
|
595 | 602 | if not for Gary Bishop and Viktor Ransmayr's great help and work. |
|
596 | 603 | |
|
597 | 604 | 2005-01-26 *** Released version 0.6.9 |
|
598 | 605 | |
|
599 | 606 | 2005-01-25 Fernando Perez <fperez@colorado.edu> |
|
600 | 607 | |
|
601 | 608 | * setup.py: finally, we have a true Windows installer, thanks to |
|
602 | 609 | the excellent work of Viktor Ransmayr |
|
603 | 610 | <viktor.ransmayr-AT-t-online.de>. The docs have been updated for |
|
604 | 611 | Windows users. The setup routine is quite a bit cleaner thanks to |
|
605 | 612 | this, and the post-install script uses the proper functions to |
|
606 | 613 | allow a clean de-installation using the standard Windows Control |
|
607 | 614 | Panel. |
|
608 | 615 | |
|
609 | 616 | * IPython/genutils.py (get_home_dir): changed to use the $HOME |
|
610 | 617 | environment variable under all OSes (including win32) if |
|
611 | 618 | available. This will give consistency to win32 users who have set |
|
612 | 619 | this variable for any reason. If os.environ['HOME'] fails, the |
|
613 | 620 | previous policy of using HOMEDRIVE\HOMEPATH kicks in. |
|
614 | 621 | |
|
615 | 622 | 2005-01-24 Fernando Perez <fperez@colorado.edu> |
|
616 | 623 | |
|
617 | 624 | * IPython/numutils.py (empty_like): add empty_like(), similar to |
|
618 | 625 | zeros_like() but taking advantage of the new empty() Numeric routine. |
|
619 | 626 | |
|
620 | 627 | 2005-01-23 *** Released version 0.6.8 |
|
621 | 628 | |
|
622 | 629 | 2005-01-22 Fernando Perez <fperez@colorado.edu> |
|
623 | 630 | |
|
624 | 631 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the |
|
625 | 632 | automatic show() calls. After discussing things with JDH, it |
|
626 | 633 | turns out there are too many corner cases where this can go wrong. |
|
627 | 634 | It's best not to try to be 'too smart', and simply have ipython |
|
628 | 635 | reproduce as much as possible the default behavior of a normal |
|
629 | 636 | python shell. |
|
630 | 637 | |
|
631 | 638 | * IPython/iplib.py (InteractiveShell.__init__): Modified the |
|
632 | 639 | line-splitting regexp and _prefilter() to avoid calling getattr() |
|
633 | 640 | on assignments. This closes |
|
634 | 641 | http://www.scipy.net/roundup/ipython/issue24. Note that Python's |
|
635 | 642 | readline uses getattr(), so a simple <TAB> keypress is still |
|
636 | 643 | enough to trigger getattr() calls on an object. |
|
637 | 644 | |
|
638 | 645 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
639 | 646 | |
|
640 | 647 | * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run |
|
641 | 648 | docstring under pylab so it doesn't mask the original. |
|
642 | 649 | |
|
643 | 650 | 2005-01-21 *** Released version 0.6.7 |
|
644 | 651 | |
|
645 | 652 | 2005-01-21 Fernando Perez <fperez@colorado.edu> |
|
646 | 653 | |
|
647 | 654 | * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with |
|
648 | 655 | signal handling for win32 users in multithreaded mode. |
|
649 | 656 | |
|
650 | 657 | 2005-01-17 Fernando Perez <fperez@colorado.edu> |
|
651 | 658 | |
|
652 | 659 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting |
|
653 | 660 | instances with no __init__. After a crash report by Norbert Nemec |
|
654 | 661 | <Norbert-AT-nemec-online.de>. |
|
655 | 662 | |
|
656 | 663 | 2005-01-14 Fernando Perez <fperez@colorado.edu> |
|
657 | 664 | |
|
658 | 665 | * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of |
|
659 | 666 | names for verbose exceptions, when multiple dotted names and the |
|
660 | 667 | 'parent' object were present on the same line. |
|
661 | 668 | |
|
662 | 669 | 2005-01-11 Fernando Perez <fperez@colorado.edu> |
|
663 | 670 | |
|
664 | 671 | * IPython/genutils.py (flag_calls): new utility to trap and flag |
|
665 | 672 | calls in functions. I need it to clean up matplotlib support. |
|
666 | 673 | Also removed some deprecated code in genutils. |
|
667 | 674 | |
|
668 | 675 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so |
|
669 | 676 | that matplotlib scripts called with %run, which don't call show() |
|
670 | 677 | themselves, still have their plotting windows open. |
|
671 | 678 | |
|
672 | 679 | 2005-01-05 Fernando Perez <fperez@colorado.edu> |
|
673 | 680 | |
|
674 | 681 | * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw |
|
675 | 682 | <astraw-AT-caltech.edu>, to fix gtk deprecation warnings. |
|
676 | 683 | |
|
677 | 684 | 2004-12-19 Fernando Perez <fperez@colorado.edu> |
|
678 | 685 | |
|
679 | 686 | * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of |
|
680 | 687 | parent_runcode, which was an eyesore. The same result can be |
|
681 | 688 | obtained with Python's regular superclass mechanisms. |
|
682 | 689 | |
|
683 | 690 | 2004-12-17 Fernando Perez <fperez@colorado.edu> |
|
684 | 691 | |
|
685 | 692 | * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem |
|
686 | 693 | reported by Prabhu. |
|
687 | 694 | (Magic.magic_sx): direct all errors to Term.cerr (defaults to |
|
688 | 695 | sys.stderr) instead of explicitly calling sys.stderr. This helps |
|
689 | 696 | maintain our I/O abstractions clean, for future GUI embeddings. |
|
690 | 697 | |
|
691 | 698 | * IPython/genutils.py (info): added new utility for sys.stderr |
|
692 | 699 | unified info message handling (thin wrapper around warn()). |
|
693 | 700 | |
|
694 | 701 | * IPython/ultraTB.py (VerboseTB.text): Fix misreported global |
|
695 | 702 | composite (dotted) names on verbose exceptions. |
|
696 | 703 | (VerboseTB.nullrepr): harden against another kind of errors which |
|
697 | 704 | Python's inspect module can trigger, and which were crashing |
|
698 | 705 | IPython. Thanks to a report by Marco Lombardi |
|
699 | 706 | <mlombard-AT-ma010192.hq.eso.org>. |
|
700 | 707 | |
|
701 | 708 | 2004-12-13 *** Released version 0.6.6 |
|
702 | 709 | |
|
703 | 710 | 2004-12-12 Fernando Perez <fperez@colorado.edu> |
|
704 | 711 | |
|
705 | 712 | * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors |
|
706 | 713 | generated by pygtk upon initialization if it was built without |
|
707 | 714 | threads (for matplotlib users). After a crash reported by |
|
708 | 715 | Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>. |
|
709 | 716 | |
|
710 | 717 | * IPython/ipmaker.py (make_IPython): fix small bug in the |
|
711 | 718 | import_some parameter for multiple imports. |
|
712 | 719 | |
|
713 | 720 | * IPython/iplib.py (ipmagic): simplified the interface of |
|
714 | 721 | ipmagic() to take a single string argument, just as it would be |
|
715 | 722 | typed at the IPython cmd line. |
|
716 | 723 | (ipalias): Added new ipalias() with an interface identical to |
|
717 | 724 | ipmagic(). This completes exposing a pure python interface to the |
|
718 | 725 | alias and magic system, which can be used in loops or more complex |
|
719 | 726 | code where IPython's automatic line mangling is not active. |
|
720 | 727 | |
|
721 | 728 | * IPython/genutils.py (timing): changed interface of timing to |
|
722 | 729 | simply run code once, which is the most common case. timings() |
|
723 | 730 | remains unchanged, for the cases where you want multiple runs. |
|
724 | 731 | |
|
725 | 732 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a |
|
726 | 733 | bug where Python2.2 crashes with exec'ing code which does not end |
|
727 | 734 | in a single newline. Python 2.3 is OK, so I hadn't noticed this |
|
728 | 735 | before. |
|
729 | 736 | |
|
730 | 737 | 2004-12-10 Fernando Perez <fperez@colorado.edu> |
|
731 | 738 | |
|
732 | 739 | * IPython/Magic.py (Magic.magic_prun): changed name of option from |
|
733 | 740 | -t to -T, to accomodate the new -t flag in %run (the %run and |
|
734 | 741 | %prun options are kind of intermixed, and it's not easy to change |
|
735 | 742 | this with the limitations of python's getopt). |
|
736 | 743 | |
|
737 | 744 | * IPython/Magic.py (Magic.magic_run): Added new -t option to time |
|
738 | 745 | the execution of scripts. It's not as fine-tuned as timeit.py, |
|
739 | 746 | but it works from inside ipython (and under 2.2, which lacks |
|
740 | 747 | timeit.py). Optionally a number of runs > 1 can be given for |
|
741 | 748 | timing very short-running code. |
|
742 | 749 | |
|
743 | 750 | * IPython/genutils.py (uniq_stable): new routine which returns a |
|
744 | 751 | list of unique elements in any iterable, but in stable order of |
|
745 | 752 | appearance. I needed this for the ultraTB fixes, and it's a handy |
|
746 | 753 | utility. |
|
747 | 754 | |
|
748 | 755 | * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of |
|
749 | 756 | dotted names in Verbose exceptions. This had been broken since |
|
750 | 757 | the very start, now x.y will properly be printed in a Verbose |
|
751 | 758 | traceback, instead of x being shown and y appearing always as an |
|
752 | 759 | 'undefined global'. Getting this to work was a bit tricky, |
|
753 | 760 | because by default python tokenizers are stateless. Saved by |
|
754 | 761 | python's ability to easily add a bit of state to an arbitrary |
|
755 | 762 | function (without needing to build a full-blown callable object). |
|
756 | 763 | |
|
757 | 764 | Also big cleanup of this code, which had horrendous runtime |
|
758 | 765 | lookups of zillions of attributes for colorization. Moved all |
|
759 | 766 | this code into a few templates, which make it cleaner and quicker. |
|
760 | 767 | |
|
761 | 768 | Printout quality was also improved for Verbose exceptions: one |
|
762 | 769 | variable per line, and memory addresses are printed (this can be |
|
763 | 770 | quite handy in nasty debugging situations, which is what Verbose |
|
764 | 771 | is for). |
|
765 | 772 | |
|
766 | 773 | * IPython/ipmaker.py (make_IPython): Do NOT execute files named in |
|
767 | 774 | the command line as scripts to be loaded by embedded instances. |
|
768 | 775 | Doing so has the potential for an infinite recursion if there are |
|
769 | 776 | exceptions thrown in the process. This fixes a strange crash |
|
770 | 777 | reported by Philippe MULLER <muller-AT-irit.fr>. |
|
771 | 778 | |
|
772 | 779 | 2004-12-09 Fernando Perez <fperez@colorado.edu> |
|
773 | 780 | |
|
774 | 781 | * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support |
|
775 | 782 | to reflect new names in matplotlib, which now expose the |
|
776 | 783 | matlab-compatible interface via a pylab module instead of the |
|
777 | 784 | 'matlab' name. The new code is backwards compatible, so users of |
|
778 | 785 | all matplotlib versions are OK. Patch by J. Hunter. |
|
779 | 786 | |
|
780 | 787 | * IPython/OInspect.py (Inspector.pinfo): Add to object? printing |
|
781 | 788 | of __init__ docstrings for instances (class docstrings are already |
|
782 | 789 | automatically printed). Instances with customized docstrings |
|
783 | 790 | (indep. of the class) are also recognized and all 3 separate |
|
784 | 791 | docstrings are printed (instance, class, constructor). After some |
|
785 | 792 | comments/suggestions by J. Hunter. |
|
786 | 793 | |
|
787 | 794 | 2004-12-05 Fernando Perez <fperez@colorado.edu> |
|
788 | 795 | |
|
789 | 796 | * IPython/iplib.py (MagicCompleter.complete): Remove annoying |
|
790 | 797 | warnings when tab-completion fails and triggers an exception. |
|
791 | 798 | |
|
792 | 799 | 2004-12-03 Fernando Perez <fperez@colorado.edu> |
|
793 | 800 | |
|
794 | 801 | * IPython/Magic.py (magic_prun): Fix bug where an exception would |
|
795 | 802 | be triggered when using 'run -p'. An incorrect option flag was |
|
796 | 803 | being set ('d' instead of 'D'). |
|
797 | 804 | (manpage): fix missing escaped \- sign. |
|
798 | 805 | |
|
799 | 806 | 2004-11-30 *** Released version 0.6.5 |
|
800 | 807 | |
|
801 | 808 | 2004-11-30 Fernando Perez <fperez@colorado.edu> |
|
802 | 809 | |
|
803 | 810 | * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint |
|
804 | 811 | setting with -d option. |
|
805 | 812 | |
|
806 | 813 | * setup.py (docfiles): Fix problem where the doc glob I was using |
|
807 | 814 | was COMPLETELY BROKEN. It was giving the right files by pure |
|
808 | 815 | accident, but failed once I tried to include ipython.el. Note: |
|
809 | 816 | glob() does NOT allow you to do exclusion on multiple endings! |
|
810 | 817 | |
|
811 | 818 | 2004-11-29 Fernando Perez <fperez@colorado.edu> |
|
812 | 819 | |
|
813 | 820 | * IPython/usage.py (__doc__): cleaned up usage docstring, by using |
|
814 | 821 | the manpage as the source. Better formatting & consistency. |
|
815 | 822 | |
|
816 | 823 | * IPython/Magic.py (magic_run): Added new -d option, to run |
|
817 | 824 | scripts under the control of the python pdb debugger. Note that |
|
818 | 825 | this required changing the %prun option -d to -D, to avoid a clash |
|
819 | 826 | (since %run must pass options to %prun, and getopt is too dumb to |
|
820 | 827 | handle options with string values with embedded spaces). Thanks |
|
821 | 828 | to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>. |
|
822 | 829 | (magic_who_ls): added type matching to %who and %whos, so that one |
|
823 | 830 | can filter their output to only include variables of certain |
|
824 | 831 | types. Another suggestion by Matthew. |
|
825 | 832 | (magic_whos): Added memory summaries in kb and Mb for arrays. |
|
826 | 833 | (magic_who): Improve formatting (break lines every 9 vars). |
|
827 | 834 | |
|
828 | 835 | 2004-11-28 Fernando Perez <fperez@colorado.edu> |
|
829 | 836 | |
|
830 | 837 | * IPython/Logger.py (Logger.log): Fix bug in syncing the input |
|
831 | 838 | cache when empty lines were present. |
|
832 | 839 | |
|
833 | 840 | 2004-11-24 Fernando Perez <fperez@colorado.edu> |
|
834 | 841 | |
|
835 | 842 | * IPython/usage.py (__doc__): document the re-activated threading |
|
836 | 843 | options for WX and GTK. |
|
837 | 844 | |
|
838 | 845 | 2004-11-23 Fernando Perez <fperez@colorado.edu> |
|
839 | 846 | |
|
840 | 847 | * IPython/Shell.py (start): Added Prabhu's big patch to reactivate |
|
841 | 848 | the -wthread and -gthread options, along with a new -tk one to try |
|
842 | 849 | and coordinate Tk threading with wx/gtk. The tk support is very |
|
843 | 850 | platform dependent, since it seems to require Tcl and Tk to be |
|
844 | 851 | built with threads (Fedora1/2 appears NOT to have it, but in |
|
845 | 852 | Prabhu's Debian boxes it works OK). But even with some Tk |
|
846 | 853 | limitations, this is a great improvement. |
|
847 | 854 | |
|
848 | 855 | * IPython/Prompts.py (prompt_specials_color): Added \t for time |
|
849 | 856 | info in user prompts. Patch by Prabhu. |
|
850 | 857 | |
|
851 | 858 | 2004-11-18 Fernando Perez <fperez@colorado.edu> |
|
852 | 859 | |
|
853 | 860 | * IPython/genutils.py (ask_yes_no): Add check for a max of 20 |
|
854 | 861 | EOFErrors and bail, to avoid infinite loops if a non-terminating |
|
855 | 862 | file is fed into ipython. Patch submitted in issue 19 by user, |
|
856 | 863 | many thanks. |
|
857 | 864 | |
|
858 | 865 | * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger |
|
859 | 866 | autoquote/parens in continuation prompts, which can cause lots of |
|
860 | 867 | problems. Closes roundup issue 20. |
|
861 | 868 | |
|
862 | 869 | 2004-11-17 Fernando Perez <fperez@colorado.edu> |
|
863 | 870 | |
|
864 | 871 | * debian/control (Build-Depends-Indep): Fix dpatch dependency, |
|
865 | 872 | reported as debian bug #280505. I'm not sure my local changelog |
|
866 | 873 | entry has the proper debian format (Jack?). |
|
867 | 874 | |
|
868 | 875 | 2004-11-08 *** Released version 0.6.4 |
|
869 | 876 | |
|
870 | 877 | 2004-11-08 Fernando Perez <fperez@colorado.edu> |
|
871 | 878 | |
|
872 | 879 | * IPython/iplib.py (init_readline): Fix exit message for Windows |
|
873 | 880 | when readline is active. Thanks to a report by Eric Jones |
|
874 | 881 | <eric-AT-enthought.com>. |
|
875 | 882 | |
|
876 | 883 | 2004-11-07 Fernando Perez <fperez@colorado.edu> |
|
877 | 884 | |
|
878 | 885 | * IPython/genutils.py (page): Add a trap for OSError exceptions, |
|
879 | 886 | sometimes seen by win2k/cygwin users. |
|
880 | 887 | |
|
881 | 888 | 2004-11-06 Fernando Perez <fperez@colorado.edu> |
|
882 | 889 | |
|
883 | 890 | * IPython/iplib.py (interact): Change the handling of %Exit from |
|
884 | 891 | trying to propagate a SystemExit to an internal ipython flag. |
|
885 | 892 | This is less elegant than using Python's exception mechanism, but |
|
886 | 893 | I can't get that to work reliably with threads, so under -pylab |
|
887 | 894 | %Exit was hanging IPython. Cross-thread exception handling is |
|
888 | 895 | really a bitch. Thaks to a bug report by Stephen Walton |
|
889 | 896 | <stephen.walton-AT-csun.edu>. |
|
890 | 897 | |
|
891 | 898 | 2004-11-04 Fernando Perez <fperez@colorado.edu> |
|
892 | 899 | |
|
893 | 900 | * IPython/iplib.py (raw_input_original): store a pointer to the |
|
894 | 901 | true raw_input to harden against code which can modify it |
|
895 | 902 | (wx.py.PyShell does this and would otherwise crash ipython). |
|
896 | 903 | Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>. |
|
897 | 904 | |
|
898 | 905 | * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for |
|
899 | 906 | Ctrl-C problem, which does not mess up the input line. |
|
900 | 907 | |
|
901 | 908 | 2004-11-03 Fernando Perez <fperez@colorado.edu> |
|
902 | 909 | |
|
903 | 910 | * IPython/Release.py: Changed licensing to BSD, in all files. |
|
904 | 911 | (name): lowercase name for tarball/RPM release. |
|
905 | 912 | |
|
906 | 913 | * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for |
|
907 | 914 | use throughout ipython. |
|
908 | 915 | |
|
909 | 916 | * IPython/Magic.py (Magic._ofind): Switch to using the new |
|
910 | 917 | OInspect.getdoc() function. |
|
911 | 918 | |
|
912 | 919 | * IPython/Shell.py (sigint_handler): Hack to ignore the execution |
|
913 | 920 | of the line currently being canceled via Ctrl-C. It's extremely |
|
914 | 921 | ugly, but I don't know how to do it better (the problem is one of |
|
915 | 922 | handling cross-thread exceptions). |
|
916 | 923 | |
|
917 | 924 | 2004-10-28 Fernando Perez <fperez@colorado.edu> |
|
918 | 925 | |
|
919 | 926 | * IPython/Shell.py (signal_handler): add signal handlers to trap |
|
920 | 927 | SIGINT and SIGSEGV in threaded code properly. Thanks to a bug |
|
921 | 928 | report by Francesc Alted. |
|
922 | 929 | |
|
923 | 930 | 2004-10-21 Fernando Perez <fperez@colorado.edu> |
|
924 | 931 | |
|
925 | 932 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @ |
|
926 | 933 | to % for pysh syntax extensions. |
|
927 | 934 | |
|
928 | 935 | 2004-10-09 Fernando Perez <fperez@colorado.edu> |
|
929 | 936 | |
|
930 | 937 | * IPython/Magic.py (Magic.magic_whos): modify output of Numeric |
|
931 | 938 | arrays to print a more useful summary, without calling str(arr). |
|
932 | 939 | This avoids the problem of extremely lengthy computations which |
|
933 | 940 | occur if arr is large, and appear to the user as a system lockup |
|
934 | 941 | with 100% cpu activity. After a suggestion by Kristian Sandberg |
|
935 | 942 | <Kristian.Sandberg@colorado.edu>. |
|
936 | 943 | (Magic.__init__): fix bug in global magic escapes not being |
|
937 | 944 | correctly set. |
|
938 | 945 | |
|
939 | 946 | 2004-10-08 Fernando Perez <fperez@colorado.edu> |
|
940 | 947 | |
|
941 | 948 | * IPython/Magic.py (__license__): change to absolute imports of |
|
942 | 949 | ipython's own internal packages, to start adapting to the absolute |
|
943 | 950 | import requirement of PEP-328. |
|
944 | 951 | |
|
945 | 952 | * IPython/genutils.py (__author__): Fix coding to utf-8 on all |
|
946 | 953 | files, and standardize author/license marks through the Release |
|
947 | 954 | module instead of having per/file stuff (except for files with |
|
948 | 955 | particular licenses, like the MIT/PSF-licensed codes). |
|
949 | 956 | |
|
950 | 957 | * IPython/Debugger.py: remove dead code for python 2.1 |
|
951 | 958 | |
|
952 | 959 | 2004-10-04 Fernando Perez <fperez@colorado.edu> |
|
953 | 960 | |
|
954 | 961 | * IPython/iplib.py (ipmagic): New function for accessing magics |
|
955 | 962 | via a normal python function call. |
|
956 | 963 | |
|
957 | 964 | * IPython/Magic.py (Magic.magic_magic): Change the magic escape |
|
958 | 965 | from '@' to '%', to accomodate the new @decorator syntax of python |
|
959 | 966 | 2.4. |
|
960 | 967 | |
|
961 | 968 | 2004-09-29 Fernando Perez <fperez@colorado.edu> |
|
962 | 969 | |
|
963 | 970 | * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to |
|
964 | 971 | matplotlib.use to prevent running scripts which try to switch |
|
965 | 972 | interactive backends from within ipython. This will just crash |
|
966 | 973 | the python interpreter, so we can't allow it (but a detailed error |
|
967 | 974 | is given to the user). |
|
968 | 975 | |
|
969 | 976 | 2004-09-28 Fernando Perez <fperez@colorado.edu> |
|
970 | 977 | |
|
971 | 978 | * IPython/Shell.py (MatplotlibShellBase.mplot_exec): |
|
972 | 979 | matplotlib-related fixes so that using @run with non-matplotlib |
|
973 | 980 | scripts doesn't pop up spurious plot windows. This requires |
|
974 | 981 | matplotlib >= 0.63, where I had to make some changes as well. |
|
975 | 982 | |
|
976 | 983 | * IPython/ipmaker.py (make_IPython): update version requirement to |
|
977 | 984 | python 2.2. |
|
978 | 985 | |
|
979 | 986 | * IPython/iplib.py (InteractiveShell.mainloop): Add an optional |
|
980 | 987 | banner arg for embedded customization. |
|
981 | 988 | |
|
982 | 989 | * IPython/Magic.py (Magic.__init__): big cleanup to remove all |
|
983 | 990 | explicit uses of __IP as the IPython's instance name. Now things |
|
984 | 991 | are properly handled via the shell.name value. The actual code |
|
985 | 992 | is a bit ugly b/c I'm doing it via a global in Magic.py, but this |
|
986 | 993 | is much better than before. I'll clean things completely when the |
|
987 | 994 | magic stuff gets a real overhaul. |
|
988 | 995 | |
|
989 | 996 | * ipython.1: small fixes, sent in by Jack Moffit. He also sent in |
|
990 | 997 | minor changes to debian dir. |
|
991 | 998 | |
|
992 | 999 | * IPython/iplib.py (InteractiveShell.__init__): Fix adding a |
|
993 | 1000 | pointer to the shell itself in the interactive namespace even when |
|
994 | 1001 | a user-supplied dict is provided. This is needed for embedding |
|
995 | 1002 | purposes (found by tests with Michel Sanner). |
|
996 | 1003 | |
|
997 | 1004 | 2004-09-27 Fernando Perez <fperez@colorado.edu> |
|
998 | 1005 | |
|
999 | 1006 | * IPython/UserConfig/ipythonrc: remove []{} from |
|
1000 | 1007 | readline_remove_delims, so that things like [modname.<TAB> do |
|
1001 | 1008 | proper completion. This disables [].TAB, but that's a less common |
|
1002 | 1009 | case than module names in list comprehensions, for example. |
|
1003 | 1010 | Thanks to a report by Andrea Riciputi. |
|
1004 | 1011 | |
|
1005 | 1012 | 2004-09-09 Fernando Perez <fperez@colorado.edu> |
|
1006 | 1013 | |
|
1007 | 1014 | * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid |
|
1008 | 1015 | blocking problems in win32 and osx. Fix by John. |
|
1009 | 1016 | |
|
1010 | 1017 | 2004-09-08 Fernando Perez <fperez@colorado.edu> |
|
1011 | 1018 | |
|
1012 | 1019 | * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug |
|
1013 | 1020 | for Win32 and OSX. Fix by John Hunter. |
|
1014 | 1021 | |
|
1015 | 1022 | 2004-08-30 *** Released version 0.6.3 |
|
1016 | 1023 | |
|
1017 | 1024 | 2004-08-30 Fernando Perez <fperez@colorado.edu> |
|
1018 | 1025 | |
|
1019 | 1026 | * setup.py (isfile): Add manpages to list of dependent files to be |
|
1020 | 1027 | updated. |
|
1021 | 1028 | |
|
1022 | 1029 | 2004-08-27 Fernando Perez <fperez@colorado.edu> |
|
1023 | 1030 | |
|
1024 | 1031 | * IPython/Shell.py (start): I've disabled -wthread and -gthread |
|
1025 | 1032 | for now. They don't really work with standalone WX/GTK code |
|
1026 | 1033 | (though matplotlib IS working fine with both of those backends). |
|
1027 | 1034 | This will neeed much more testing. I disabled most things with |
|
1028 | 1035 | comments, so turning it back on later should be pretty easy. |
|
1029 | 1036 | |
|
1030 | 1037 | * IPython/iplib.py (InteractiveShell.__init__): Fix accidental |
|
1031 | 1038 | autocalling of expressions like r'foo', by modifying the line |
|
1032 | 1039 | split regexp. Closes |
|
1033 | 1040 | http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas |
|
1034 | 1041 | Riley <ipythonbugs-AT-sabi.net>. |
|
1035 | 1042 | (InteractiveShell.mainloop): honor --nobanner with banner |
|
1036 | 1043 | extensions. |
|
1037 | 1044 | |
|
1038 | 1045 | * IPython/Shell.py: Significant refactoring of all classes, so |
|
1039 | 1046 | that we can really support ALL matplotlib backends and threading |
|
1040 | 1047 | models (John spotted a bug with Tk which required this). Now we |
|
1041 | 1048 | should support single-threaded, WX-threads and GTK-threads, both |
|
1042 | 1049 | for generic code and for matplotlib. |
|
1043 | 1050 | |
|
1044 | 1051 | * IPython/ipmaker.py (__call__): Changed -mpthread option to |
|
1045 | 1052 | -pylab, to simplify things for users. Will also remove the pylab |
|
1046 | 1053 | profile, since now all of matplotlib configuration is directly |
|
1047 | 1054 | handled here. This also reduces startup time. |
|
1048 | 1055 | |
|
1049 | 1056 | * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of |
|
1050 | 1057 | shell wasn't being correctly called. Also in IPShellWX. |
|
1051 | 1058 | |
|
1052 | 1059 | * IPython/iplib.py (InteractiveShell.__init__): Added option to |
|
1053 | 1060 | fine-tune banner. |
|
1054 | 1061 | |
|
1055 | 1062 | * IPython/numutils.py (spike): Deprecate these spike functions, |
|
1056 | 1063 | delete (long deprecated) gnuplot_exec handler. |
|
1057 | 1064 | |
|
1058 | 1065 | 2004-08-26 Fernando Perez <fperez@colorado.edu> |
|
1059 | 1066 | |
|
1060 | 1067 | * ipython.1: Update for threading options, plus some others which |
|
1061 | 1068 | were missing. |
|
1062 | 1069 | |
|
1063 | 1070 | * IPython/ipmaker.py (__call__): Added -wthread option for |
|
1064 | 1071 | wxpython thread handling. Make sure threading options are only |
|
1065 | 1072 | valid at the command line. |
|
1066 | 1073 | |
|
1067 | 1074 | * scripts/ipython: moved shell selection into a factory function |
|
1068 | 1075 | in Shell.py, to keep the starter script to a minimum. |
|
1069 | 1076 | |
|
1070 | 1077 | 2004-08-25 Fernando Perez <fperez@colorado.edu> |
|
1071 | 1078 | |
|
1072 | 1079 | * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by |
|
1073 | 1080 | John. Along with some recent changes he made to matplotlib, the |
|
1074 | 1081 | next versions of both systems should work very well together. |
|
1075 | 1082 | |
|
1076 | 1083 | 2004-08-24 Fernando Perez <fperez@colorado.edu> |
|
1077 | 1084 | |
|
1078 | 1085 | * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I |
|
1079 | 1086 | tried to switch the profiling to using hotshot, but I'm getting |
|
1080 | 1087 | strange errors from prof.runctx() there. I may be misreading the |
|
1081 | 1088 | docs, but it looks weird. For now the profiling code will |
|
1082 | 1089 | continue to use the standard profiler. |
|
1083 | 1090 | |
|
1084 | 1091 | 2004-08-23 Fernando Perez <fperez@colorado.edu> |
|
1085 | 1092 | |
|
1086 | 1093 | * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX |
|
1087 | 1094 | threaded shell, by John Hunter. It's not quite ready yet, but |
|
1088 | 1095 | close. |
|
1089 | 1096 | |
|
1090 | 1097 | 2004-08-22 Fernando Perez <fperez@colorado.edu> |
|
1091 | 1098 | |
|
1092 | 1099 | * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also |
|
1093 | 1100 | in Magic and ultraTB. |
|
1094 | 1101 | |
|
1095 | 1102 | * ipython.1: document threading options in manpage. |
|
1096 | 1103 | |
|
1097 | 1104 | * scripts/ipython: Changed name of -thread option to -gthread, |
|
1098 | 1105 | since this is GTK specific. I want to leave the door open for a |
|
1099 | 1106 | -wthread option for WX, which will most likely be necessary. This |
|
1100 | 1107 | change affects usage and ipmaker as well. |
|
1101 | 1108 | |
|
1102 | 1109 | * IPython/Shell.py (matplotlib_shell): Add a factory function to |
|
1103 | 1110 | handle the matplotlib shell issues. Code by John Hunter |
|
1104 | 1111 | <jdhunter-AT-nitace.bsd.uchicago.edu>. |
|
1105 | 1112 | (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's |
|
1106 | 1113 | broken (and disabled for end users) for now, but it puts the |
|
1107 | 1114 | infrastructure in place. |
|
1108 | 1115 | |
|
1109 | 1116 | 2004-08-21 Fernando Perez <fperez@colorado.edu> |
|
1110 | 1117 | |
|
1111 | 1118 | * ipythonrc-pylab: Add matplotlib support. |
|
1112 | 1119 | |
|
1113 | 1120 | * matplotlib_config.py: new files for matplotlib support, part of |
|
1114 | 1121 | the pylab profile. |
|
1115 | 1122 | |
|
1116 | 1123 | * IPython/usage.py (__doc__): documented the threading options. |
|
1117 | 1124 | |
|
1118 | 1125 | 2004-08-20 Fernando Perez <fperez@colorado.edu> |
|
1119 | 1126 | |
|
1120 | 1127 | * ipython: Modified the main calling routine to handle the -thread |
|
1121 | 1128 | and -mpthread options. This needs to be done as a top-level hack, |
|
1122 | 1129 | because it determines which class to instantiate for IPython |
|
1123 | 1130 | itself. |
|
1124 | 1131 | |
|
1125 | 1132 | * IPython/Shell.py (MTInteractiveShell.__init__): New set of |
|
1126 | 1133 | classes to support multithreaded GTK operation without blocking, |
|
1127 | 1134 | and matplotlib with all backends. This is a lot of still very |
|
1128 | 1135 | experimental code, and threads are tricky. So it may still have a |
|
1129 | 1136 | few rough edges... This code owes a lot to |
|
1130 | 1137 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by |
|
1131 | 1138 | Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and |
|
1132 | 1139 | to John Hunter for all the matplotlib work. |
|
1133 | 1140 | |
|
1134 | 1141 | * IPython/ipmaker.py (__call__): Added -thread and -mpthread |
|
1135 | 1142 | options for gtk thread and matplotlib support. |
|
1136 | 1143 | |
|
1137 | 1144 | 2004-08-16 Fernando Perez <fperez@colorado.edu> |
|
1138 | 1145 | |
|
1139 | 1146 | * IPython/iplib.py (InteractiveShell.__init__): don't trigger |
|
1140 | 1147 | autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug |
|
1141 | 1148 | reported by Stephen Walton <stephen.walton-AT-csun.edu>. |
|
1142 | 1149 | |
|
1143 | 1150 | 2004-08-11 Fernando Perez <fperez@colorado.edu> |
|
1144 | 1151 | |
|
1145 | 1152 | * setup.py (isfile): Fix build so documentation gets updated for |
|
1146 | 1153 | rpms (it was only done for .tgz builds). |
|
1147 | 1154 | |
|
1148 | 1155 | 2004-08-10 Fernando Perez <fperez@colorado.edu> |
|
1149 | 1156 | |
|
1150 | 1157 | * genutils.py (Term): Fix misspell of stdin stream (sin->cin). |
|
1151 | 1158 | |
|
1152 | 1159 | * iplib.py : Silence syntax error exceptions in tab-completion. |
|
1153 | 1160 | |
|
1154 | 1161 | 2004-08-05 Fernando Perez <fperez@colorado.edu> |
|
1155 | 1162 | |
|
1156 | 1163 | * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set |
|
1157 | 1164 | 'color off' mark for continuation prompts. This was causing long |
|
1158 | 1165 | continuation lines to mis-wrap. |
|
1159 | 1166 | |
|
1160 | 1167 | 2004-08-01 Fernando Perez <fperez@colorado.edu> |
|
1161 | 1168 | |
|
1162 | 1169 | * IPython/ipmaker.py (make_IPython): Allow the shell class used |
|
1163 | 1170 | for building ipython to be a parameter. All this is necessary |
|
1164 | 1171 | right now to have a multithreaded version, but this insane |
|
1165 | 1172 | non-design will be cleaned up soon. For now, it's a hack that |
|
1166 | 1173 | works. |
|
1167 | 1174 | |
|
1168 | 1175 | * IPython/Shell.py (IPShell.__init__): Stop using mutable default |
|
1169 | 1176 | args in various places. No bugs so far, but it's a dangerous |
|
1170 | 1177 | practice. |
|
1171 | 1178 | |
|
1172 | 1179 | 2004-07-31 Fernando Perez <fperez@colorado.edu> |
|
1173 | 1180 | |
|
1174 | 1181 | * IPython/iplib.py (complete): ignore SyntaxError exceptions to |
|
1175 | 1182 | fix completion of files with dots in their names under most |
|
1176 | 1183 | profiles (pysh was OK because the completion order is different). |
|
1177 | 1184 | |
|
1178 | 1185 | 2004-07-27 Fernando Perez <fperez@colorado.edu> |
|
1179 | 1186 | |
|
1180 | 1187 | * IPython/iplib.py (InteractiveShell.__init__): build dict of |
|
1181 | 1188 | keywords manually, b/c the one in keyword.py was removed in python |
|
1182 | 1189 | 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>. |
|
1183 | 1190 | This is NOT a bug under python 2.3 and earlier. |
|
1184 | 1191 | |
|
1185 | 1192 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1186 | 1193 | |
|
1187 | 1194 | * IPython/ultraTB.py (VerboseTB.text): Add another |
|
1188 | 1195 | linecache.checkcache() call to try to prevent inspect.py from |
|
1189 | 1196 | crashing under python 2.3. I think this fixes |
|
1190 | 1197 | http://www.scipy.net/roundup/ipython/issue17. |
|
1191 | 1198 | |
|
1192 | 1199 | 2004-07-26 *** Released version 0.6.2 |
|
1193 | 1200 | |
|
1194 | 1201 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1195 | 1202 | |
|
1196 | 1203 | * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would |
|
1197 | 1204 | fail for any number. |
|
1198 | 1205 | (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for |
|
1199 | 1206 | empty bookmarks. |
|
1200 | 1207 | |
|
1201 | 1208 | 2004-07-26 *** Released version 0.6.1 |
|
1202 | 1209 | |
|
1203 | 1210 | 2004-07-26 Fernando Perez <fperez@colorado.edu> |
|
1204 | 1211 | |
|
1205 | 1212 | * ipython_win_post_install.py (run): Added pysh shortcut for Windows. |
|
1206 | 1213 | |
|
1207 | 1214 | * IPython/iplib.py (protect_filename): Applied Ville's patch for |
|
1208 | 1215 | escaping '()[]{}' in filenames. |
|
1209 | 1216 | |
|
1210 | 1217 | * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for |
|
1211 | 1218 | Python 2.2 users who lack a proper shlex.split. |
|
1212 | 1219 | |
|
1213 | 1220 | 2004-07-19 Fernando Perez <fperez@colorado.edu> |
|
1214 | 1221 | |
|
1215 | 1222 | * IPython/iplib.py (InteractiveShell.init_readline): Add support |
|
1216 | 1223 | for reading readline's init file. I follow the normal chain: |
|
1217 | 1224 | $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a |
|
1218 | 1225 | report by Mike Heeter. This closes |
|
1219 | 1226 | http://www.scipy.net/roundup/ipython/issue16. |
|
1220 | 1227 | |
|
1221 | 1228 | 2004-07-18 Fernando Perez <fperez@colorado.edu> |
|
1222 | 1229 | |
|
1223 | 1230 | * IPython/iplib.py (__init__): Add better handling of '\' under |
|
1224 | 1231 | Win32 for filenames. After a patch by Ville. |
|
1225 | 1232 | |
|
1226 | 1233 | 2004-07-17 Fernando Perez <fperez@colorado.edu> |
|
1227 | 1234 | |
|
1228 | 1235 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1229 | 1236 | autocalling would be triggered for 'foo is bar' if foo is |
|
1230 | 1237 | callable. I also cleaned up the autocall detection code to use a |
|
1231 | 1238 | regexp, which is faster. Bug reported by Alexander Schmolck. |
|
1232 | 1239 | |
|
1233 | 1240 | * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with |
|
1234 | 1241 | '?' in them would confuse the help system. Reported by Alex |
|
1235 | 1242 | Schmolck. |
|
1236 | 1243 | |
|
1237 | 1244 | 2004-07-16 Fernando Perez <fperez@colorado.edu> |
|
1238 | 1245 | |
|
1239 | 1246 | * IPython/GnuplotInteractive.py (__all__): added plot2. |
|
1240 | 1247 | |
|
1241 | 1248 | * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for |
|
1242 | 1249 | plotting dictionaries, lists or tuples of 1d arrays. |
|
1243 | 1250 | |
|
1244 | 1251 | * IPython/Magic.py (Magic.magic_hist): small clenaups and |
|
1245 | 1252 | optimizations. |
|
1246 | 1253 | |
|
1247 | 1254 | * IPython/iplib.py:Remove old Changelog info for cleanup. This is |
|
1248 | 1255 | the information which was there from Janko's original IPP code: |
|
1249 | 1256 | |
|
1250 | 1257 | 03.05.99 20:53 porto.ifm.uni-kiel.de |
|
1251 | 1258 | --Started changelog. |
|
1252 | 1259 | --make clear do what it say it does |
|
1253 | 1260 | --added pretty output of lines from inputcache |
|
1254 | 1261 | --Made Logger a mixin class, simplifies handling of switches |
|
1255 | 1262 | --Added own completer class. .string<TAB> expands to last history |
|
1256 | 1263 | line which starts with string. The new expansion is also present |
|
1257 | 1264 | with Ctrl-r from the readline library. But this shows, who this |
|
1258 | 1265 | can be done for other cases. |
|
1259 | 1266 | --Added convention that all shell functions should accept a |
|
1260 | 1267 | parameter_string This opens the door for different behaviour for |
|
1261 | 1268 | each function. @cd is a good example of this. |
|
1262 | 1269 | |
|
1263 | 1270 | 04.05.99 12:12 porto.ifm.uni-kiel.de |
|
1264 | 1271 | --added logfile rotation |
|
1265 | 1272 | --added new mainloop method which freezes first the namespace |
|
1266 | 1273 | |
|
1267 | 1274 | 07.05.99 21:24 porto.ifm.uni-kiel.de |
|
1268 | 1275 | --added the docreader classes. Now there is a help system. |
|
1269 | 1276 | -This is only a first try. Currently it's not easy to put new |
|
1270 | 1277 | stuff in the indices. But this is the way to go. Info would be |
|
1271 | 1278 | better, but HTML is every where and not everybody has an info |
|
1272 | 1279 | system installed and it's not so easy to change html-docs to info. |
|
1273 | 1280 | --added global logfile option |
|
1274 | 1281 | --there is now a hook for object inspection method pinfo needs to |
|
1275 | 1282 | be provided for this. Can be reached by two '??'. |
|
1276 | 1283 | |
|
1277 | 1284 | 08.05.99 20:51 porto.ifm.uni-kiel.de |
|
1278 | 1285 | --added a README |
|
1279 | 1286 | --bug in rc file. Something has changed so functions in the rc |
|
1280 | 1287 | file need to reference the shell and not self. Not clear if it's a |
|
1281 | 1288 | bug or feature. |
|
1282 | 1289 | --changed rc file for new behavior |
|
1283 | 1290 | |
|
1284 | 1291 | 2004-07-15 Fernando Perez <fperez@colorado.edu> |
|
1285 | 1292 | |
|
1286 | 1293 | * IPython/Logger.py (Logger.log): fixed recent bug where the input |
|
1287 | 1294 | cache was falling out of sync in bizarre manners when multi-line |
|
1288 | 1295 | input was present. Minor optimizations and cleanup. |
|
1289 | 1296 | |
|
1290 | 1297 | (Logger): Remove old Changelog info for cleanup. This is the |
|
1291 | 1298 | information which was there from Janko's original code: |
|
1292 | 1299 | |
|
1293 | 1300 | Changes to Logger: - made the default log filename a parameter |
|
1294 | 1301 | |
|
1295 | 1302 | - put a check for lines beginning with !@? in log(). Needed |
|
1296 | 1303 | (even if the handlers properly log their lines) for mid-session |
|
1297 | 1304 | logging activation to work properly. Without this, lines logged |
|
1298 | 1305 | in mid session, which get read from the cache, would end up |
|
1299 | 1306 | 'bare' (with !@? in the open) in the log. Now they are caught |
|
1300 | 1307 | and prepended with a #. |
|
1301 | 1308 | |
|
1302 | 1309 | * IPython/iplib.py (InteractiveShell.init_readline): added check |
|
1303 | 1310 | in case MagicCompleter fails to be defined, so we don't crash. |
|
1304 | 1311 | |
|
1305 | 1312 | 2004-07-13 Fernando Perez <fperez@colorado.edu> |
|
1306 | 1313 | |
|
1307 | 1314 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation |
|
1308 | 1315 | of EPS if the requested filename ends in '.eps'. |
|
1309 | 1316 | |
|
1310 | 1317 | 2004-07-04 Fernando Perez <fperez@colorado.edu> |
|
1311 | 1318 | |
|
1312 | 1319 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix |
|
1313 | 1320 | escaping of quotes when calling the shell. |
|
1314 | 1321 | |
|
1315 | 1322 | 2004-07-02 Fernando Perez <fperez@colorado.edu> |
|
1316 | 1323 | |
|
1317 | 1324 | * IPython/Prompts.py (CachedOutput.update): Fix problem with |
|
1318 | 1325 | gettext not working because we were clobbering '_'. Fixes |
|
1319 | 1326 | http://www.scipy.net/roundup/ipython/issue6. |
|
1320 | 1327 | |
|
1321 | 1328 | 2004-07-01 Fernando Perez <fperez@colorado.edu> |
|
1322 | 1329 | |
|
1323 | 1330 | * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling |
|
1324 | 1331 | into @cd. Patch by Ville. |
|
1325 | 1332 | |
|
1326 | 1333 | * IPython/iplib.py (InteractiveShell.post_config_initialization): |
|
1327 | 1334 | new function to store things after ipmaker runs. Patch by Ville. |
|
1328 | 1335 | Eventually this will go away once ipmaker is removed and the class |
|
1329 | 1336 | gets cleaned up, but for now it's ok. Key functionality here is |
|
1330 | 1337 | the addition of the persistent storage mechanism, a dict for |
|
1331 | 1338 | keeping data across sessions (for now just bookmarks, but more can |
|
1332 | 1339 | be implemented later). |
|
1333 | 1340 | |
|
1334 | 1341 | * IPython/Magic.py (Magic.magic_bookmark): New bookmark system, |
|
1335 | 1342 | persistent across sections. Patch by Ville, I modified it |
|
1336 | 1343 | soemwhat to allow bookmarking arbitrary dirs other than CWD. Also |
|
1337 | 1344 | added a '-l' option to list all bookmarks. |
|
1338 | 1345 | |
|
1339 | 1346 | * IPython/iplib.py (InteractiveShell.atexit_operations): new |
|
1340 | 1347 | center for cleanup. Registered with atexit.register(). I moved |
|
1341 | 1348 | here the old exit_cleanup(). After a patch by Ville. |
|
1342 | 1349 | |
|
1343 | 1350 | * IPython/Magic.py (get_py_filename): added '~' to the accepted |
|
1344 | 1351 | characters in the hacked shlex_split for python 2.2. |
|
1345 | 1352 | |
|
1346 | 1353 | * IPython/iplib.py (file_matches): more fixes to filenames with |
|
1347 | 1354 | whitespace in them. It's not perfect, but limitations in python's |
|
1348 | 1355 | readline make it impossible to go further. |
|
1349 | 1356 | |
|
1350 | 1357 | 2004-06-29 Fernando Perez <fperez@colorado.edu> |
|
1351 | 1358 | |
|
1352 | 1359 | * IPython/iplib.py (file_matches): escape whitespace correctly in |
|
1353 | 1360 | filename completions. Bug reported by Ville. |
|
1354 | 1361 | |
|
1355 | 1362 | 2004-06-28 Fernando Perez <fperez@colorado.edu> |
|
1356 | 1363 | |
|
1357 | 1364 | * IPython/ipmaker.py (__call__): Added per-profile histories. Now |
|
1358 | 1365 | the history file will be called 'history-PROFNAME' (or just |
|
1359 | 1366 | 'history' if no profile is loaded). I was getting annoyed at |
|
1360 | 1367 | getting my Numerical work history clobbered by pysh sessions. |
|
1361 | 1368 | |
|
1362 | 1369 | * IPython/iplib.py (InteractiveShell.__init__): Internal |
|
1363 | 1370 | getoutputerror() function so that we can honor the system_verbose |
|
1364 | 1371 | flag for _all_ system calls. I also added escaping of # |
|
1365 | 1372 | characters here to avoid confusing Itpl. |
|
1366 | 1373 | |
|
1367 | 1374 | * IPython/Magic.py (shlex_split): removed call to shell in |
|
1368 | 1375 | parse_options and replaced it with shlex.split(). The annoying |
|
1369 | 1376 | part was that in Python 2.2, shlex.split() doesn't exist, so I had |
|
1370 | 1377 | to backport it from 2.3, with several frail hacks (the shlex |
|
1371 | 1378 | module is rather limited in 2.2). Thanks to a suggestion by Ville |
|
1372 | 1379 | Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no |
|
1373 | 1380 | problem. |
|
1374 | 1381 | |
|
1375 | 1382 | (Magic.magic_system_verbose): new toggle to print the actual |
|
1376 | 1383 | system calls made by ipython. Mainly for debugging purposes. |
|
1377 | 1384 | |
|
1378 | 1385 | * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which |
|
1379 | 1386 | doesn't support persistence. Reported (and fix suggested) by |
|
1380 | 1387 | Travis Caldwell <travis_caldwell2000@yahoo.com>. |
|
1381 | 1388 | |
|
1382 | 1389 | 2004-06-26 Fernando Perez <fperez@colorado.edu> |
|
1383 | 1390 | |
|
1384 | 1391 | * IPython/Logger.py (Logger.log): fix to handle correctly empty |
|
1385 | 1392 | continue prompts. |
|
1386 | 1393 | |
|
1387 | 1394 | * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh() |
|
1388 | 1395 | function (basically a big docstring) and a few more things here to |
|
1389 | 1396 | speedup startup. pysh.py is now very lightweight. We want because |
|
1390 | 1397 | it gets execfile'd, while InterpreterExec gets imported, so |
|
1391 | 1398 | byte-compilation saves time. |
|
1392 | 1399 | |
|
1393 | 1400 | 2004-06-25 Fernando Perez <fperez@colorado.edu> |
|
1394 | 1401 | |
|
1395 | 1402 | * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd |
|
1396 | 1403 | -NUM', which was recently broken. |
|
1397 | 1404 | |
|
1398 | 1405 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow ! |
|
1399 | 1406 | in multi-line input (but not !!, which doesn't make sense there). |
|
1400 | 1407 | |
|
1401 | 1408 | * IPython/UserConfig/ipythonrc: made autoindent on by default. |
|
1402 | 1409 | It's just too useful, and people can turn it off in the less |
|
1403 | 1410 | common cases where it's a problem. |
|
1404 | 1411 | |
|
1405 | 1412 | 2004-06-24 Fernando Perez <fperez@colorado.edu> |
|
1406 | 1413 | |
|
1407 | 1414 | * IPython/iplib.py (InteractiveShell._prefilter): big change - |
|
1408 | 1415 | special syntaxes (like alias calling) is now allied in multi-line |
|
1409 | 1416 | input. This is still _very_ experimental, but it's necessary for |
|
1410 | 1417 | efficient shell usage combining python looping syntax with system |
|
1411 | 1418 | calls. For now it's restricted to aliases, I don't think it |
|
1412 | 1419 | really even makes sense to have this for magics. |
|
1413 | 1420 | |
|
1414 | 1421 | 2004-06-23 Fernando Perez <fperez@colorado.edu> |
|
1415 | 1422 | |
|
1416 | 1423 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added |
|
1417 | 1424 | $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd. |
|
1418 | 1425 | |
|
1419 | 1426 | * IPython/Magic.py (Magic.magic_rehashx): modified to handle |
|
1420 | 1427 | extensions under Windows (after code sent by Gary Bishop). The |
|
1421 | 1428 | extensions considered 'executable' are stored in IPython's rc |
|
1422 | 1429 | structure as win_exec_ext. |
|
1423 | 1430 | |
|
1424 | 1431 | * IPython/genutils.py (shell): new function, like system() but |
|
1425 | 1432 | without return value. Very useful for interactive shell work. |
|
1426 | 1433 | |
|
1427 | 1434 | * IPython/Magic.py (Magic.magic_unalias): New @unalias function to |
|
1428 | 1435 | delete aliases. |
|
1429 | 1436 | |
|
1430 | 1437 | * IPython/iplib.py (InteractiveShell.alias_table_update): make |
|
1431 | 1438 | sure that the alias table doesn't contain python keywords. |
|
1432 | 1439 | |
|
1433 | 1440 | 2004-06-21 Fernando Perez <fperez@colorado.edu> |
|
1434 | 1441 | |
|
1435 | 1442 | * IPython/Magic.py (Magic.magic_rehash): Fix crash when |
|
1436 | 1443 | non-existent items are found in $PATH. Reported by Thorsten. |
|
1437 | 1444 | |
|
1438 | 1445 | 2004-06-20 Fernando Perez <fperez@colorado.edu> |
|
1439 | 1446 | |
|
1440 | 1447 | * IPython/iplib.py (complete): modified the completer so that the |
|
1441 | 1448 | order of priorities can be easily changed at runtime. |
|
1442 | 1449 | |
|
1443 | 1450 | * IPython/Extensions/InterpreterExec.py (prefilter_shell): |
|
1444 | 1451 | Modified to auto-execute all lines beginning with '~', '/' or '.'. |
|
1445 | 1452 | |
|
1446 | 1453 | * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to |
|
1447 | 1454 | expand Python variables prepended with $ in all system calls. The |
|
1448 | 1455 | same was done to InteractiveShell.handle_shell_escape. Now all |
|
1449 | 1456 | system access mechanisms (!, !!, @sc, @sx and aliases) allow the |
|
1450 | 1457 | expansion of python variables and expressions according to the |
|
1451 | 1458 | syntax of PEP-215 - http://www.python.org/peps/pep-0215.html. |
|
1452 | 1459 | |
|
1453 | 1460 | Though PEP-215 has been rejected, a similar (but simpler) one |
|
1454 | 1461 | seems like it will go into Python 2.4, PEP-292 - |
|
1455 | 1462 | http://www.python.org/peps/pep-0292.html. |
|
1456 | 1463 | |
|
1457 | 1464 | I'll keep the full syntax of PEP-215, since IPython has since the |
|
1458 | 1465 | start used Ka-Ping Yee's reference implementation discussed there |
|
1459 | 1466 | (Itpl), and I actually like the powerful semantics it offers. |
|
1460 | 1467 | |
|
1461 | 1468 | In order to access normal shell variables, the $ has to be escaped |
|
1462 | 1469 | via an extra $. For example: |
|
1463 | 1470 | |
|
1464 | 1471 | In [7]: PATH='a python variable' |
|
1465 | 1472 | |
|
1466 | 1473 | In [8]: !echo $PATH |
|
1467 | 1474 | a python variable |
|
1468 | 1475 | |
|
1469 | 1476 | In [9]: !echo $$PATH |
|
1470 | 1477 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
1471 | 1478 | |
|
1472 | 1479 | (Magic.parse_options): escape $ so the shell doesn't evaluate |
|
1473 | 1480 | things prematurely. |
|
1474 | 1481 | |
|
1475 | 1482 | * IPython/iplib.py (InteractiveShell.call_alias): added the |
|
1476 | 1483 | ability for aliases to expand python variables via $. |
|
1477 | 1484 | |
|
1478 | 1485 | * IPython/Magic.py (Magic.magic_rehash): based on the new alias |
|
1479 | 1486 | system, now there's a @rehash/@rehashx pair of magics. These work |
|
1480 | 1487 | like the csh rehash command, and can be invoked at any time. They |
|
1481 | 1488 | build a table of aliases to everything in the user's $PATH |
|
1482 | 1489 | (@rehash uses everything, @rehashx is slower but only adds |
|
1483 | 1490 | executable files). With this, the pysh.py-based shell profile can |
|
1484 | 1491 | now simply call rehash upon startup, and full access to all |
|
1485 | 1492 | programs in the user's path is obtained. |
|
1486 | 1493 | |
|
1487 | 1494 | * IPython/iplib.py (InteractiveShell.call_alias): The new alias |
|
1488 | 1495 | functionality is now fully in place. I removed the old dynamic |
|
1489 | 1496 | code generation based approach, in favor of a much lighter one |
|
1490 | 1497 | based on a simple dict. The advantage is that this allows me to |
|
1491 | 1498 | now have thousands of aliases with negligible cost (unthinkable |
|
1492 | 1499 | with the old system). |
|
1493 | 1500 | |
|
1494 | 1501 | 2004-06-19 Fernando Perez <fperez@colorado.edu> |
|
1495 | 1502 | |
|
1496 | 1503 | * IPython/iplib.py (__init__): extended MagicCompleter class to |
|
1497 | 1504 | also complete (last in priority) on user aliases. |
|
1498 | 1505 | |
|
1499 | 1506 | * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in |
|
1500 | 1507 | call to eval. |
|
1501 | 1508 | (ItplNS.__init__): Added a new class which functions like Itpl, |
|
1502 | 1509 | but allows configuring the namespace for the evaluation to occur |
|
1503 | 1510 | in. |
|
1504 | 1511 | |
|
1505 | 1512 | 2004-06-18 Fernando Perez <fperez@colorado.edu> |
|
1506 | 1513 | |
|
1507 | 1514 | * IPython/iplib.py (InteractiveShell.runcode): modify to print a |
|
1508 | 1515 | better message when 'exit' or 'quit' are typed (a common newbie |
|
1509 | 1516 | confusion). |
|
1510 | 1517 | |
|
1511 | 1518 | * IPython/Magic.py (Magic.magic_colors): Added the runtime color |
|
1512 | 1519 | check for Windows users. |
|
1513 | 1520 | |
|
1514 | 1521 | * IPython/iplib.py (InteractiveShell.user_setup): removed |
|
1515 | 1522 | disabling of colors for Windows. I'll test at runtime and issue a |
|
1516 | 1523 | warning if Gary's readline isn't found, as to nudge users to |
|
1517 | 1524 | download it. |
|
1518 | 1525 | |
|
1519 | 1526 | 2004-06-16 Fernando Perez <fperez@colorado.edu> |
|
1520 | 1527 | |
|
1521 | 1528 | * IPython/genutils.py (Stream.__init__): changed to print errors |
|
1522 | 1529 | to sys.stderr. I had a circular dependency here. Now it's |
|
1523 | 1530 | possible to run ipython as IDLE's shell (consider this pre-alpha, |
|
1524 | 1531 | since true stdout things end up in the starting terminal instead |
|
1525 | 1532 | of IDLE's out). |
|
1526 | 1533 | |
|
1527 | 1534 | * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for |
|
1528 | 1535 | users who haven't # updated their prompt_in2 definitions. Remove |
|
1529 | 1536 | eventually. |
|
1530 | 1537 | (multiple_replace): added credit to original ASPN recipe. |
|
1531 | 1538 | |
|
1532 | 1539 | 2004-06-15 Fernando Perez <fperez@colorado.edu> |
|
1533 | 1540 | |
|
1534 | 1541 | * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the |
|
1535 | 1542 | list of auto-defined aliases. |
|
1536 | 1543 | |
|
1537 | 1544 | 2004-06-13 Fernando Perez <fperez@colorado.edu> |
|
1538 | 1545 | |
|
1539 | 1546 | * setup.py (scriptfiles): Don't trigger win_post_install unless an |
|
1540 | 1547 | install was really requested (so setup.py can be used for other |
|
1541 | 1548 | things under Windows). |
|
1542 | 1549 | |
|
1543 | 1550 | 2004-06-10 Fernando Perez <fperez@colorado.edu> |
|
1544 | 1551 | |
|
1545 | 1552 | * IPython/Logger.py (Logger.create_log): Manually remove any old |
|
1546 | 1553 | backup, since os.remove may fail under Windows. Fixes bug |
|
1547 | 1554 | reported by Thorsten. |
|
1548 | 1555 | |
|
1549 | 1556 | 2004-06-09 Fernando Perez <fperez@colorado.edu> |
|
1550 | 1557 | |
|
1551 | 1558 | * examples/example-embed.py: fixed all references to %n (replaced |
|
1552 | 1559 | with \\# for ps1/out prompts and with \\D for ps2 prompts). Done |
|
1553 | 1560 | for all examples and the manual as well. |
|
1554 | 1561 | |
|
1555 | 1562 | 2004-06-08 Fernando Perez <fperez@colorado.edu> |
|
1556 | 1563 | |
|
1557 | 1564 | * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt |
|
1558 | 1565 | alignment and color management. All 3 prompt subsystems now |
|
1559 | 1566 | inherit from BasePrompt. |
|
1560 | 1567 | |
|
1561 | 1568 | * tools/release: updates for windows installer build and tag rpms |
|
1562 | 1569 | with python version (since paths are fixed). |
|
1563 | 1570 | |
|
1564 | 1571 | * IPython/UserConfig/ipythonrc: modified to use \# instead of %n, |
|
1565 | 1572 | which will become eventually obsolete. Also fixed the default |
|
1566 | 1573 | prompt_in2 to use \D, so at least new users start with the correct |
|
1567 | 1574 | defaults. |
|
1568 | 1575 | WARNING: Users with existing ipythonrc files will need to apply |
|
1569 | 1576 | this fix manually! |
|
1570 | 1577 | |
|
1571 | 1578 | * setup.py: make windows installer (.exe). This is finally the |
|
1572 | 1579 | integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>, |
|
1573 | 1580 | which I hadn't included because it required Python 2.3 (or recent |
|
1574 | 1581 | distutils). |
|
1575 | 1582 | |
|
1576 | 1583 | * IPython/usage.py (__doc__): update docs (and manpage) to reflect |
|
1577 | 1584 | usage of new '\D' escape. |
|
1578 | 1585 | |
|
1579 | 1586 | * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which |
|
1580 | 1587 | lacks os.getuid()) |
|
1581 | 1588 | (CachedOutput.set_colors): Added the ability to turn coloring |
|
1582 | 1589 | on/off with @colors even for manually defined prompt colors. It |
|
1583 | 1590 | uses a nasty global, but it works safely and via the generic color |
|
1584 | 1591 | handling mechanism. |
|
1585 | 1592 | (Prompt2.__init__): Introduced new escape '\D' for continuation |
|
1586 | 1593 | prompts. It represents the counter ('\#') as dots. |
|
1587 | 1594 | *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will |
|
1588 | 1595 | need to update their ipythonrc files and replace '%n' with '\D' in |
|
1589 | 1596 | their prompt_in2 settings everywhere. Sorry, but there's |
|
1590 | 1597 | otherwise no clean way to get all prompts to properly align. The |
|
1591 | 1598 | ipythonrc shipped with IPython has been updated. |
|
1592 | 1599 | |
|
1593 | 1600 | 2004-06-07 Fernando Perez <fperez@colorado.edu> |
|
1594 | 1601 | |
|
1595 | 1602 | * setup.py (isfile): Pass local_icons option to latex2html, so the |
|
1596 | 1603 | resulting HTML file is self-contained. Thanks to |
|
1597 | 1604 | dryice-AT-liu.com.cn for the tip. |
|
1598 | 1605 | |
|
1599 | 1606 | * pysh.py: I created a new profile 'shell', which implements a |
|
1600 | 1607 | _rudimentary_ IPython-based shell. This is in NO WAY a realy |
|
1601 | 1608 | system shell, nor will it become one anytime soon. It's mainly |
|
1602 | 1609 | meant to illustrate the use of the new flexible bash-like prompts. |
|
1603 | 1610 | I guess it could be used by hardy souls for true shell management, |
|
1604 | 1611 | but it's no tcsh/bash... pysh.py is loaded by the 'shell' |
|
1605 | 1612 | profile. This uses the InterpreterExec extension provided by |
|
1606 | 1613 | W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl> |
|
1607 | 1614 | |
|
1608 | 1615 | * IPython/Prompts.py (PromptOut.__str__): now it will correctly |
|
1609 | 1616 | auto-align itself with the length of the previous input prompt |
|
1610 | 1617 | (taking into account the invisible color escapes). |
|
1611 | 1618 | (CachedOutput.__init__): Large restructuring of this class. Now |
|
1612 | 1619 | all three prompts (primary1, primary2, output) are proper objects, |
|
1613 | 1620 | managed by the 'parent' CachedOutput class. The code is still a |
|
1614 | 1621 | bit hackish (all prompts share state via a pointer to the cache), |
|
1615 | 1622 | but it's overall far cleaner than before. |
|
1616 | 1623 | |
|
1617 | 1624 | * IPython/genutils.py (getoutputerror): modified to add verbose, |
|
1618 | 1625 | debug and header options. This makes the interface of all getout* |
|
1619 | 1626 | functions uniform. |
|
1620 | 1627 | (SystemExec.getoutputerror): added getoutputerror to SystemExec. |
|
1621 | 1628 | |
|
1622 | 1629 | * IPython/Magic.py (Magic.default_option): added a function to |
|
1623 | 1630 | allow registering default options for any magic command. This |
|
1624 | 1631 | makes it easy to have profiles which customize the magics globally |
|
1625 | 1632 | for a certain use. The values set through this function are |
|
1626 | 1633 | picked up by the parse_options() method, which all magics should |
|
1627 | 1634 | use to parse their options. |
|
1628 | 1635 | |
|
1629 | 1636 | * IPython/genutils.py (warn): modified the warnings framework to |
|
1630 | 1637 | use the Term I/O class. I'm trying to slowly unify all of |
|
1631 | 1638 | IPython's I/O operations to pass through Term. |
|
1632 | 1639 | |
|
1633 | 1640 | * IPython/Prompts.py (Prompt2._str_other): Added functionality in |
|
1634 | 1641 | the secondary prompt to correctly match the length of the primary |
|
1635 | 1642 | one for any prompt. Now multi-line code will properly line up |
|
1636 | 1643 | even for path dependent prompts, such as the new ones available |
|
1637 | 1644 | via the prompt_specials. |
|
1638 | 1645 | |
|
1639 | 1646 | 2004-06-06 Fernando Perez <fperez@colorado.edu> |
|
1640 | 1647 | |
|
1641 | 1648 | * IPython/Prompts.py (prompt_specials): Added the ability to have |
|
1642 | 1649 | bash-like special sequences in the prompts, which get |
|
1643 | 1650 | automatically expanded. Things like hostname, current working |
|
1644 | 1651 | directory and username are implemented already, but it's easy to |
|
1645 | 1652 | add more in the future. Thanks to a patch by W.J. van der Laan |
|
1646 | 1653 | <gnufnork-AT-hetdigitalegat.nl> |
|
1647 | 1654 | (prompt_specials): Added color support for prompt strings, so |
|
1648 | 1655 | users can define arbitrary color setups for their prompts. |
|
1649 | 1656 | |
|
1650 | 1657 | 2004-06-05 Fernando Perez <fperez@colorado.edu> |
|
1651 | 1658 | |
|
1652 | 1659 | * IPython/genutils.py (Term.reopen_all): Added Windows-specific |
|
1653 | 1660 | code to load Gary Bishop's readline and configure it |
|
1654 | 1661 | automatically. Thanks to Gary for help on this. |
|
1655 | 1662 | |
|
1656 | 1663 | 2004-06-01 Fernando Perez <fperez@colorado.edu> |
|
1657 | 1664 | |
|
1658 | 1665 | * IPython/Logger.py (Logger.create_log): fix bug for logging |
|
1659 | 1666 | with no filename (previous fix was incomplete). |
|
1660 | 1667 | |
|
1661 | 1668 | 2004-05-25 Fernando Perez <fperez@colorado.edu> |
|
1662 | 1669 | |
|
1663 | 1670 | * IPython/Magic.py (Magic.parse_options): fix bug where naked |
|
1664 | 1671 | parens would get passed to the shell. |
|
1665 | 1672 | |
|
1666 | 1673 | 2004-05-20 Fernando Perez <fperez@colorado.edu> |
|
1667 | 1674 | |
|
1668 | 1675 | * IPython/Magic.py (Magic.magic_prun): changed default profile |
|
1669 | 1676 | sort order to 'time' (the more common profiling need). |
|
1670 | 1677 | |
|
1671 | 1678 | * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache |
|
1672 | 1679 | so that source code shown is guaranteed in sync with the file on |
|
1673 | 1680 | disk (also changed in psource). Similar fix to the one for |
|
1674 | 1681 | ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du |
|
1675 | 1682 | <yann.ledu-AT-noos.fr>. |
|
1676 | 1683 | |
|
1677 | 1684 | * IPython/Magic.py (Magic.parse_options): Fixed bug where commands |
|
1678 | 1685 | with a single option would not be correctly parsed. Closes |
|
1679 | 1686 | http://www.scipy.net/roundup/ipython/issue14. This bug had been |
|
1680 | 1687 | introduced in 0.6.0 (on 2004-05-06). |
|
1681 | 1688 | |
|
1682 | 1689 | 2004-05-13 *** Released version 0.6.0 |
|
1683 | 1690 | |
|
1684 | 1691 | 2004-05-13 Fernando Perez <fperez@colorado.edu> |
|
1685 | 1692 | |
|
1686 | 1693 | * debian/: Added debian/ directory to CVS, so that debian support |
|
1687 | 1694 | is publicly accessible. The debian package is maintained by Jack |
|
1688 | 1695 | Moffit <jack-AT-xiph.org>. |
|
1689 | 1696 | |
|
1690 | 1697 | * Documentation: included the notes about an ipython-based system |
|
1691 | 1698 | shell (the hypothetical 'pysh') into the new_design.pdf document, |
|
1692 | 1699 | so that these ideas get distributed to users along with the |
|
1693 | 1700 | official documentation. |
|
1694 | 1701 | |
|
1695 | 1702 | 2004-05-10 Fernando Perez <fperez@colorado.edu> |
|
1696 | 1703 | |
|
1697 | 1704 | * IPython/Logger.py (Logger.create_log): fix recently introduced |
|
1698 | 1705 | bug (misindented line) where logstart would fail when not given an |
|
1699 | 1706 | explicit filename. |
|
1700 | 1707 | |
|
1701 | 1708 | 2004-05-09 Fernando Perez <fperez@colorado.edu> |
|
1702 | 1709 | |
|
1703 | 1710 | * IPython/Magic.py (Magic.parse_options): skip system call when |
|
1704 | 1711 | there are no options to look for. Faster, cleaner for the common |
|
1705 | 1712 | case. |
|
1706 | 1713 | |
|
1707 | 1714 | * Documentation: many updates to the manual: describing Windows |
|
1708 | 1715 | support better, Gnuplot updates, credits, misc small stuff. Also |
|
1709 | 1716 | updated the new_design doc a bit. |
|
1710 | 1717 | |
|
1711 | 1718 | 2004-05-06 *** Released version 0.6.0.rc1 |
|
1712 | 1719 | |
|
1713 | 1720 | 2004-05-06 Fernando Perez <fperez@colorado.edu> |
|
1714 | 1721 | |
|
1715 | 1722 | * IPython/ultraTB.py (ListTB.text): modified a ton of string += |
|
1716 | 1723 | operations to use the vastly more efficient list/''.join() method. |
|
1717 | 1724 | (FormattedTB.text): Fix |
|
1718 | 1725 | http://www.scipy.net/roundup/ipython/issue12 - exception source |
|
1719 | 1726 | extract not updated after reload. Thanks to Mike Salib |
|
1720 | 1727 | <msalib-AT-mit.edu> for pinning the source of the problem. |
|
1721 | 1728 | Fortunately, the solution works inside ipython and doesn't require |
|
1722 | 1729 | any changes to python proper. |
|
1723 | 1730 | |
|
1724 | 1731 | * IPython/Magic.py (Magic.parse_options): Improved to process the |
|
1725 | 1732 | argument list as a true shell would (by actually using the |
|
1726 | 1733 | underlying system shell). This way, all @magics automatically get |
|
1727 | 1734 | shell expansion for variables. Thanks to a comment by Alex |
|
1728 | 1735 | Schmolck. |
|
1729 | 1736 | |
|
1730 | 1737 | 2004-04-04 Fernando Perez <fperez@colorado.edu> |
|
1731 | 1738 | |
|
1732 | 1739 | * IPython/iplib.py (InteractiveShell.interact): Added a special |
|
1733 | 1740 | trap for a debugger quit exception, which is basically impossible |
|
1734 | 1741 | to handle by normal mechanisms, given what pdb does to the stack. |
|
1735 | 1742 | This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>. |
|
1736 | 1743 | |
|
1737 | 1744 | 2004-04-03 Fernando Perez <fperez@colorado.edu> |
|
1738 | 1745 | |
|
1739 | 1746 | * IPython/genutils.py (Term): Standardized the names of the Term |
|
1740 | 1747 | class streams to cin/cout/cerr, following C++ naming conventions |
|
1741 | 1748 | (I can't use in/out/err because 'in' is not a valid attribute |
|
1742 | 1749 | name). |
|
1743 | 1750 | |
|
1744 | 1751 | * IPython/iplib.py (InteractiveShell.interact): don't increment |
|
1745 | 1752 | the prompt if there's no user input. By Daniel 'Dang' Griffith |
|
1746 | 1753 | <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from |
|
1747 | 1754 | Francois Pinard. |
|
1748 | 1755 | |
|
1749 | 1756 | 2004-04-02 Fernando Perez <fperez@colorado.edu> |
|
1750 | 1757 | |
|
1751 | 1758 | * IPython/genutils.py (Stream.__init__): Modified to survive at |
|
1752 | 1759 | least importing in contexts where stdin/out/err aren't true file |
|
1753 | 1760 | objects, such as PyCrust (they lack fileno() and mode). However, |
|
1754 | 1761 | the recovery facilities which rely on these things existing will |
|
1755 | 1762 | not work. |
|
1756 | 1763 | |
|
1757 | 1764 | 2004-04-01 Fernando Perez <fperez@colorado.edu> |
|
1758 | 1765 | |
|
1759 | 1766 | * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to |
|
1760 | 1767 | use the new getoutputerror() function, so it properly |
|
1761 | 1768 | distinguishes stdout/err. |
|
1762 | 1769 | |
|
1763 | 1770 | * IPython/genutils.py (getoutputerror): added a function to |
|
1764 | 1771 | capture separately the standard output and error of a command. |
|
1765 | 1772 | After a comment from dang on the mailing lists. This code is |
|
1766 | 1773 | basically a modified version of commands.getstatusoutput(), from |
|
1767 | 1774 | the standard library. |
|
1768 | 1775 | |
|
1769 | 1776 | * IPython/iplib.py (InteractiveShell.handle_shell_escape): added |
|
1770 | 1777 | '!!' as a special syntax (shorthand) to access @sx. |
|
1771 | 1778 | |
|
1772 | 1779 | * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell |
|
1773 | 1780 | command and return its output as a list split on '\n'. |
|
1774 | 1781 | |
|
1775 | 1782 | 2004-03-31 Fernando Perez <fperez@colorado.edu> |
|
1776 | 1783 | |
|
1777 | 1784 | * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__ |
|
1778 | 1785 | method to dictionaries used as FakeModule instances if they lack |
|
1779 | 1786 | it. At least pydoc in python2.3 breaks for runtime-defined |
|
1780 | 1787 | functions without this hack. At some point I need to _really_ |
|
1781 | 1788 | understand what FakeModule is doing, because it's a gross hack. |
|
1782 | 1789 | But it solves Arnd's problem for now... |
|
1783 | 1790 | |
|
1784 | 1791 | 2004-02-27 Fernando Perez <fperez@colorado.edu> |
|
1785 | 1792 | |
|
1786 | 1793 | * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate' |
|
1787 | 1794 | mode would behave erratically. Also increased the number of |
|
1788 | 1795 | possible logs in rotate mod to 999. Thanks to Rod Holland |
|
1789 | 1796 | <rhh@StructureLABS.com> for the report and fixes. |
|
1790 | 1797 | |
|
1791 | 1798 | 2004-02-26 Fernando Perez <fperez@colorado.edu> |
|
1792 | 1799 | |
|
1793 | 1800 | * IPython/genutils.py (page): Check that the curses module really |
|
1794 | 1801 | has the initscr attribute before trying to use it. For some |
|
1795 | 1802 | reason, the Solaris curses module is missing this. I think this |
|
1796 | 1803 | should be considered a Solaris python bug, but I'm not sure. |
|
1797 | 1804 | |
|
1798 | 1805 | 2004-01-17 Fernando Perez <fperez@colorado.edu> |
|
1799 | 1806 | |
|
1800 | 1807 | * IPython/genutils.py (Stream.__init__): Changes to try to make |
|
1801 | 1808 | ipython robust against stdin/out/err being closed by the user. |
|
1802 | 1809 | This is 'user error' (and blocks a normal python session, at least |
|
1803 | 1810 | the stdout case). However, Ipython should be able to survive such |
|
1804 | 1811 | instances of abuse as gracefully as possible. To simplify the |
|
1805 | 1812 | coding and maintain compatibility with Gary Bishop's Term |
|
1806 | 1813 | contributions, I've made use of classmethods for this. I think |
|
1807 | 1814 | this introduces a dependency on python 2.2. |
|
1808 | 1815 | |
|
1809 | 1816 | 2004-01-13 Fernando Perez <fperez@colorado.edu> |
|
1810 | 1817 | |
|
1811 | 1818 | * IPython/numutils.py (exp_safe): simplified the code a bit and |
|
1812 | 1819 | removed the need for importing the kinds module altogether. |
|
1813 | 1820 | |
|
1814 | 1821 | 2004-01-06 Fernando Perez <fperez@colorado.edu> |
|
1815 | 1822 | |
|
1816 | 1823 | * IPython/Magic.py (Magic.magic_sc): Made the shell capture system |
|
1817 | 1824 | a magic function instead, after some community feedback. No |
|
1818 | 1825 | special syntax will exist for it, but its name is deliberately |
|
1819 | 1826 | very short. |
|
1820 | 1827 | |
|
1821 | 1828 | 2003-12-20 Fernando Perez <fperez@colorado.edu> |
|
1822 | 1829 | |
|
1823 | 1830 | * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added |
|
1824 | 1831 | new functionality, to automagically assign the result of a shell |
|
1825 | 1832 | command to a variable. I'll solicit some community feedback on |
|
1826 | 1833 | this before making it permanent. |
|
1827 | 1834 | |
|
1828 | 1835 | * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was |
|
1829 | 1836 | requested about callables for which inspect couldn't obtain a |
|
1830 | 1837 | proper argspec. Thanks to a crash report sent by Etienne |
|
1831 | 1838 | Posthumus <etienne-AT-apple01.cs.vu.nl>. |
|
1832 | 1839 | |
|
1833 | 1840 | 2003-12-09 Fernando Perez <fperez@colorado.edu> |
|
1834 | 1841 | |
|
1835 | 1842 | * IPython/genutils.py (page): patch for the pager to work across |
|
1836 | 1843 | various versions of Windows. By Gary Bishop. |
|
1837 | 1844 | |
|
1838 | 1845 | 2003-12-04 Fernando Perez <fperez@colorado.edu> |
|
1839 | 1846 | |
|
1840 | 1847 | * IPython/Gnuplot2.py (PlotItems): Fixes for working with |
|
1841 | 1848 | Gnuplot.py version 1.7, whose internal names changed quite a bit. |
|
1842 | 1849 | While I tested this and it looks ok, there may still be corner |
|
1843 | 1850 | cases I've missed. |
|
1844 | 1851 | |
|
1845 | 1852 | 2003-12-01 Fernando Perez <fperez@colorado.edu> |
|
1846 | 1853 | |
|
1847 | 1854 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug |
|
1848 | 1855 | where a line like 'p,q=1,2' would fail because the automagic |
|
1849 | 1856 | system would be triggered for @p. |
|
1850 | 1857 | |
|
1851 | 1858 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related |
|
1852 | 1859 | cleanups, code unmodified. |
|
1853 | 1860 | |
|
1854 | 1861 | * IPython/genutils.py (Term): added a class for IPython to handle |
|
1855 | 1862 | output. In most cases it will just be a proxy for stdout/err, but |
|
1856 | 1863 | having this allows modifications to be made for some platforms, |
|
1857 | 1864 | such as handling color escapes under Windows. All of this code |
|
1858 | 1865 | was contributed by Gary Bishop, with minor modifications by me. |
|
1859 | 1866 | The actual changes affect many files. |
|
1860 | 1867 | |
|
1861 | 1868 | 2003-11-30 Fernando Perez <fperez@colorado.edu> |
|
1862 | 1869 | |
|
1863 | 1870 | * IPython/iplib.py (file_matches): new completion code, courtesy |
|
1864 | 1871 | of Jeff Collins. This enables filename completion again under |
|
1865 | 1872 | python 2.3, which disabled it at the C level. |
|
1866 | 1873 | |
|
1867 | 1874 | 2003-11-11 Fernando Perez <fperez@colorado.edu> |
|
1868 | 1875 | |
|
1869 | 1876 | * IPython/numutils.py (amap): Added amap() fn. Simple shorthand |
|
1870 | 1877 | for Numeric.array(map(...)), but often convenient. |
|
1871 | 1878 | |
|
1872 | 1879 | 2003-11-05 Fernando Perez <fperez@colorado.edu> |
|
1873 | 1880 | |
|
1874 | 1881 | * IPython/numutils.py (frange): Changed a call from int() to |
|
1875 | 1882 | int(round()) to prevent a problem reported with arange() in the |
|
1876 | 1883 | numpy list. |
|
1877 | 1884 | |
|
1878 | 1885 | 2003-10-06 Fernando Perez <fperez@colorado.edu> |
|
1879 | 1886 | |
|
1880 | 1887 | * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to |
|
1881 | 1888 | prevent crashes if sys lacks an argv attribute (it happens with |
|
1882 | 1889 | embedded interpreters which build a bare-bones sys module). |
|
1883 | 1890 | Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>. |
|
1884 | 1891 | |
|
1885 | 1892 | 2003-09-24 Fernando Perez <fperez@colorado.edu> |
|
1886 | 1893 | |
|
1887 | 1894 | * IPython/Magic.py (Magic._ofind): blanket except around getattr() |
|
1888 | 1895 | to protect against poorly written user objects where __getattr__ |
|
1889 | 1896 | raises exceptions other than AttributeError. Thanks to a bug |
|
1890 | 1897 | report by Oliver Sander <osander-AT-gmx.de>. |
|
1891 | 1898 | |
|
1892 | 1899 | * IPython/FakeModule.py (FakeModule.__repr__): this method was |
|
1893 | 1900 | missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>. |
|
1894 | 1901 | |
|
1895 | 1902 | 2003-09-09 Fernando Perez <fperez@colorado.edu> |
|
1896 | 1903 | |
|
1897 | 1904 | * IPython/iplib.py (InteractiveShell._prefilter): fix bug where |
|
1898 | 1905 | unpacking a list whith a callable as first element would |
|
1899 | 1906 | mistakenly trigger autocalling. Thanks to a bug report by Jeffery |
|
1900 | 1907 | Collins. |
|
1901 | 1908 | |
|
1902 | 1909 | 2003-08-25 *** Released version 0.5.0 |
|
1903 | 1910 | |
|
1904 | 1911 | 2003-08-22 Fernando Perez <fperez@colorado.edu> |
|
1905 | 1912 | |
|
1906 | 1913 | * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of |
|
1907 | 1914 | improperly defined user exceptions. Thanks to feedback from Mark |
|
1908 | 1915 | Russell <mrussell-AT-verio.net>. |
|
1909 | 1916 | |
|
1910 | 1917 | 2003-08-20 Fernando Perez <fperez@colorado.edu> |
|
1911 | 1918 | |
|
1912 | 1919 | * IPython/OInspect.py (Inspector.pinfo): changed String Form |
|
1913 | 1920 | printing so that it would print multi-line string forms starting |
|
1914 | 1921 | with a new line. This way the formatting is better respected for |
|
1915 | 1922 | objects which work hard to make nice string forms. |
|
1916 | 1923 | |
|
1917 | 1924 | * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where |
|
1918 | 1925 | autocall would overtake data access for objects with both |
|
1919 | 1926 | __getitem__ and __call__. |
|
1920 | 1927 | |
|
1921 | 1928 | 2003-08-19 *** Released version 0.5.0-rc1 |
|
1922 | 1929 | |
|
1923 | 1930 | 2003-08-19 Fernando Perez <fperez@colorado.edu> |
|
1924 | 1931 | |
|
1925 | 1932 | * IPython/deep_reload.py (load_tail): single tiny change here |
|
1926 | 1933 | seems to fix the long-standing bug of dreload() failing to work |
|
1927 | 1934 | for dotted names. But this module is pretty tricky, so I may have |
|
1928 | 1935 | missed some subtlety. Needs more testing!. |
|
1929 | 1936 | |
|
1930 | 1937 | * IPython/ultraTB.py (VerboseTB.linereader): harden against user |
|
1931 | 1938 | exceptions which have badly implemented __str__ methods. |
|
1932 | 1939 | (VerboseTB.text): harden against inspect.getinnerframes crashing, |
|
1933 | 1940 | which I've been getting reports about from Python 2.3 users. I |
|
1934 | 1941 | wish I had a simple test case to reproduce the problem, so I could |
|
1935 | 1942 | either write a cleaner workaround or file a bug report if |
|
1936 | 1943 | necessary. |
|
1937 | 1944 | |
|
1938 | 1945 | * IPython/Magic.py (Magic.magic_edit): fixed bug where after |
|
1939 | 1946 | making a class 'foo', file 'foo.py' couldn't be edited. Thanks to |
|
1940 | 1947 | a bug report by Tjabo Kloppenburg. |
|
1941 | 1948 | |
|
1942 | 1949 | * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb |
|
1943 | 1950 | crashes. Wrapped the pdb call in a blanket try/except, since pdb |
|
1944 | 1951 | seems rather unstable. Thanks to a bug report by Tjabo |
|
1945 | 1952 | Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>. |
|
1946 | 1953 | |
|
1947 | 1954 | * IPython/Release.py (version): release 0.5.0-rc1. I want to put |
|
1948 | 1955 | this out soon because of the critical fixes in the inner loop for |
|
1949 | 1956 | generators. |
|
1950 | 1957 | |
|
1951 | 1958 | * IPython/Magic.py (Magic.getargspec): removed. This (and |
|
1952 | 1959 | _get_def) have been obsoleted by OInspect for a long time, I |
|
1953 | 1960 | hadn't noticed that they were dead code. |
|
1954 | 1961 | (Magic._ofind): restored _ofind functionality for a few literals |
|
1955 | 1962 | (those in ["''",'""','[]','{}','()']). But it won't work anymore |
|
1956 | 1963 | for things like "hello".capitalize?, since that would require a |
|
1957 | 1964 | potentially dangerous eval() again. |
|
1958 | 1965 | |
|
1959 | 1966 | * IPython/iplib.py (InteractiveShell._prefilter): reorganized the |
|
1960 | 1967 | logic a bit more to clean up the escapes handling and minimize the |
|
1961 | 1968 | use of _ofind to only necessary cases. The interactive 'feel' of |
|
1962 | 1969 | IPython should have improved quite a bit with the changes in |
|
1963 | 1970 | _prefilter and _ofind (besides being far safer than before). |
|
1964 | 1971 | |
|
1965 | 1972 | * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather |
|
1966 | 1973 | obscure, never reported). Edit would fail to find the object to |
|
1967 | 1974 | edit under some circumstances. |
|
1968 | 1975 | (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls |
|
1969 | 1976 | which were causing double-calling of generators. Those eval calls |
|
1970 | 1977 | were _very_ dangerous, since code with side effects could be |
|
1971 | 1978 | triggered. As they say, 'eval is evil'... These were the |
|
1972 | 1979 | nastiest evals in IPython. Besides, _ofind is now far simpler, |
|
1973 | 1980 | and it should also be quite a bit faster. Its use of inspect is |
|
1974 | 1981 | also safer, so perhaps some of the inspect-related crashes I've |
|
1975 | 1982 | seen lately with Python 2.3 might be taken care of. That will |
|
1976 | 1983 | need more testing. |
|
1977 | 1984 | |
|
1978 | 1985 | 2003-08-17 Fernando Perez <fperez@colorado.edu> |
|
1979 | 1986 | |
|
1980 | 1987 | * IPython/iplib.py (InteractiveShell._prefilter): significant |
|
1981 | 1988 | simplifications to the logic for handling user escapes. Faster |
|
1982 | 1989 | and simpler code. |
|
1983 | 1990 | |
|
1984 | 1991 | 2003-08-14 Fernando Perez <fperez@colorado.edu> |
|
1985 | 1992 | |
|
1986 | 1993 | * IPython/numutils.py (sum_flat): rewrote to be non-recursive. |
|
1987 | 1994 | Now it requires O(N) storage (N=size(a)) for non-contiguous input, |
|
1988 | 1995 | but it should be quite a bit faster. And the recursive version |
|
1989 | 1996 | generated O(log N) intermediate storage for all rank>1 arrays, |
|
1990 | 1997 | even if they were contiguous. |
|
1991 | 1998 | (l1norm): Added this function. |
|
1992 | 1999 | (norm): Added this function for arbitrary norms (including |
|
1993 | 2000 | l-infinity). l1 and l2 are still special cases for convenience |
|
1994 | 2001 | and speed. |
|
1995 | 2002 | |
|
1996 | 2003 | 2003-08-03 Fernando Perez <fperez@colorado.edu> |
|
1997 | 2004 | |
|
1998 | 2005 | * IPython/Magic.py (Magic.magic_edit): Removed all remaining string |
|
1999 | 2006 | exceptions, which now raise PendingDeprecationWarnings in Python |
|
2000 | 2007 | 2.3. There were some in Magic and some in Gnuplot2. |
|
2001 | 2008 | |
|
2002 | 2009 | 2003-06-30 Fernando Perez <fperez@colorado.edu> |
|
2003 | 2010 | |
|
2004 | 2011 | * IPython/genutils.py (page): modified to call curses only for |
|
2005 | 2012 | terminals where TERM=='xterm'. After problems under many other |
|
2006 | 2013 | terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>. |
|
2007 | 2014 | |
|
2008 | 2015 | * IPython/iplib.py (complete): removed spurious 'print "IE"' which |
|
2009 | 2016 | would be triggered when readline was absent. This was just an old |
|
2010 | 2017 | debugging statement I'd forgotten to take out. |
|
2011 | 2018 | |
|
2012 | 2019 | 2003-06-20 Fernando Perez <fperez@colorado.edu> |
|
2013 | 2020 | |
|
2014 | 2021 | * IPython/genutils.py (clock): modified to return only user time |
|
2015 | 2022 | (not counting system time), after a discussion on scipy. While |
|
2016 | 2023 | system time may be a useful quantity occasionally, it may much |
|
2017 | 2024 | more easily be skewed by occasional swapping or other similar |
|
2018 | 2025 | activity. |
|
2019 | 2026 | |
|
2020 | 2027 | 2003-06-05 Fernando Perez <fperez@colorado.edu> |
|
2021 | 2028 | |
|
2022 | 2029 | * IPython/numutils.py (identity): new function, for building |
|
2023 | 2030 | arbitrary rank Kronecker deltas (mostly backwards compatible with |
|
2024 | 2031 | Numeric.identity) |
|
2025 | 2032 | |
|
2026 | 2033 | 2003-06-03 Fernando Perez <fperez@colorado.edu> |
|
2027 | 2034 | |
|
2028 | 2035 | * IPython/iplib.py (InteractiveShell.handle_magic): protect |
|
2029 | 2036 | arguments passed to magics with spaces, to allow trailing '\' to |
|
2030 | 2037 | work normally (mainly for Windows users). |
|
2031 | 2038 | |
|
2032 | 2039 | 2003-05-29 Fernando Perez <fperez@colorado.edu> |
|
2033 | 2040 | |
|
2034 | 2041 | * IPython/ipmaker.py (make_IPython): Load site._Helper() as help |
|
2035 | 2042 | instead of pydoc.help. This fixes a bizarre behavior where |
|
2036 | 2043 | printing '%s' % locals() would trigger the help system. Now |
|
2037 | 2044 | ipython behaves like normal python does. |
|
2038 | 2045 | |
|
2039 | 2046 | Note that if one does 'from pydoc import help', the bizarre |
|
2040 | 2047 | behavior returns, but this will also happen in normal python, so |
|
2041 | 2048 | it's not an ipython bug anymore (it has to do with how pydoc.help |
|
2042 | 2049 | is implemented). |
|
2043 | 2050 | |
|
2044 | 2051 | 2003-05-22 Fernando Perez <fperez@colorado.edu> |
|
2045 | 2052 | |
|
2046 | 2053 | * IPython/FlexCompleter.py (Completer.attr_matches): fixed to |
|
2047 | 2054 | return [] instead of None when nothing matches, also match to end |
|
2048 | 2055 | of line. Patch by Gary Bishop. |
|
2049 | 2056 | |
|
2050 | 2057 | * IPython/ipmaker.py (make_IPython): Added same sys.excepthook |
|
2051 | 2058 | protection as before, for files passed on the command line. This |
|
2052 | 2059 | prevents the CrashHandler from kicking in if user files call into |
|
2053 | 2060 | sys.excepthook (such as PyQt and WxWindows have a nasty habit of |
|
2054 | 2061 | doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr> |
|
2055 | 2062 | |
|
2056 | 2063 | 2003-05-20 *** Released version 0.4.0 |
|
2057 | 2064 | |
|
2058 | 2065 | 2003-05-20 Fernando Perez <fperez@colorado.edu> |
|
2059 | 2066 | |
|
2060 | 2067 | * setup.py: added support for manpages. It's a bit hackish b/c of |
|
2061 | 2068 | a bug in the way the bdist_rpm distutils target handles gzipped |
|
2062 | 2069 | manpages, but it works. After a patch by Jack. |
|
2063 | 2070 | |
|
2064 | 2071 | 2003-05-19 Fernando Perez <fperez@colorado.edu> |
|
2065 | 2072 | |
|
2066 | 2073 | * IPython/numutils.py: added a mockup of the kinds module, since |
|
2067 | 2074 | it was recently removed from Numeric. This way, numutils will |
|
2068 | 2075 | work for all users even if they are missing kinds. |
|
2069 | 2076 | |
|
2070 | 2077 | * IPython/Magic.py (Magic._ofind): Harden against an inspect |
|
2071 | 2078 | failure, which can occur with SWIG-wrapped extensions. After a |
|
2072 | 2079 | crash report from Prabhu. |
|
2073 | 2080 | |
|
2074 | 2081 | 2003-05-16 Fernando Perez <fperez@colorado.edu> |
|
2075 | 2082 | |
|
2076 | 2083 | * IPython/iplib.py (InteractiveShell.excepthook): New method to |
|
2077 | 2084 | protect ipython from user code which may call directly |
|
2078 | 2085 | sys.excepthook (this looks like an ipython crash to the user, even |
|
2079 | 2086 | when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
2080 | 2087 | This is especially important to help users of WxWindows, but may |
|
2081 | 2088 | also be useful in other cases. |
|
2082 | 2089 | |
|
2083 | 2090 | * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow |
|
2084 | 2091 | an optional tb_offset to be specified, and to preserve exception |
|
2085 | 2092 | info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>. |
|
2086 | 2093 | |
|
2087 | 2094 | * ipython.1 (Default): Thanks to Jack's work, we now have manpages! |
|
2088 | 2095 | |
|
2089 | 2096 | 2003-05-15 Fernando Perez <fperez@colorado.edu> |
|
2090 | 2097 | |
|
2091 | 2098 | * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when |
|
2092 | 2099 | installing for a new user under Windows. |
|
2093 | 2100 | |
|
2094 | 2101 | 2003-05-12 Fernando Perez <fperez@colorado.edu> |
|
2095 | 2102 | |
|
2096 | 2103 | * IPython/iplib.py (InteractiveShell.handle_emacs): New line |
|
2097 | 2104 | handler for Emacs comint-based lines. Currently it doesn't do |
|
2098 | 2105 | much (but importantly, it doesn't update the history cache). In |
|
2099 | 2106 | the future it may be expanded if Alex needs more functionality |
|
2100 | 2107 | there. |
|
2101 | 2108 | |
|
2102 | 2109 | * IPython/CrashHandler.py (CrashHandler.__call__): Added platform |
|
2103 | 2110 | info to crash reports. |
|
2104 | 2111 | |
|
2105 | 2112 | * IPython/iplib.py (InteractiveShell.mainloop): Added -c option, |
|
2106 | 2113 | just like Python's -c. Also fixed crash with invalid -color |
|
2107 | 2114 | option value at startup. Thanks to Will French |
|
2108 | 2115 | <wfrench-AT-bestweb.net> for the bug report. |
|
2109 | 2116 | |
|
2110 | 2117 | 2003-05-09 Fernando Perez <fperez@colorado.edu> |
|
2111 | 2118 | |
|
2112 | 2119 | * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString |
|
2113 | 2120 | to EvalDict (it's a mapping, after all) and simplified its code |
|
2114 | 2121 | quite a bit, after a nice discussion on c.l.py where Gustavo |
|
2115 | 2122 | Córdova <gcordova-AT-sismex.com> suggested the new version. |
|
2116 | 2123 | |
|
2117 | 2124 | 2003-04-30 Fernando Perez <fperez@colorado.edu> |
|
2118 | 2125 | |
|
2119 | 2126 | * IPython/genutils.py (timings_out): modified it to reduce its |
|
2120 | 2127 | overhead in the common reps==1 case. |
|
2121 | 2128 | |
|
2122 | 2129 | 2003-04-29 Fernando Perez <fperez@colorado.edu> |
|
2123 | 2130 | |
|
2124 | 2131 | * IPython/genutils.py (timings_out): Modified to use the resource |
|
2125 | 2132 | module, which avoids the wraparound problems of time.clock(). |
|
2126 | 2133 | |
|
2127 | 2134 | 2003-04-17 *** Released version 0.2.15pre4 |
|
2128 | 2135 | |
|
2129 | 2136 | 2003-04-17 Fernando Perez <fperez@colorado.edu> |
|
2130 | 2137 | |
|
2131 | 2138 | * setup.py (scriptfiles): Split windows-specific stuff over to a |
|
2132 | 2139 | separate file, in an attempt to have a Windows GUI installer. |
|
2133 | 2140 | That didn't work, but part of the groundwork is done. |
|
2134 | 2141 | |
|
2135 | 2142 | * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for |
|
2136 | 2143 | indent/unindent with 4 spaces. Particularly useful in combination |
|
2137 | 2144 | with the new auto-indent option. |
|
2138 | 2145 | |
|
2139 | 2146 | 2003-04-16 Fernando Perez <fperez@colorado.edu> |
|
2140 | 2147 | |
|
2141 | 2148 | * IPython/Magic.py: various replacements of self.rc for |
|
2142 | 2149 | self.shell.rc. A lot more remains to be done to fully disentangle |
|
2143 | 2150 | this class from the main Shell class. |
|
2144 | 2151 | |
|
2145 | 2152 | * IPython/GnuplotRuntime.py: added checks for mouse support so |
|
2146 | 2153 | that we don't try to enable it if the current gnuplot doesn't |
|
2147 | 2154 | really support it. Also added checks so that we don't try to |
|
2148 | 2155 | enable persist under Windows (where Gnuplot doesn't recognize the |
|
2149 | 2156 | option). |
|
2150 | 2157 | |
|
2151 | 2158 | * IPython/iplib.py (InteractiveShell.interact): Added optional |
|
2152 | 2159 | auto-indenting code, after a patch by King C. Shu |
|
2153 | 2160 | <kingshu-AT-myrealbox.com>. It's off by default because it doesn't |
|
2154 | 2161 | get along well with pasting indented code. If I ever figure out |
|
2155 | 2162 | how to make that part go well, it will become on by default. |
|
2156 | 2163 | |
|
2157 | 2164 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would |
|
2158 | 2165 | crash ipython if there was an unmatched '%' in the user's prompt |
|
2159 | 2166 | string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2160 | 2167 | |
|
2161 | 2168 | * IPython/iplib.py (InteractiveShell.interact): removed the |
|
2162 | 2169 | ability to ask the user whether he wants to crash or not at the |
|
2163 | 2170 | 'last line' exception handler. Calling functions at that point |
|
2164 | 2171 | changes the stack, and the error reports would have incorrect |
|
2165 | 2172 | tracebacks. |
|
2166 | 2173 | |
|
2167 | 2174 | * IPython/Magic.py (Magic.magic_page): Added new @page magic, to |
|
2168 | 2175 | pass through a peger a pretty-printed form of any object. After a |
|
2169 | 2176 | contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr> |
|
2170 | 2177 | |
|
2171 | 2178 | 2003-04-14 Fernando Perez <fperez@colorado.edu> |
|
2172 | 2179 | |
|
2173 | 2180 | * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where |
|
2174 | 2181 | all files in ~ would be modified at first install (instead of |
|
2175 | 2182 | ~/.ipython). This could be potentially disastrous, as the |
|
2176 | 2183 | modification (make line-endings native) could damage binary files. |
|
2177 | 2184 | |
|
2178 | 2185 | 2003-04-10 Fernando Perez <fperez@colorado.edu> |
|
2179 | 2186 | |
|
2180 | 2187 | * IPython/iplib.py (InteractiveShell.handle_help): Modified to |
|
2181 | 2188 | handle only lines which are invalid python. This now means that |
|
2182 | 2189 | lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins |
|
2183 | 2190 | for the bug report. |
|
2184 | 2191 | |
|
2185 | 2192 | 2003-04-01 Fernando Perez <fperez@colorado.edu> |
|
2186 | 2193 | |
|
2187 | 2194 | * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug |
|
2188 | 2195 | where failing to set sys.last_traceback would crash pdb.pm(). |
|
2189 | 2196 | Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug |
|
2190 | 2197 | report. |
|
2191 | 2198 | |
|
2192 | 2199 | 2003-03-25 Fernando Perez <fperez@colorado.edu> |
|
2193 | 2200 | |
|
2194 | 2201 | * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler |
|
2195 | 2202 | before printing it (it had a lot of spurious blank lines at the |
|
2196 | 2203 | end). |
|
2197 | 2204 | |
|
2198 | 2205 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr |
|
2199 | 2206 | output would be sent 21 times! Obviously people don't use this |
|
2200 | 2207 | too often, or I would have heard about it. |
|
2201 | 2208 | |
|
2202 | 2209 | 2003-03-24 Fernando Perez <fperez@colorado.edu> |
|
2203 | 2210 | |
|
2204 | 2211 | * setup.py (scriptfiles): renamed the data_files parameter from |
|
2205 | 2212 | 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink |
|
2206 | 2213 | for the patch. |
|
2207 | 2214 | |
|
2208 | 2215 | 2003-03-20 Fernando Perez <fperez@colorado.edu> |
|
2209 | 2216 | |
|
2210 | 2217 | * IPython/genutils.py (error): added error() and fatal() |
|
2211 | 2218 | functions. |
|
2212 | 2219 | |
|
2213 | 2220 | 2003-03-18 *** Released version 0.2.15pre3 |
|
2214 | 2221 | |
|
2215 | 2222 | 2003-03-18 Fernando Perez <fperez@colorado.edu> |
|
2216 | 2223 | |
|
2217 | 2224 | * setupext/install_data_ext.py |
|
2218 | 2225 | (install_data_ext.initialize_options): Class contributed by Jack |
|
2219 | 2226 | Moffit for fixing the old distutils hack. He is sending this to |
|
2220 | 2227 | the distutils folks so in the future we may not need it as a |
|
2221 | 2228 | private fix. |
|
2222 | 2229 | |
|
2223 | 2230 | * MANIFEST.in: Extensive reorganization, based on Jack Moffit's |
|
2224 | 2231 | changes for Debian packaging. See his patch for full details. |
|
2225 | 2232 | The old distutils hack of making the ipythonrc* files carry a |
|
2226 | 2233 | bogus .py extension is gone, at last. Examples were moved to a |
|
2227 | 2234 | separate subdir under doc/, and the separate executable scripts |
|
2228 | 2235 | now live in their own directory. Overall a great cleanup. The |
|
2229 | 2236 | manual was updated to use the new files, and setup.py has been |
|
2230 | 2237 | fixed for this setup. |
|
2231 | 2238 | |
|
2232 | 2239 | * IPython/PyColorize.py (Parser.usage): made non-executable and |
|
2233 | 2240 | created a pycolor wrapper around it to be included as a script. |
|
2234 | 2241 | |
|
2235 | 2242 | 2003-03-12 *** Released version 0.2.15pre2 |
|
2236 | 2243 | |
|
2237 | 2244 | 2003-03-12 Fernando Perez <fperez@colorado.edu> |
|
2238 | 2245 | |
|
2239 | 2246 | * IPython/ColorANSI.py (make_color_table): Finally fixed the |
|
2240 | 2247 | long-standing problem with garbage characters in some terminals. |
|
2241 | 2248 | The issue was really that the \001 and \002 escapes must _only_ be |
|
2242 | 2249 | passed to input prompts (which call readline), but _never_ to |
|
2243 | 2250 | normal text to be printed on screen. I changed ColorANSI to have |
|
2244 | 2251 | two classes: TermColors and InputTermColors, each with the |
|
2245 | 2252 | appropriate escapes for input prompts or normal text. The code in |
|
2246 | 2253 | Prompts.py got slightly more complicated, but this very old and |
|
2247 | 2254 | annoying bug is finally fixed. |
|
2248 | 2255 | |
|
2249 | 2256 | All the credit for nailing down the real origin of this problem |
|
2250 | 2257 | and the correct solution goes to Jack Moffit <jack-AT-xiph.org>. |
|
2251 | 2258 | *Many* thanks to him for spending quite a bit of effort on this. |
|
2252 | 2259 | |
|
2253 | 2260 | 2003-03-05 *** Released version 0.2.15pre1 |
|
2254 | 2261 | |
|
2255 | 2262 | 2003-03-03 Fernando Perez <fperez@colorado.edu> |
|
2256 | 2263 | |
|
2257 | 2264 | * IPython/FakeModule.py: Moved the former _FakeModule to a |
|
2258 | 2265 | separate file, because it's also needed by Magic (to fix a similar |
|
2259 | 2266 | pickle-related issue in @run). |
|
2260 | 2267 | |
|
2261 | 2268 | 2003-03-02 Fernando Perez <fperez@colorado.edu> |
|
2262 | 2269 | |
|
2263 | 2270 | * IPython/Magic.py (Magic.magic_autocall): new magic to control |
|
2264 | 2271 | the autocall option at runtime. |
|
2265 | 2272 | (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns |
|
2266 | 2273 | across Magic.py to start separating Magic from InteractiveShell. |
|
2267 | 2274 | (Magic._ofind): Fixed to return proper namespace for dotted |
|
2268 | 2275 | names. Before, a dotted name would always return 'not currently |
|
2269 | 2276 | defined', because it would find the 'parent'. s.x would be found, |
|
2270 | 2277 | but since 'x' isn't defined by itself, it would get confused. |
|
2271 | 2278 | (Magic.magic_run): Fixed pickling problems reported by Ralf |
|
2272 | 2279 | Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to |
|
2273 | 2280 | that I'd used when Mike Heeter reported similar issues at the |
|
2274 | 2281 | top-level, but now for @run. It boils down to injecting the |
|
2275 | 2282 | namespace where code is being executed with something that looks |
|
2276 | 2283 | enough like a module to fool pickle.dump(). Since a pickle stores |
|
2277 | 2284 | a named reference to the importing module, we need this for |
|
2278 | 2285 | pickles to save something sensible. |
|
2279 | 2286 | |
|
2280 | 2287 | * IPython/ipmaker.py (make_IPython): added an autocall option. |
|
2281 | 2288 | |
|
2282 | 2289 | * IPython/iplib.py (InteractiveShell._prefilter): reordered all of |
|
2283 | 2290 | the auto-eval code. Now autocalling is an option, and the code is |
|
2284 | 2291 | also vastly safer. There is no more eval() involved at all. |
|
2285 | 2292 | |
|
2286 | 2293 | 2003-03-01 Fernando Perez <fperez@colorado.edu> |
|
2287 | 2294 | |
|
2288 | 2295 | * IPython/Magic.py (Magic._ofind): Changed interface to return a |
|
2289 | 2296 | dict with named keys instead of a tuple. |
|
2290 | 2297 | |
|
2291 | 2298 | * IPython: Started using CVS for IPython as of 0.2.15pre1. |
|
2292 | 2299 | |
|
2293 | 2300 | * setup.py (make_shortcut): Fixed message about directories |
|
2294 | 2301 | created during Windows installation (the directories were ok, just |
|
2295 | 2302 | the printed message was misleading). Thanks to Chris Liechti |
|
2296 | 2303 | <cliechti-AT-gmx.net> for the heads up. |
|
2297 | 2304 | |
|
2298 | 2305 | 2003-02-21 Fernando Perez <fperez@colorado.edu> |
|
2299 | 2306 | |
|
2300 | 2307 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching |
|
2301 | 2308 | of ValueError exception when checking for auto-execution. This |
|
2302 | 2309 | one is raised by things like Numeric arrays arr.flat when the |
|
2303 | 2310 | array is non-contiguous. |
|
2304 | 2311 | |
|
2305 | 2312 | 2003-01-31 Fernando Perez <fperez@colorado.edu> |
|
2306 | 2313 | |
|
2307 | 2314 | * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would |
|
2308 | 2315 | not return any value at all (even though the command would get |
|
2309 | 2316 | executed). |
|
2310 | 2317 | (xsys): Flush stdout right after printing the command to ensure |
|
2311 | 2318 | proper ordering of commands and command output in the total |
|
2312 | 2319 | output. |
|
2313 | 2320 | (SystemExec/xsys/bq): Switched the names of xsys/bq and |
|
2314 | 2321 | system/getoutput as defaults. The old ones are kept for |
|
2315 | 2322 | compatibility reasons, so no code which uses this library needs |
|
2316 | 2323 | changing. |
|
2317 | 2324 | |
|
2318 | 2325 | 2003-01-27 *** Released version 0.2.14 |
|
2319 | 2326 | |
|
2320 | 2327 | 2003-01-25 Fernando Perez <fperez@colorado.edu> |
|
2321 | 2328 | |
|
2322 | 2329 | * IPython/Magic.py (Magic.magic_edit): Fixed problem where |
|
2323 | 2330 | functions defined in previous edit sessions could not be re-edited |
|
2324 | 2331 | (because the temp files were immediately removed). Now temp files |
|
2325 | 2332 | are removed only at IPython's exit. |
|
2326 | 2333 | (Magic.magic_run): Improved @run to perform shell-like expansions |
|
2327 | 2334 | on its arguments (~users and $VARS). With this, @run becomes more |
|
2328 | 2335 | like a normal command-line. |
|
2329 | 2336 | |
|
2330 | 2337 | * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small |
|
2331 | 2338 | bugs related to embedding and cleaned up that code. A fairly |
|
2332 | 2339 | important one was the impossibility to access the global namespace |
|
2333 | 2340 | through the embedded IPython (only local variables were visible). |
|
2334 | 2341 | |
|
2335 | 2342 | 2003-01-14 Fernando Perez <fperez@colorado.edu> |
|
2336 | 2343 | |
|
2337 | 2344 | * IPython/iplib.py (InteractiveShell._prefilter): Fixed |
|
2338 | 2345 | auto-calling to be a bit more conservative. Now it doesn't get |
|
2339 | 2346 | triggered if any of '!=()<>' are in the rest of the input line, to |
|
2340 | 2347 | allow comparing callables. Thanks to Alex for the heads up. |
|
2341 | 2348 | |
|
2342 | 2349 | 2003-01-07 Fernando Perez <fperez@colorado.edu> |
|
2343 | 2350 | |
|
2344 | 2351 | * IPython/genutils.py (page): fixed estimation of the number of |
|
2345 | 2352 | lines in a string to be paged to simply count newlines. This |
|
2346 | 2353 | prevents over-guessing due to embedded escape sequences. A better |
|
2347 | 2354 | long-term solution would involve stripping out the control chars |
|
2348 | 2355 | for the count, but it's potentially so expensive I just don't |
|
2349 | 2356 | think it's worth doing. |
|
2350 | 2357 | |
|
2351 | 2358 | 2002-12-19 *** Released version 0.2.14pre50 |
|
2352 | 2359 | |
|
2353 | 2360 | 2002-12-19 Fernando Perez <fperez@colorado.edu> |
|
2354 | 2361 | |
|
2355 | 2362 | * tools/release (version): Changed release scripts to inform |
|
2356 | 2363 | Andrea and build a NEWS file with a list of recent changes. |
|
2357 | 2364 | |
|
2358 | 2365 | * IPython/ColorANSI.py (__all__): changed terminal detection |
|
2359 | 2366 | code. Seems to work better for xterms without breaking |
|
2360 | 2367 | konsole. Will need more testing to determine if WinXP and Mac OSX |
|
2361 | 2368 | also work ok. |
|
2362 | 2369 | |
|
2363 | 2370 | 2002-12-18 *** Released version 0.2.14pre49 |
|
2364 | 2371 | |
|
2365 | 2372 | 2002-12-18 Fernando Perez <fperez@colorado.edu> |
|
2366 | 2373 | |
|
2367 | 2374 | * Docs: added new info about Mac OSX, from Andrea. |
|
2368 | 2375 | |
|
2369 | 2376 | * IPython/Gnuplot2.py (String): Added a String PlotItem class to |
|
2370 | 2377 | allow direct plotting of python strings whose format is the same |
|
2371 | 2378 | of gnuplot data files. |
|
2372 | 2379 | |
|
2373 | 2380 | 2002-12-16 Fernando Perez <fperez@colorado.edu> |
|
2374 | 2381 | |
|
2375 | 2382 | * IPython/iplib.py (InteractiveShell.interact): fixed default (y) |
|
2376 | 2383 | value of exit question to be acknowledged. |
|
2377 | 2384 | |
|
2378 | 2385 | 2002-12-03 Fernando Perez <fperez@colorado.edu> |
|
2379 | 2386 | |
|
2380 | 2387 | * IPython/ipmaker.py: removed generators, which had been added |
|
2381 | 2388 | by mistake in an earlier debugging run. This was causing trouble |
|
2382 | 2389 | to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu> |
|
2383 | 2390 | for pointing this out. |
|
2384 | 2391 | |
|
2385 | 2392 | 2002-11-17 Fernando Perez <fperez@colorado.edu> |
|
2386 | 2393 | |
|
2387 | 2394 | * Manual: updated the Gnuplot section. |
|
2388 | 2395 | |
|
2389 | 2396 | * IPython/GnuplotRuntime.py: refactored a lot all this code, with |
|
2390 | 2397 | a much better split of what goes in Runtime and what goes in |
|
2391 | 2398 | Interactive. |
|
2392 | 2399 | |
|
2393 | 2400 | * IPython/ipmaker.py: fixed bug where import_fail_info wasn't |
|
2394 | 2401 | being imported from iplib. |
|
2395 | 2402 | |
|
2396 | 2403 | * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc |
|
2397 | 2404 | for command-passing. Now the global Gnuplot instance is called |
|
2398 | 2405 | 'gp' instead of 'g', which was really a far too fragile and |
|
2399 | 2406 | common name. |
|
2400 | 2407 | |
|
2401 | 2408 | * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken |
|
2402 | 2409 | bounding boxes generated by Gnuplot for square plots. |
|
2403 | 2410 | |
|
2404 | 2411 | * IPython/genutils.py (popkey): new function added. I should |
|
2405 | 2412 | suggest this on c.l.py as a dict method, it seems useful. |
|
2406 | 2413 | |
|
2407 | 2414 | * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot |
|
2408 | 2415 | to transparently handle PostScript generation. MUCH better than |
|
2409 | 2416 | the previous plot_eps/replot_eps (which I removed now). The code |
|
2410 | 2417 | is also fairly clean and well documented now (including |
|
2411 | 2418 | docstrings). |
|
2412 | 2419 | |
|
2413 | 2420 | 2002-11-13 Fernando Perez <fperez@colorado.edu> |
|
2414 | 2421 | |
|
2415 | 2422 | * IPython/Magic.py (Magic.magic_edit): fixed docstring |
|
2416 | 2423 | (inconsistent with options). |
|
2417 | 2424 | |
|
2418 | 2425 | * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been |
|
2419 | 2426 | manually disabled, I don't know why. Fixed it. |
|
2420 | 2427 | (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly |
|
2421 | 2428 | eps output. |
|
2422 | 2429 | |
|
2423 | 2430 | 2002-11-12 Fernando Perez <fperez@colorado.edu> |
|
2424 | 2431 | |
|
2425 | 2432 | * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they |
|
2426 | 2433 | don't propagate up to caller. Fixes crash reported by François |
|
2427 | 2434 | Pinard. |
|
2428 | 2435 | |
|
2429 | 2436 | 2002-11-09 Fernando Perez <fperez@colorado.edu> |
|
2430 | 2437 | |
|
2431 | 2438 | * IPython/ipmaker.py (make_IPython): fixed problem with writing |
|
2432 | 2439 | history file for new users. |
|
2433 | 2440 | (make_IPython): fixed bug where initial install would leave the |
|
2434 | 2441 | user running in the .ipython dir. |
|
2435 | 2442 | (make_IPython): fixed bug where config dir .ipython would be |
|
2436 | 2443 | created regardless of the given -ipythondir option. Thanks to Cory |
|
2437 | 2444 | Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report. |
|
2438 | 2445 | |
|
2439 | 2446 | * IPython/genutils.py (ask_yes_no): new function for asking yes/no |
|
2440 | 2447 | type confirmations. Will need to use it in all of IPython's code |
|
2441 | 2448 | consistently. |
|
2442 | 2449 | |
|
2443 | 2450 | * IPython/CrashHandler.py (CrashHandler.__call__): changed the |
|
2444 | 2451 | context to print 31 lines instead of the default 5. This will make |
|
2445 | 2452 | the crash reports extremely detailed in case the problem is in |
|
2446 | 2453 | libraries I don't have access to. |
|
2447 | 2454 | |
|
2448 | 2455 | * IPython/iplib.py (InteractiveShell.interact): changed the 'last |
|
2449 | 2456 | line of defense' code to still crash, but giving users fair |
|
2450 | 2457 | warning. I don't want internal errors to go unreported: if there's |
|
2451 | 2458 | an internal problem, IPython should crash and generate a full |
|
2452 | 2459 | report. |
|
2453 | 2460 | |
|
2454 | 2461 | 2002-11-08 Fernando Perez <fperez@colorado.edu> |
|
2455 | 2462 | |
|
2456 | 2463 | * IPython/iplib.py (InteractiveShell.interact): added code to trap |
|
2457 | 2464 | otherwise uncaught exceptions which can appear if people set |
|
2458 | 2465 | sys.stdout to something badly broken. Thanks to a crash report |
|
2459 | 2466 | from henni-AT-mail.brainbot.com. |
|
2460 | 2467 | |
|
2461 | 2468 | 2002-11-04 Fernando Perez <fperez@colorado.edu> |
|
2462 | 2469 | |
|
2463 | 2470 | * IPython/iplib.py (InteractiveShell.interact): added |
|
2464 | 2471 | __IPYTHON__active to the builtins. It's a flag which goes on when |
|
2465 | 2472 | the interaction starts and goes off again when it stops. This |
|
2466 | 2473 | allows embedding code to detect being inside IPython. Before this |
|
2467 | 2474 | was done via __IPYTHON__, but that only shows that an IPython |
|
2468 | 2475 | instance has been created. |
|
2469 | 2476 | |
|
2470 | 2477 | * IPython/Magic.py (Magic.magic_env): I realized that in a |
|
2471 | 2478 | UserDict, instance.data holds the data as a normal dict. So I |
|
2472 | 2479 | modified @env to return os.environ.data instead of rebuilding a |
|
2473 | 2480 | dict by hand. |
|
2474 | 2481 | |
|
2475 | 2482 | 2002-11-02 Fernando Perez <fperez@colorado.edu> |
|
2476 | 2483 | |
|
2477 | 2484 | * IPython/genutils.py (warn): changed so that level 1 prints no |
|
2478 | 2485 | header. Level 2 is now the default (with 'WARNING' header, as |
|
2479 | 2486 | before). I think I tracked all places where changes were needed in |
|
2480 | 2487 | IPython, but outside code using the old level numbering may have |
|
2481 | 2488 | broken. |
|
2482 | 2489 | |
|
2483 | 2490 | * IPython/iplib.py (InteractiveShell.runcode): added this to |
|
2484 | 2491 | handle the tracebacks in SystemExit traps correctly. The previous |
|
2485 | 2492 | code (through interact) was printing more of the stack than |
|
2486 | 2493 | necessary, showing IPython internal code to the user. |
|
2487 | 2494 | |
|
2488 | 2495 | * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by |
|
2489 | 2496 | default. Now that the default at the confirmation prompt is yes, |
|
2490 | 2497 | it's not so intrusive. François' argument that ipython sessions |
|
2491 | 2498 | tend to be complex enough not to lose them from an accidental C-d, |
|
2492 | 2499 | is a valid one. |
|
2493 | 2500 | |
|
2494 | 2501 | * IPython/iplib.py (InteractiveShell.interact): added a |
|
2495 | 2502 | showtraceback() call to the SystemExit trap, and modified the exit |
|
2496 | 2503 | confirmation to have yes as the default. |
|
2497 | 2504 | |
|
2498 | 2505 | * IPython/UserConfig/ipythonrc.py: removed 'session' option from |
|
2499 | 2506 | this file. It's been gone from the code for a long time, this was |
|
2500 | 2507 | simply leftover junk. |
|
2501 | 2508 | |
|
2502 | 2509 | 2002-11-01 Fernando Perez <fperez@colorado.edu> |
|
2503 | 2510 | |
|
2504 | 2511 | * IPython/UserConfig/ipythonrc.py: new confirm_exit option |
|
2505 | 2512 | added. If set, IPython now traps EOF and asks for |
|
2506 | 2513 | confirmation. After a request by François Pinard. |
|
2507 | 2514 | |
|
2508 | 2515 | * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead |
|
2509 | 2516 | of @abort, and with a new (better) mechanism for handling the |
|
2510 | 2517 | exceptions. |
|
2511 | 2518 | |
|
2512 | 2519 | 2002-10-27 Fernando Perez <fperez@colorado.edu> |
|
2513 | 2520 | |
|
2514 | 2521 | * IPython/usage.py (__doc__): updated the --help information and |
|
2515 | 2522 | the ipythonrc file to indicate that -log generates |
|
2516 | 2523 | ./ipython.log. Also fixed the corresponding info in @logstart. |
|
2517 | 2524 | This and several other fixes in the manuals thanks to reports by |
|
2518 | 2525 | François Pinard <pinard-AT-iro.umontreal.ca>. |
|
2519 | 2526 | |
|
2520 | 2527 | * IPython/Logger.py (Logger.switch_log): Fixed error message to |
|
2521 | 2528 | refer to @logstart (instead of @log, which doesn't exist). |
|
2522 | 2529 | |
|
2523 | 2530 | * IPython/iplib.py (InteractiveShell._prefilter): fixed |
|
2524 | 2531 | AttributeError crash. Thanks to Christopher Armstrong |
|
2525 | 2532 | <radix-AT-twistedmatrix.com> for the report/fix. This bug had been |
|
2526 | 2533 | introduced recently (in 0.2.14pre37) with the fix to the eval |
|
2527 | 2534 | problem mentioned below. |
|
2528 | 2535 | |
|
2529 | 2536 | 2002-10-17 Fernando Perez <fperez@colorado.edu> |
|
2530 | 2537 | |
|
2531 | 2538 | * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows |
|
2532 | 2539 | installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>. |
|
2533 | 2540 | |
|
2534 | 2541 | * IPython/iplib.py (InteractiveShell._prefilter): Many changes to |
|
2535 | 2542 | this function to fix a problem reported by Alex Schmolck. He saw |
|
2536 | 2543 | it with list comprehensions and generators, which were getting |
|
2537 | 2544 | called twice. The real problem was an 'eval' call in testing for |
|
2538 | 2545 | automagic which was evaluating the input line silently. |
|
2539 | 2546 | |
|
2540 | 2547 | This is a potentially very nasty bug, if the input has side |
|
2541 | 2548 | effects which must not be repeated. The code is much cleaner now, |
|
2542 | 2549 | without any blanket 'except' left and with a regexp test for |
|
2543 | 2550 | actual function names. |
|
2544 | 2551 | |
|
2545 | 2552 | But an eval remains, which I'm not fully comfortable with. I just |
|
2546 | 2553 | don't know how to find out if an expression could be a callable in |
|
2547 | 2554 | the user's namespace without doing an eval on the string. However |
|
2548 | 2555 | that string is now much more strictly checked so that no code |
|
2549 | 2556 | slips by, so the eval should only happen for things that can |
|
2550 | 2557 | really be only function/method names. |
|
2551 | 2558 | |
|
2552 | 2559 | 2002-10-15 Fernando Perez <fperez@colorado.edu> |
|
2553 | 2560 | |
|
2554 | 2561 | * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac |
|
2555 | 2562 | OSX information to main manual, removed README_Mac_OSX file from |
|
2556 | 2563 | distribution. Also updated credits for recent additions. |
|
2557 | 2564 | |
|
2558 | 2565 | 2002-10-10 Fernando Perez <fperez@colorado.edu> |
|
2559 | 2566 | |
|
2560 | 2567 | * README_Mac_OSX: Added a README for Mac OSX users for fixing |
|
2561 | 2568 | terminal-related issues. Many thanks to Andrea Riciputi |
|
2562 | 2569 | <andrea.riciputi-AT-libero.it> for writing it. |
|
2563 | 2570 | |
|
2564 | 2571 | * IPython/UserConfig/ipythonrc.py: Fixes to various small issues, |
|
2565 | 2572 | thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>. |
|
2566 | 2573 | |
|
2567 | 2574 | * setup.py (make_shortcut): Fixes for Windows installation. Thanks |
|
2568 | 2575 | to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad |
|
2569 | 2576 | <syver-en-AT-online.no> who both submitted patches for this problem. |
|
2570 | 2577 | |
|
2571 | 2578 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for |
|
2572 | 2579 | global embedding to make sure that things don't overwrite user |
|
2573 | 2580 | globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com> |
|
2574 | 2581 | |
|
2575 | 2582 | * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6 |
|
2576 | 2583 | compatibility. Thanks to Hayden Callow |
|
2577 | 2584 | <h.callow-AT-elec.canterbury.ac.nz> |
|
2578 | 2585 | |
|
2579 | 2586 | 2002-10-04 Fernando Perez <fperez@colorado.edu> |
|
2580 | 2587 | |
|
2581 | 2588 | * IPython/Gnuplot2.py (PlotItem): Added 'index' option for |
|
2582 | 2589 | Gnuplot.File objects. |
|
2583 | 2590 | |
|
2584 | 2591 | 2002-07-23 Fernando Perez <fperez@colorado.edu> |
|
2585 | 2592 | |
|
2586 | 2593 | * IPython/genutils.py (timing): Added timings() and timing() for |
|
2587 | 2594 | quick access to the most commonly needed data, the execution |
|
2588 | 2595 | times. Old timing() renamed to timings_out(). |
|
2589 | 2596 | |
|
2590 | 2597 | 2002-07-18 Fernando Perez <fperez@colorado.edu> |
|
2591 | 2598 | |
|
2592 | 2599 | * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed |
|
2593 | 2600 | bug with nested instances disrupting the parent's tab completion. |
|
2594 | 2601 | |
|
2595 | 2602 | * IPython/iplib.py (all_completions): Added Alex Schmolck's |
|
2596 | 2603 | all_completions code to begin the emacs integration. |
|
2597 | 2604 | |
|
2598 | 2605 | * IPython/Gnuplot2.py (zip_items): Added optional 'titles' |
|
2599 | 2606 | argument to allow titling individual arrays when plotting. |
|
2600 | 2607 | |
|
2601 | 2608 | 2002-07-15 Fernando Perez <fperez@colorado.edu> |
|
2602 | 2609 | |
|
2603 | 2610 | * setup.py (make_shortcut): changed to retrieve the value of |
|
2604 | 2611 | 'Program Files' directory from the registry (this value changes in |
|
2605 | 2612 | non-english versions of Windows). Thanks to Thomas Fanslau |
|
2606 | 2613 | <tfanslau-AT-gmx.de> for the report. |
|
2607 | 2614 | |
|
2608 | 2615 | 2002-07-10 Fernando Perez <fperez@colorado.edu> |
|
2609 | 2616 | |
|
2610 | 2617 | * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for |
|
2611 | 2618 | a bug in pdb, which crashes if a line with only whitespace is |
|
2612 | 2619 | entered. Bug report submitted to sourceforge. |
|
2613 | 2620 | |
|
2614 | 2621 | 2002-07-09 Fernando Perez <fperez@colorado.edu> |
|
2615 | 2622 | |
|
2616 | 2623 | * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when |
|
2617 | 2624 | reporting exceptions (it's a bug in inspect.py, I just set a |
|
2618 | 2625 | workaround). |
|
2619 | 2626 | |
|
2620 | 2627 | 2002-07-08 Fernando Perez <fperez@colorado.edu> |
|
2621 | 2628 | |
|
2622 | 2629 | * IPython/iplib.py (InteractiveShell.__init__): fixed reference to |
|
2623 | 2630 | __IPYTHON__ in __builtins__ to show up in user_ns. |
|
2624 | 2631 | |
|
2625 | 2632 | 2002-07-03 Fernando Perez <fperez@colorado.edu> |
|
2626 | 2633 | |
|
2627 | 2634 | * IPython/GnuplotInteractive.py (magic_gp_set_default): changed |
|
2628 | 2635 | name from @gp_set_instance to @gp_set_default. |
|
2629 | 2636 | |
|
2630 | 2637 | * IPython/ipmaker.py (make_IPython): default editor value set to |
|
2631 | 2638 | '0' (a string), to match the rc file. Otherwise will crash when |
|
2632 | 2639 | .strip() is called on it. |
|
2633 | 2640 | |
|
2634 | 2641 | |
|
2635 | 2642 | 2002-06-28 Fernando Perez <fperez@colorado.edu> |
|
2636 | 2643 | |
|
2637 | 2644 | * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing |
|
2638 | 2645 | of files in current directory when a file is executed via |
|
2639 | 2646 | @run. Patch also by RA <ralf_ahlbrink-AT-web.de>. |
|
2640 | 2647 | |
|
2641 | 2648 | * setup.py (manfiles): fix for rpm builds, submitted by RA |
|
2642 | 2649 | <ralf_ahlbrink-AT-web.de>. Now we have RPMs! |
|
2643 | 2650 | |
|
2644 | 2651 | * IPython/ipmaker.py (make_IPython): fixed lookup of default |
|
2645 | 2652 | editor when set to '0'. Problem was, '0' evaluates to True (it's a |
|
2646 | 2653 | string!). A. Schmolck caught this one. |
|
2647 | 2654 | |
|
2648 | 2655 | 2002-06-27 Fernando Perez <fperez@colorado.edu> |
|
2649 | 2656 | |
|
2650 | 2657 | * IPython/ipmaker.py (make_IPython): fixed bug when running user |
|
2651 | 2658 | defined files at the cmd line. __name__ wasn't being set to |
|
2652 | 2659 | __main__. |
|
2653 | 2660 | |
|
2654 | 2661 | * IPython/Gnuplot2.py (zip_items): improved it so it can plot also |
|
2655 | 2662 | regular lists and tuples besides Numeric arrays. |
|
2656 | 2663 | |
|
2657 | 2664 | * IPython/Prompts.py (CachedOutput.__call__): Added output |
|
2658 | 2665 | supression for input ending with ';'. Similar to Mathematica and |
|
2659 | 2666 | Matlab. The _* vars and Out[] list are still updated, just like |
|
2660 | 2667 | Mathematica behaves. |
|
2661 | 2668 | |
|
2662 | 2669 | 2002-06-25 Fernando Perez <fperez@colorado.edu> |
|
2663 | 2670 | |
|
2664 | 2671 | * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of |
|
2665 | 2672 | .ini extensions for profiels under Windows. |
|
2666 | 2673 | |
|
2667 | 2674 | * IPython/OInspect.py (Inspector.pinfo): improved alignment of |
|
2668 | 2675 | string form. Fix contributed by Alexander Schmolck |
|
2669 | 2676 | <a.schmolck-AT-gmx.net> |
|
2670 | 2677 | |
|
2671 | 2678 | * IPython/GnuplotRuntime.py (gp_new): new function. Returns a |
|
2672 | 2679 | pre-configured Gnuplot instance. |
|
2673 | 2680 | |
|
2674 | 2681 | 2002-06-21 Fernando Perez <fperez@colorado.edu> |
|
2675 | 2682 | |
|
2676 | 2683 | * IPython/numutils.py (exp_safe): new function, works around the |
|
2677 | 2684 | underflow problems in Numeric. |
|
2678 | 2685 | (log2): New fn. Safe log in base 2: returns exact integer answer |
|
2679 | 2686 | for exact integer powers of 2. |
|
2680 | 2687 | |
|
2681 | 2688 | * IPython/Magic.py (get_py_filename): fixed it not expanding '~' |
|
2682 | 2689 | properly. |
|
2683 | 2690 | |
|
2684 | 2691 | 2002-06-20 Fernando Perez <fperez@colorado.edu> |
|
2685 | 2692 | |
|
2686 | 2693 | * IPython/genutils.py (timing): new function like |
|
2687 | 2694 | Mathematica's. Similar to time_test, but returns more info. |
|
2688 | 2695 | |
|
2689 | 2696 | 2002-06-18 Fernando Perez <fperez@colorado.edu> |
|
2690 | 2697 | |
|
2691 | 2698 | * IPython/Magic.py (Magic.magic_save): modified @save and @r |
|
2692 | 2699 | according to Mike Heeter's suggestions. |
|
2693 | 2700 | |
|
2694 | 2701 | 2002-06-16 Fernando Perez <fperez@colorado.edu> |
|
2695 | 2702 | |
|
2696 | 2703 | * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot |
|
2697 | 2704 | system. GnuplotMagic is gone as a user-directory option. New files |
|
2698 | 2705 | make it easier to use all the gnuplot stuff both from external |
|
2699 | 2706 | programs as well as from IPython. Had to rewrite part of |
|
2700 | 2707 | hardcopy() b/c of a strange bug: often the ps files simply don't |
|
2701 | 2708 | get created, and require a repeat of the command (often several |
|
2702 | 2709 | times). |
|
2703 | 2710 | |
|
2704 | 2711 | * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to |
|
2705 | 2712 | resolve output channel at call time, so that if sys.stderr has |
|
2706 | 2713 | been redirected by user this gets honored. |
|
2707 | 2714 | |
|
2708 | 2715 | 2002-06-13 Fernando Perez <fperez@colorado.edu> |
|
2709 | 2716 | |
|
2710 | 2717 | * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to |
|
2711 | 2718 | IPShell. Kept a copy with the old names to avoid breaking people's |
|
2712 | 2719 | embedded code. |
|
2713 | 2720 | |
|
2714 | 2721 | * IPython/ipython: simplified it to the bare minimum after |
|
2715 | 2722 | Holger's suggestions. Added info about how to use it in |
|
2716 | 2723 | PYTHONSTARTUP. |
|
2717 | 2724 | |
|
2718 | 2725 | * IPython/Shell.py (IPythonShell): changed the options passing |
|
2719 | 2726 | from a string with funky %s replacements to a straight list. Maybe |
|
2720 | 2727 | a bit more typing, but it follows sys.argv conventions, so there's |
|
2721 | 2728 | less special-casing to remember. |
|
2722 | 2729 | |
|
2723 | 2730 | 2002-06-12 Fernando Perez <fperez@colorado.edu> |
|
2724 | 2731 | |
|
2725 | 2732 | * IPython/Magic.py (Magic.magic_r): new magic auto-repeat |
|
2726 | 2733 | command. Thanks to a suggestion by Mike Heeter. |
|
2727 | 2734 | (Magic.magic_pfile): added behavior to look at filenames if given |
|
2728 | 2735 | arg is not a defined object. |
|
2729 | 2736 | (Magic.magic_save): New @save function to save code snippets. Also |
|
2730 | 2737 | a Mike Heeter idea. |
|
2731 | 2738 | |
|
2732 | 2739 | * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to |
|
2733 | 2740 | plot() and replot(). Much more convenient now, especially for |
|
2734 | 2741 | interactive use. |
|
2735 | 2742 | |
|
2736 | 2743 | * IPython/Magic.py (Magic.magic_run): Added .py automatically to |
|
2737 | 2744 | filenames. |
|
2738 | 2745 | |
|
2739 | 2746 | 2002-06-02 Fernando Perez <fperez@colorado.edu> |
|
2740 | 2747 | |
|
2741 | 2748 | * IPython/Struct.py (Struct.__init__): modified to admit |
|
2742 | 2749 | initialization via another struct. |
|
2743 | 2750 | |
|
2744 | 2751 | * IPython/genutils.py (SystemExec.__init__): New stateful |
|
2745 | 2752 | interface to xsys and bq. Useful for writing system scripts. |
|
2746 | 2753 | |
|
2747 | 2754 | 2002-05-30 Fernando Perez <fperez@colorado.edu> |
|
2748 | 2755 | |
|
2749 | 2756 | * MANIFEST.in: Changed docfile selection to exclude all the lyx |
|
2750 | 2757 | documents. This will make the user download smaller (it's getting |
|
2751 | 2758 | too big). |
|
2752 | 2759 | |
|
2753 | 2760 | 2002-05-29 Fernando Perez <fperez@colorado.edu> |
|
2754 | 2761 | |
|
2755 | 2762 | * IPython/iplib.py (_FakeModule.__init__): New class introduced to |
|
2756 | 2763 | fix problems with shelve and pickle. Seems to work, but I don't |
|
2757 | 2764 | know if corner cases break it. Thanks to Mike Heeter |
|
2758 | 2765 | <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases. |
|
2759 | 2766 | |
|
2760 | 2767 | 2002-05-24 Fernando Perez <fperez@colorado.edu> |
|
2761 | 2768 | |
|
2762 | 2769 | * IPython/Magic.py (Macro.__init__): fixed magics embedded in |
|
2763 | 2770 | macros having broken. |
|
2764 | 2771 | |
|
2765 | 2772 | 2002-05-21 Fernando Perez <fperez@colorado.edu> |
|
2766 | 2773 | |
|
2767 | 2774 | * IPython/Magic.py (Magic.magic_logstart): fixed recently |
|
2768 | 2775 | introduced logging bug: all history before logging started was |
|
2769 | 2776 | being written one character per line! This came from the redesign |
|
2770 | 2777 | of the input history as a special list which slices to strings, |
|
2771 | 2778 | not to lists. |
|
2772 | 2779 | |
|
2773 | 2780 | 2002-05-20 Fernando Perez <fperez@colorado.edu> |
|
2774 | 2781 | |
|
2775 | 2782 | * IPython/Prompts.py (CachedOutput.__init__): made the color table |
|
2776 | 2783 | be an attribute of all classes in this module. The design of these |
|
2777 | 2784 | classes needs some serious overhauling. |
|
2778 | 2785 | |
|
2779 | 2786 | * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug |
|
2780 | 2787 | which was ignoring '_' in option names. |
|
2781 | 2788 | |
|
2782 | 2789 | * IPython/ultraTB.py (FormattedTB.__init__): Changed |
|
2783 | 2790 | 'Verbose_novars' to 'Context' and made it the new default. It's a |
|
2784 | 2791 | bit more readable and also safer than verbose. |
|
2785 | 2792 | |
|
2786 | 2793 | * IPython/PyColorize.py (Parser.__call__): Fixed coloring of |
|
2787 | 2794 | triple-quoted strings. |
|
2788 | 2795 | |
|
2789 | 2796 | * IPython/OInspect.py (__all__): new module exposing the object |
|
2790 | 2797 | introspection facilities. Now the corresponding magics are dummy |
|
2791 | 2798 | wrappers around this. Having this module will make it much easier |
|
2792 | 2799 | to put these functions into our modified pdb. |
|
2793 | 2800 | This new object inspector system uses the new colorizing module, |
|
2794 | 2801 | so source code and other things are nicely syntax highlighted. |
|
2795 | 2802 | |
|
2796 | 2803 | 2002-05-18 Fernando Perez <fperez@colorado.edu> |
|
2797 | 2804 | |
|
2798 | 2805 | * IPython/ColorANSI.py: Split the coloring tools into a separate |
|
2799 | 2806 | module so I can use them in other code easier (they were part of |
|
2800 | 2807 | ultraTB). |
|
2801 | 2808 | |
|
2802 | 2809 | 2002-05-17 Fernando Perez <fperez@colorado.edu> |
|
2803 | 2810 | |
|
2804 | 2811 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2805 | 2812 | fixed it to set the global 'g' also to the called instance, as |
|
2806 | 2813 | long as 'g' was still a gnuplot instance (so it doesn't overwrite |
|
2807 | 2814 | user's 'g' variables). |
|
2808 | 2815 | |
|
2809 | 2816 | * IPython/iplib.py (InteractiveShell.__init__): Added In/Out |
|
2810 | 2817 | global variables (aliases to _ih,_oh) so that users which expect |
|
2811 | 2818 | In[5] or Out[7] to work aren't unpleasantly surprised. |
|
2812 | 2819 | (InputList.__getslice__): new class to allow executing slices of |
|
2813 | 2820 | input history directly. Very simple class, complements the use of |
|
2814 | 2821 | macros. |
|
2815 | 2822 | |
|
2816 | 2823 | 2002-05-16 Fernando Perez <fperez@colorado.edu> |
|
2817 | 2824 | |
|
2818 | 2825 | * setup.py (docdirbase): make doc directory be just doc/IPython |
|
2819 | 2826 | without version numbers, it will reduce clutter for users. |
|
2820 | 2827 | |
|
2821 | 2828 | * IPython/Magic.py (Magic.magic_run): Add explicit local dict to |
|
2822 | 2829 | execfile call to prevent possible memory leak. See for details: |
|
2823 | 2830 | http://mail.python.org/pipermail/python-list/2002-February/088476.html |
|
2824 | 2831 | |
|
2825 | 2832 | 2002-05-15 Fernando Perez <fperez@colorado.edu> |
|
2826 | 2833 | |
|
2827 | 2834 | * IPython/Magic.py (Magic.magic_psource): made the object |
|
2828 | 2835 | introspection names be more standard: pdoc, pdef, pfile and |
|
2829 | 2836 | psource. They all print/page their output, and it makes |
|
2830 | 2837 | remembering them easier. Kept old names for compatibility as |
|
2831 | 2838 | aliases. |
|
2832 | 2839 | |
|
2833 | 2840 | 2002-05-14 Fernando Perez <fperez@colorado.edu> |
|
2834 | 2841 | |
|
2835 | 2842 | * IPython/UserConfig/GnuplotMagic.py: I think I finally understood |
|
2836 | 2843 | what the mouse problem was. The trick is to use gnuplot with temp |
|
2837 | 2844 | files and NOT with pipes (for data communication), because having |
|
2838 | 2845 | both pipes and the mouse on is bad news. |
|
2839 | 2846 | |
|
2840 | 2847 | 2002-05-13 Fernando Perez <fperez@colorado.edu> |
|
2841 | 2848 | |
|
2842 | 2849 | * IPython/Magic.py (Magic._ofind): fixed namespace order search |
|
2843 | 2850 | bug. Information would be reported about builtins even when |
|
2844 | 2851 | user-defined functions overrode them. |
|
2845 | 2852 | |
|
2846 | 2853 | 2002-05-11 Fernando Perez <fperez@colorado.edu> |
|
2847 | 2854 | |
|
2848 | 2855 | * IPython/__init__.py (__all__): removed FlexCompleter from |
|
2849 | 2856 | __all__ so that things don't fail in platforms without readline. |
|
2850 | 2857 | |
|
2851 | 2858 | 2002-05-10 Fernando Perez <fperez@colorado.edu> |
|
2852 | 2859 | |
|
2853 | 2860 | * IPython/__init__.py (__all__): removed numutils from __all__ b/c |
|
2854 | 2861 | it requires Numeric, effectively making Numeric a dependency for |
|
2855 | 2862 | IPython. |
|
2856 | 2863 | |
|
2857 | 2864 | * Released 0.2.13 |
|
2858 | 2865 | |
|
2859 | 2866 | * IPython/Magic.py (Magic.magic_prun): big overhaul to the |
|
2860 | 2867 | profiler interface. Now all the major options from the profiler |
|
2861 | 2868 | module are directly supported in IPython, both for single |
|
2862 | 2869 | expressions (@prun) and for full programs (@run -p). |
|
2863 | 2870 | |
|
2864 | 2871 | 2002-05-09 Fernando Perez <fperez@colorado.edu> |
|
2865 | 2872 | |
|
2866 | 2873 | * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of |
|
2867 | 2874 | magic properly formatted for screen. |
|
2868 | 2875 | |
|
2869 | 2876 | * setup.py (make_shortcut): Changed things to put pdf version in |
|
2870 | 2877 | doc/ instead of doc/manual (had to change lyxport a bit). |
|
2871 | 2878 | |
|
2872 | 2879 | * IPython/Magic.py (Profile.string_stats): made profile runs go |
|
2873 | 2880 | through pager (they are long and a pager allows searching, saving, |
|
2874 | 2881 | etc.) |
|
2875 | 2882 | |
|
2876 | 2883 | 2002-05-08 Fernando Perez <fperez@colorado.edu> |
|
2877 | 2884 | |
|
2878 | 2885 | * Released 0.2.12 |
|
2879 | 2886 | |
|
2880 | 2887 | 2002-05-06 Fernando Perez <fperez@colorado.edu> |
|
2881 | 2888 | |
|
2882 | 2889 | * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently |
|
2883 | 2890 | introduced); 'hist n1 n2' was broken. |
|
2884 | 2891 | (Magic.magic_pdb): added optional on/off arguments to @pdb |
|
2885 | 2892 | (Magic.magic_run): added option -i to @run, which executes code in |
|
2886 | 2893 | the IPython namespace instead of a clean one. Also added @irun as |
|
2887 | 2894 | an alias to @run -i. |
|
2888 | 2895 | |
|
2889 | 2896 | * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance): |
|
2890 | 2897 | fixed (it didn't really do anything, the namespaces were wrong). |
|
2891 | 2898 | |
|
2892 | 2899 | * IPython/Debugger.py (__init__): Added workaround for python 2.1 |
|
2893 | 2900 | |
|
2894 | 2901 | * IPython/__init__.py (__all__): Fixed package namespace, now |
|
2895 | 2902 | 'import IPython' does give access to IPython.<all> as |
|
2896 | 2903 | expected. Also renamed __release__ to Release. |
|
2897 | 2904 | |
|
2898 | 2905 | * IPython/Debugger.py (__license__): created new Pdb class which |
|
2899 | 2906 | functions like a drop-in for the normal pdb.Pdb but does NOT |
|
2900 | 2907 | import readline by default. This way it doesn't muck up IPython's |
|
2901 | 2908 | readline handling, and now tab-completion finally works in the |
|
2902 | 2909 | debugger -- sort of. It completes things globally visible, but the |
|
2903 | 2910 | completer doesn't track the stack as pdb walks it. That's a bit |
|
2904 | 2911 | tricky, and I'll have to implement it later. |
|
2905 | 2912 | |
|
2906 | 2913 | 2002-05-05 Fernando Perez <fperez@colorado.edu> |
|
2907 | 2914 | |
|
2908 | 2915 | * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for |
|
2909 | 2916 | magic docstrings when printed via ? (explicit \'s were being |
|
2910 | 2917 | printed). |
|
2911 | 2918 | |
|
2912 | 2919 | * IPython/ipmaker.py (make_IPython): fixed namespace |
|
2913 | 2920 | identification bug. Now variables loaded via logs or command-line |
|
2914 | 2921 | files are recognized in the interactive namespace by @who. |
|
2915 | 2922 | |
|
2916 | 2923 | * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in |
|
2917 | 2924 | log replay system stemming from the string form of Structs. |
|
2918 | 2925 | |
|
2919 | 2926 | * IPython/Magic.py (Macro.__init__): improved macros to properly |
|
2920 | 2927 | handle magic commands in them. |
|
2921 | 2928 | (Magic.magic_logstart): usernames are now expanded so 'logstart |
|
2922 | 2929 | ~/mylog' now works. |
|
2923 | 2930 | |
|
2924 | 2931 | * IPython/iplib.py (complete): fixed bug where paths starting with |
|
2925 | 2932 | '/' would be completed as magic names. |
|
2926 | 2933 | |
|
2927 | 2934 | 2002-05-04 Fernando Perez <fperez@colorado.edu> |
|
2928 | 2935 | |
|
2929 | 2936 | * IPython/Magic.py (Magic.magic_run): added options -p and -f to |
|
2930 | 2937 | allow running full programs under the profiler's control. |
|
2931 | 2938 | |
|
2932 | 2939 | * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars |
|
2933 | 2940 | mode to report exceptions verbosely but without formatting |
|
2934 | 2941 | variables. This addresses the issue of ipython 'freezing' (it's |
|
2935 | 2942 | not frozen, but caught in an expensive formatting loop) when huge |
|
2936 | 2943 | variables are in the context of an exception. |
|
2937 | 2944 | (VerboseTB.text): Added '--->' markers at line where exception was |
|
2938 | 2945 | triggered. Much clearer to read, especially in NoColor modes. |
|
2939 | 2946 | |
|
2940 | 2947 | * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been |
|
2941 | 2948 | implemented in reverse when changing to the new parse_options(). |
|
2942 | 2949 | |
|
2943 | 2950 | 2002-05-03 Fernando Perez <fperez@colorado.edu> |
|
2944 | 2951 | |
|
2945 | 2952 | * IPython/Magic.py (Magic.parse_options): new function so that |
|
2946 | 2953 | magics can parse options easier. |
|
2947 | 2954 | (Magic.magic_prun): new function similar to profile.run(), |
|
2948 | 2955 | suggested by Chris Hart. |
|
2949 | 2956 | (Magic.magic_cd): fixed behavior so that it only changes if |
|
2950 | 2957 | directory actually is in history. |
|
2951 | 2958 | |
|
2952 | 2959 | * IPython/usage.py (__doc__): added information about potential |
|
2953 | 2960 | slowness of Verbose exception mode when there are huge data |
|
2954 | 2961 | structures to be formatted (thanks to Archie Paulson). |
|
2955 | 2962 | |
|
2956 | 2963 | * IPython/ipmaker.py (make_IPython): Changed default logging |
|
2957 | 2964 | (when simply called with -log) to use curr_dir/ipython.log in |
|
2958 | 2965 | rotate mode. Fixed crash which was occuring with -log before |
|
2959 | 2966 | (thanks to Jim Boyle). |
|
2960 | 2967 | |
|
2961 | 2968 | 2002-05-01 Fernando Perez <fperez@colorado.edu> |
|
2962 | 2969 | |
|
2963 | 2970 | * Released 0.2.11 for these fixes (mainly the ultraTB one which |
|
2964 | 2971 | was nasty -- though somewhat of a corner case). |
|
2965 | 2972 | |
|
2966 | 2973 | * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to |
|
2967 | 2974 | text (was a bug). |
|
2968 | 2975 | |
|
2969 | 2976 | 2002-04-30 Fernando Perez <fperez@colorado.edu> |
|
2970 | 2977 | |
|
2971 | 2978 | * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add |
|
2972 | 2979 | a print after ^D or ^C from the user so that the In[] prompt |
|
2973 | 2980 | doesn't over-run the gnuplot one. |
|
2974 | 2981 | |
|
2975 | 2982 | 2002-04-29 Fernando Perez <fperez@colorado.edu> |
|
2976 | 2983 | |
|
2977 | 2984 | * Released 0.2.10 |
|
2978 | 2985 | |
|
2979 | 2986 | * IPython/__release__.py (version): get date dynamically. |
|
2980 | 2987 | |
|
2981 | 2988 | * Misc. documentation updates thanks to Arnd's comments. Also ran |
|
2982 | 2989 | a full spellcheck on the manual (hadn't been done in a while). |
|
2983 | 2990 | |
|
2984 | 2991 | 2002-04-27 Fernando Perez <fperez@colorado.edu> |
|
2985 | 2992 | |
|
2986 | 2993 | * IPython/Magic.py (Magic.magic_logstart): Fixed bug where |
|
2987 | 2994 | starting a log in mid-session would reset the input history list. |
|
2988 | 2995 | |
|
2989 | 2996 | 2002-04-26 Fernando Perez <fperez@colorado.edu> |
|
2990 | 2997 | |
|
2991 | 2998 | * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not |
|
2992 | 2999 | all files were being included in an update. Now anything in |
|
2993 | 3000 | UserConfig that matches [A-Za-z]*.py will go (this excludes |
|
2994 | 3001 | __init__.py) |
|
2995 | 3002 | |
|
2996 | 3003 | 2002-04-25 Fernando Perez <fperez@colorado.edu> |
|
2997 | 3004 | |
|
2998 | 3005 | * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__ |
|
2999 | 3006 | to __builtins__ so that any form of embedded or imported code can |
|
3000 | 3007 | test for being inside IPython. |
|
3001 | 3008 | |
|
3002 | 3009 | * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance): |
|
3003 | 3010 | changed to GnuplotMagic because it's now an importable module, |
|
3004 | 3011 | this makes the name follow that of the standard Gnuplot module. |
|
3005 | 3012 | GnuplotMagic can now be loaded at any time in mid-session. |
|
3006 | 3013 | |
|
3007 | 3014 | 2002-04-24 Fernando Perez <fperez@colorado.edu> |
|
3008 | 3015 | |
|
3009 | 3016 | * IPython/numutils.py: removed SIUnits. It doesn't properly set |
|
3010 | 3017 | the globals (IPython has its own namespace) and the |
|
3011 | 3018 | PhysicalQuantity stuff is much better anyway. |
|
3012 | 3019 | |
|
3013 | 3020 | * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot |
|
3014 | 3021 | embedding example to standard user directory for |
|
3015 | 3022 | distribution. Also put it in the manual. |
|
3016 | 3023 | |
|
3017 | 3024 | * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot |
|
3018 | 3025 | instance as first argument (so it doesn't rely on some obscure |
|
3019 | 3026 | hidden global). |
|
3020 | 3027 | |
|
3021 | 3028 | * IPython/UserConfig/ipythonrc.py: put () back in accepted |
|
3022 | 3029 | delimiters. While it prevents ().TAB from working, it allows |
|
3023 | 3030 | completions in open (... expressions. This is by far a more common |
|
3024 | 3031 | case. |
|
3025 | 3032 | |
|
3026 | 3033 | 2002-04-23 Fernando Perez <fperez@colorado.edu> |
|
3027 | 3034 | |
|
3028 | 3035 | * IPython/Extensions/InterpreterPasteInput.py: new |
|
3029 | 3036 | syntax-processing module for pasting lines with >>> or ... at the |
|
3030 | 3037 | start. |
|
3031 | 3038 | |
|
3032 | 3039 | * IPython/Extensions/PhysicalQ_Interactive.py |
|
3033 | 3040 | (PhysicalQuantityInteractive.__int__): fixed to work with either |
|
3034 | 3041 | Numeric or math. |
|
3035 | 3042 | |
|
3036 | 3043 | * IPython/UserConfig/ipythonrc-numeric.py: reorganized the |
|
3037 | 3044 | provided profiles. Now we have: |
|
3038 | 3045 | -math -> math module as * and cmath with its own namespace. |
|
3039 | 3046 | -numeric -> Numeric as *, plus gnuplot & grace |
|
3040 | 3047 | -physics -> same as before |
|
3041 | 3048 | |
|
3042 | 3049 | * IPython/Magic.py (Magic.magic_magic): Fixed bug where |
|
3043 | 3050 | user-defined magics wouldn't be found by @magic if they were |
|
3044 | 3051 | defined as class methods. Also cleaned up the namespace search |
|
3045 | 3052 | logic and the string building (to use %s instead of many repeated |
|
3046 | 3053 | string adds). |
|
3047 | 3054 | |
|
3048 | 3055 | * IPython/UserConfig/example-magic.py (magic_foo): updated example |
|
3049 | 3056 | of user-defined magics to operate with class methods (cleaner, in |
|
3050 | 3057 | line with the gnuplot code). |
|
3051 | 3058 | |
|
3052 | 3059 | 2002-04-22 Fernando Perez <fperez@colorado.edu> |
|
3053 | 3060 | |
|
3054 | 3061 | * setup.py: updated dependency list so that manual is updated when |
|
3055 | 3062 | all included files change. |
|
3056 | 3063 | |
|
3057 | 3064 | * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring |
|
3058 | 3065 | the delimiter removal option (the fix is ugly right now). |
|
3059 | 3066 | |
|
3060 | 3067 | * IPython/UserConfig/ipythonrc-physics.py: simplified not to load |
|
3061 | 3068 | all of the math profile (quicker loading, no conflict between |
|
3062 | 3069 | g-9.8 and g-gnuplot). |
|
3063 | 3070 | |
|
3064 | 3071 | * IPython/CrashHandler.py (CrashHandler.__call__): changed default |
|
3065 | 3072 | name of post-mortem files to IPython_crash_report.txt. |
|
3066 | 3073 | |
|
3067 | 3074 | * Cleanup/update of the docs. Added all the new readline info and |
|
3068 | 3075 | formatted all lists as 'real lists'. |
|
3069 | 3076 | |
|
3070 | 3077 | * IPython/ipmaker.py (make_IPython): removed now-obsolete |
|
3071 | 3078 | tab-completion options, since the full readline parse_and_bind is |
|
3072 | 3079 | now accessible. |
|
3073 | 3080 | |
|
3074 | 3081 | * IPython/iplib.py (InteractiveShell.init_readline): Changed |
|
3075 | 3082 | handling of readline options. Now users can specify any string to |
|
3076 | 3083 | be passed to parse_and_bind(), as well as the delimiters to be |
|
3077 | 3084 | removed. |
|
3078 | 3085 | (InteractiveShell.__init__): Added __name__ to the global |
|
3079 | 3086 | namespace so that things like Itpl which rely on its existence |
|
3080 | 3087 | don't crash. |
|
3081 | 3088 | (InteractiveShell._prefilter): Defined the default with a _ so |
|
3082 | 3089 | that prefilter() is easier to override, while the default one |
|
3083 | 3090 | remains available. |
|
3084 | 3091 | |
|
3085 | 3092 | 2002-04-18 Fernando Perez <fperez@colorado.edu> |
|
3086 | 3093 | |
|
3087 | 3094 | * Added information about pdb in the docs. |
|
3088 | 3095 | |
|
3089 | 3096 | 2002-04-17 Fernando Perez <fperez@colorado.edu> |
|
3090 | 3097 | |
|
3091 | 3098 | * IPython/ipmaker.py (make_IPython): added rc_override option to |
|
3092 | 3099 | allow passing config options at creation time which may override |
|
3093 | 3100 | anything set in the config files or command line. This is |
|
3094 | 3101 | particularly useful for configuring embedded instances. |
|
3095 | 3102 | |
|
3096 | 3103 | 2002-04-15 Fernando Perez <fperez@colorado.edu> |
|
3097 | 3104 | |
|
3098 | 3105 | * IPython/Logger.py (Logger.log): Fixed a nasty bug which could |
|
3099 | 3106 | crash embedded instances because of the input cache falling out of |
|
3100 | 3107 | sync with the output counter. |
|
3101 | 3108 | |
|
3102 | 3109 | * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug |
|
3103 | 3110 | mode which calls pdb after an uncaught exception in IPython itself. |
|
3104 | 3111 | |
|
3105 | 3112 | 2002-04-14 Fernando Perez <fperez@colorado.edu> |
|
3106 | 3113 | |
|
3107 | 3114 | * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up |
|
3108 | 3115 | readline, fix it back after each call. |
|
3109 | 3116 | |
|
3110 | 3117 | * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private |
|
3111 | 3118 | method to force all access via __call__(), which guarantees that |
|
3112 | 3119 | traceback references are properly deleted. |
|
3113 | 3120 | |
|
3114 | 3121 | * IPython/Prompts.py (CachedOutput._display): minor fixes to |
|
3115 | 3122 | improve printing when pprint is in use. |
|
3116 | 3123 | |
|
3117 | 3124 | 2002-04-13 Fernando Perez <fperez@colorado.edu> |
|
3118 | 3125 | |
|
3119 | 3126 | * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit |
|
3120 | 3127 | exceptions aren't caught anymore. If the user triggers one, he |
|
3121 | 3128 | should know why he's doing it and it should go all the way up, |
|
3122 | 3129 | just like any other exception. So now @abort will fully kill the |
|
3123 | 3130 | embedded interpreter and the embedding code (unless that happens |
|
3124 | 3131 | to catch SystemExit). |
|
3125 | 3132 | |
|
3126 | 3133 | * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag |
|
3127 | 3134 | and a debugger() method to invoke the interactive pdb debugger |
|
3128 | 3135 | after printing exception information. Also added the corresponding |
|
3129 | 3136 | -pdb option and @pdb magic to control this feature, and updated |
|
3130 | 3137 | the docs. After a suggestion from Christopher Hart |
|
3131 | 3138 | (hart-AT-caltech.edu). |
|
3132 | 3139 | |
|
3133 | 3140 | 2002-04-12 Fernando Perez <fperez@colorado.edu> |
|
3134 | 3141 | |
|
3135 | 3142 | * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use |
|
3136 | 3143 | the exception handlers defined by the user (not the CrashHandler) |
|
3137 | 3144 | so that user exceptions don't trigger an ipython bug report. |
|
3138 | 3145 | |
|
3139 | 3146 | * IPython/ultraTB.py (ColorTB.__init__): made the color scheme |
|
3140 | 3147 | configurable (it should have always been so). |
|
3141 | 3148 | |
|
3142 | 3149 | 2002-03-26 Fernando Perez <fperez@colorado.edu> |
|
3143 | 3150 | |
|
3144 | 3151 | * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here |
|
3145 | 3152 | and there to fix embedding namespace issues. This should all be |
|
3146 | 3153 | done in a more elegant way. |
|
3147 | 3154 | |
|
3148 | 3155 | 2002-03-25 Fernando Perez <fperez@colorado.edu> |
|
3149 | 3156 | |
|
3150 | 3157 | * IPython/genutils.py (get_home_dir): Try to make it work under |
|
3151 | 3158 | win9x also. |
|
3152 | 3159 | |
|
3153 | 3160 | 2002-03-20 Fernando Perez <fperez@colorado.edu> |
|
3154 | 3161 | |
|
3155 | 3162 | * IPython/Shell.py (IPythonShellEmbed.__init__): leave |
|
3156 | 3163 | sys.displayhook untouched upon __init__. |
|
3157 | 3164 | |
|
3158 | 3165 | 2002-03-19 Fernando Perez <fperez@colorado.edu> |
|
3159 | 3166 | |
|
3160 | 3167 | * Released 0.2.9 (for embedding bug, basically). |
|
3161 | 3168 | |
|
3162 | 3169 | * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit |
|
3163 | 3170 | exceptions so that enclosing shell's state can be restored. |
|
3164 | 3171 | |
|
3165 | 3172 | * Changed magic_gnuplot.py to magic-gnuplot.py to standardize |
|
3166 | 3173 | naming conventions in the .ipython/ dir. |
|
3167 | 3174 | |
|
3168 | 3175 | * IPython/iplib.py (InteractiveShell.init_readline): removed '-' |
|
3169 | 3176 | from delimiters list so filenames with - in them get expanded. |
|
3170 | 3177 | |
|
3171 | 3178 | * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with |
|
3172 | 3179 | sys.displayhook not being properly restored after an embedded call. |
|
3173 | 3180 | |
|
3174 | 3181 | 2002-03-18 Fernando Perez <fperez@colorado.edu> |
|
3175 | 3182 | |
|
3176 | 3183 | * Released 0.2.8 |
|
3177 | 3184 | |
|
3178 | 3185 | * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where |
|
3179 | 3186 | some files weren't being included in a -upgrade. |
|
3180 | 3187 | (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous |
|
3181 | 3188 | on' so that the first tab completes. |
|
3182 | 3189 | (InteractiveShell.handle_magic): fixed bug with spaces around |
|
3183 | 3190 | quotes breaking many magic commands. |
|
3184 | 3191 | |
|
3185 | 3192 | * setup.py: added note about ignoring the syntax error messages at |
|
3186 | 3193 | installation. |
|
3187 | 3194 | |
|
3188 | 3195 | * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished |
|
3189 | 3196 | streamlining the gnuplot interface, now there's only one magic @gp. |
|
3190 | 3197 | |
|
3191 | 3198 | 2002-03-17 Fernando Perez <fperez@colorado.edu> |
|
3192 | 3199 | |
|
3193 | 3200 | * IPython/UserConfig/magic_gnuplot.py: new name for the |
|
3194 | 3201 | example-magic_pm.py file. Much enhanced system, now with a shell |
|
3195 | 3202 | for communicating directly with gnuplot, one command at a time. |
|
3196 | 3203 | |
|
3197 | 3204 | * IPython/Magic.py (Magic.magic_run): added option -n to prevent |
|
3198 | 3205 | setting __name__=='__main__'. |
|
3199 | 3206 | |
|
3200 | 3207 | * IPython/UserConfig/example-magic_pm.py (magic_pm): Added |
|
3201 | 3208 | mini-shell for accessing gnuplot from inside ipython. Should |
|
3202 | 3209 | extend it later for grace access too. Inspired by Arnd's |
|
3203 | 3210 | suggestion. |
|
3204 | 3211 | |
|
3205 | 3212 | * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when |
|
3206 | 3213 | calling magic functions with () in their arguments. Thanks to Arnd |
|
3207 | 3214 | Baecker for pointing this to me. |
|
3208 | 3215 | |
|
3209 | 3216 | * IPython/numutils.py (sum_flat): fixed bug. Would recurse |
|
3210 | 3217 | infinitely for integer or complex arrays (only worked with floats). |
|
3211 | 3218 | |
|
3212 | 3219 | 2002-03-16 Fernando Perez <fperez@colorado.edu> |
|
3213 | 3220 | |
|
3214 | 3221 | * setup.py: Merged setup and setup_windows into a single script |
|
3215 | 3222 | which properly handles things for windows users. |
|
3216 | 3223 | |
|
3217 | 3224 | 2002-03-15 Fernando Perez <fperez@colorado.edu> |
|
3218 | 3225 | |
|
3219 | 3226 | * Big change to the manual: now the magics are all automatically |
|
3220 | 3227 | documented. This information is generated from their docstrings |
|
3221 | 3228 | and put in a latex file included by the manual lyx file. This way |
|
3222 | 3229 | we get always up to date information for the magics. The manual |
|
3223 | 3230 | now also has proper version information, also auto-synced. |
|
3224 | 3231 | |
|
3225 | 3232 | For this to work, an undocumented --magic_docstrings option was added. |
|
3226 | 3233 | |
|
3227 | 3234 | 2002-03-13 Fernando Perez <fperez@colorado.edu> |
|
3228 | 3235 | |
|
3229 | 3236 | * IPython/ultraTB.py (TermColors): fixed problem with dark colors |
|
3230 | 3237 | under CDE terminals. An explicit ;2 color reset is needed in the escapes. |
|
3231 | 3238 | |
|
3232 | 3239 | 2002-03-12 Fernando Perez <fperez@colorado.edu> |
|
3233 | 3240 | |
|
3234 | 3241 | * IPython/ultraTB.py (TermColors): changed color escapes again to |
|
3235 | 3242 | fix the (old, reintroduced) line-wrapping bug. Basically, if |
|
3236 | 3243 | \001..\002 aren't given in the color escapes, lines get wrapped |
|
3237 | 3244 | weirdly. But giving those screws up old xterms and emacs terms. So |
|
3238 | 3245 | I added some logic for emacs terms to be ok, but I can't identify old |
|
3239 | 3246 | xterms separately ($TERM=='xterm' for many terminals, like konsole). |
|
3240 | 3247 | |
|
3241 | 3248 | 2002-03-10 Fernando Perez <fperez@colorado.edu> |
|
3242 | 3249 | |
|
3243 | 3250 | * IPython/usage.py (__doc__): Various documentation cleanups and |
|
3244 | 3251 | updates, both in usage docstrings and in the manual. |
|
3245 | 3252 | |
|
3246 | 3253 | * IPython/Prompts.py (CachedOutput.set_colors): cleanups for |
|
3247 | 3254 | handling of caching. Set minimum acceptabe value for having a |
|
3248 | 3255 | cache at 20 values. |
|
3249 | 3256 | |
|
3250 | 3257 | * IPython/iplib.py (InteractiveShell.user_setup): moved the |
|
3251 | 3258 | install_first_time function to a method, renamed it and added an |
|
3252 | 3259 | 'upgrade' mode. Now people can update their config directory with |
|
3253 | 3260 | a simple command line switch (-upgrade, also new). |
|
3254 | 3261 | |
|
3255 | 3262 | * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to |
|
3256 | 3263 | @file (convenient for automagic users under Python >= 2.2). |
|
3257 | 3264 | Removed @files (it seemed more like a plural than an abbrev. of |
|
3258 | 3265 | 'file show'). |
|
3259 | 3266 | |
|
3260 | 3267 | * IPython/iplib.py (install_first_time): Fixed crash if there were |
|
3261 | 3268 | backup files ('~') in .ipython/ install directory. |
|
3262 | 3269 | |
|
3263 | 3270 | * IPython/ipmaker.py (make_IPython): fixes for new prompt |
|
3264 | 3271 | system. Things look fine, but these changes are fairly |
|
3265 | 3272 | intrusive. Test them for a few days. |
|
3266 | 3273 | |
|
3267 | 3274 | * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of |
|
3268 | 3275 | the prompts system. Now all in/out prompt strings are user |
|
3269 | 3276 | controllable. This is particularly useful for embedding, as one |
|
3270 | 3277 | can tag embedded instances with particular prompts. |
|
3271 | 3278 | |
|
3272 | 3279 | Also removed global use of sys.ps1/2, which now allows nested |
|
3273 | 3280 | embeddings without any problems. Added command-line options for |
|
3274 | 3281 | the prompt strings. |
|
3275 | 3282 | |
|
3276 | 3283 | 2002-03-08 Fernando Perez <fperez@colorado.edu> |
|
3277 | 3284 | |
|
3278 | 3285 | * IPython/UserConfig/example-embed-short.py (ipshell): added |
|
3279 | 3286 | example file with the bare minimum code for embedding. |
|
3280 | 3287 | |
|
3281 | 3288 | * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added |
|
3282 | 3289 | functionality for the embeddable shell to be activated/deactivated |
|
3283 | 3290 | either globally or at each call. |
|
3284 | 3291 | |
|
3285 | 3292 | * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of |
|
3286 | 3293 | rewriting the prompt with '--->' for auto-inputs with proper |
|
3287 | 3294 | coloring. Now the previous UGLY hack in handle_auto() is gone, and |
|
3288 | 3295 | this is handled by the prompts class itself, as it should. |
|
3289 | 3296 | |
|
3290 | 3297 | 2002-03-05 Fernando Perez <fperez@colorado.edu> |
|
3291 | 3298 | |
|
3292 | 3299 | * IPython/Magic.py (Magic.magic_logstart): Changed @log to |
|
3293 | 3300 | @logstart to avoid name clashes with the math log function. |
|
3294 | 3301 | |
|
3295 | 3302 | * Big updates to X/Emacs section of the manual. |
|
3296 | 3303 | |
|
3297 | 3304 | * Removed ipython_emacs. Milan explained to me how to pass |
|
3298 | 3305 | arguments to ipython through Emacs. Some day I'm going to end up |
|
3299 | 3306 | learning some lisp... |
|
3300 | 3307 | |
|
3301 | 3308 | 2002-03-04 Fernando Perez <fperez@colorado.edu> |
|
3302 | 3309 | |
|
3303 | 3310 | * IPython/ipython_emacs: Created script to be used as the |
|
3304 | 3311 | py-python-command Emacs variable so we can pass IPython |
|
3305 | 3312 | parameters. I can't figure out how to tell Emacs directly to pass |
|
3306 | 3313 | parameters to IPython, so a dummy shell script will do it. |
|
3307 | 3314 | |
|
3308 | 3315 | Other enhancements made for things to work better under Emacs' |
|
3309 | 3316 | various types of terminals. Many thanks to Milan Zamazal |
|
3310 | 3317 | <pdm-AT-zamazal.org> for all the suggestions and pointers. |
|
3311 | 3318 | |
|
3312 | 3319 | 2002-03-01 Fernando Perez <fperez@colorado.edu> |
|
3313 | 3320 | |
|
3314 | 3321 | * IPython/ipmaker.py (make_IPython): added a --readline! option so |
|
3315 | 3322 | that loading of readline is now optional. This gives better |
|
3316 | 3323 | control to emacs users. |
|
3317 | 3324 | |
|
3318 | 3325 | * IPython/ultraTB.py (__date__): Modified color escape sequences |
|
3319 | 3326 | and now things work fine under xterm and in Emacs' term buffers |
|
3320 | 3327 | (though not shell ones). Well, in emacs you get colors, but all |
|
3321 | 3328 | seem to be 'light' colors (no difference between dark and light |
|
3322 | 3329 | ones). But the garbage chars are gone, and also in xterms. It |
|
3323 | 3330 | seems that now I'm using 'cleaner' ansi sequences. |
|
3324 | 3331 | |
|
3325 | 3332 | 2002-02-21 Fernando Perez <fperez@colorado.edu> |
|
3326 | 3333 | |
|
3327 | 3334 | * Released 0.2.7 (mainly to publish the scoping fix). |
|
3328 | 3335 | |
|
3329 | 3336 | * IPython/Logger.py (Logger.logstate): added. A corresponding |
|
3330 | 3337 | @logstate magic was created. |
|
3331 | 3338 | |
|
3332 | 3339 | * IPython/Magic.py: fixed nested scoping problem under Python |
|
3333 | 3340 | 2.1.x (automagic wasn't working). |
|
3334 | 3341 | |
|
3335 | 3342 | 2002-02-20 Fernando Perez <fperez@colorado.edu> |
|
3336 | 3343 | |
|
3337 | 3344 | * Released 0.2.6. |
|
3338 | 3345 | |
|
3339 | 3346 | * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet' |
|
3340 | 3347 | option so that logs can come out without any headers at all. |
|
3341 | 3348 | |
|
3342 | 3349 | * IPython/UserConfig/ipythonrc-scipy.py: created a profile for |
|
3343 | 3350 | SciPy. |
|
3344 | 3351 | |
|
3345 | 3352 | * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so |
|
3346 | 3353 | that embedded IPython calls don't require vars() to be explicitly |
|
3347 | 3354 | passed. Now they are extracted from the caller's frame (code |
|
3348 | 3355 | snatched from Eric Jones' weave). Added better documentation to |
|
3349 | 3356 | the section on embedding and the example file. |
|
3350 | 3357 | |
|
3351 | 3358 | * IPython/genutils.py (page): Changed so that under emacs, it just |
|
3352 | 3359 | prints the string. You can then page up and down in the emacs |
|
3353 | 3360 | buffer itself. This is how the builtin help() works. |
|
3354 | 3361 | |
|
3355 | 3362 | * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with |
|
3356 | 3363 | macro scoping: macros need to be executed in the user's namespace |
|
3357 | 3364 | to work as if they had been typed by the user. |
|
3358 | 3365 | |
|
3359 | 3366 | * IPython/Magic.py (Magic.magic_macro): Changed macros so they |
|
3360 | 3367 | execute automatically (no need to type 'exec...'). They then |
|
3361 | 3368 | behave like 'true macros'. The printing system was also modified |
|
3362 | 3369 | for this to work. |
|
3363 | 3370 | |
|
3364 | 3371 | 2002-02-19 Fernando Perez <fperez@colorado.edu> |
|
3365 | 3372 | |
|
3366 | 3373 | * IPython/genutils.py (page_file): new function for paging files |
|
3367 | 3374 | in an OS-independent way. Also necessary for file viewing to work |
|
3368 | 3375 | well inside Emacs buffers. |
|
3369 | 3376 | (page): Added checks for being in an emacs buffer. |
|
3370 | 3377 | (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed |
|
3371 | 3378 | same bug in iplib. |
|
3372 | 3379 | |
|
3373 | 3380 | 2002-02-18 Fernando Perez <fperez@colorado.edu> |
|
3374 | 3381 | |
|
3375 | 3382 | * IPython/iplib.py (InteractiveShell.init_readline): modified use |
|
3376 | 3383 | of readline so that IPython can work inside an Emacs buffer. |
|
3377 | 3384 | |
|
3378 | 3385 | * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to |
|
3379 | 3386 | method signatures (they weren't really bugs, but it looks cleaner |
|
3380 | 3387 | and keeps PyChecker happy). |
|
3381 | 3388 | |
|
3382 | 3389 | * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP |
|
3383 | 3390 | for implementing various user-defined hooks. Currently only |
|
3384 | 3391 | display is done. |
|
3385 | 3392 | |
|
3386 | 3393 | * IPython/Prompts.py (CachedOutput._display): changed display |
|
3387 | 3394 | functions so that they can be dynamically changed by users easily. |
|
3388 | 3395 | |
|
3389 | 3396 | * IPython/Extensions/numeric_formats.py (num_display): added an |
|
3390 | 3397 | extension for printing NumPy arrays in flexible manners. It |
|
3391 | 3398 | doesn't do anything yet, but all the structure is in |
|
3392 | 3399 | place. Ultimately the plan is to implement output format control |
|
3393 | 3400 | like in Octave. |
|
3394 | 3401 | |
|
3395 | 3402 | * IPython/Magic.py (Magic.lsmagic): changed so that bound magic |
|
3396 | 3403 | methods are found at run-time by all the automatic machinery. |
|
3397 | 3404 | |
|
3398 | 3405 | 2002-02-17 Fernando Perez <fperez@colorado.edu> |
|
3399 | 3406 | |
|
3400 | 3407 | * setup_Windows.py (make_shortcut): documented. Cleaned up the |
|
3401 | 3408 | whole file a little. |
|
3402 | 3409 | |
|
3403 | 3410 | * ToDo: closed this document. Now there's a new_design.lyx |
|
3404 | 3411 | document for all new ideas. Added making a pdf of it for the |
|
3405 | 3412 | end-user distro. |
|
3406 | 3413 | |
|
3407 | 3414 | * IPython/Logger.py (Logger.switch_log): Created this to replace |
|
3408 | 3415 | logon() and logoff(). It also fixes a nasty crash reported by |
|
3409 | 3416 | Philip Hisley <compsys-AT-starpower.net>. Many thanks to him. |
|
3410 | 3417 | |
|
3411 | 3418 | * IPython/iplib.py (complete): got auto-completion to work with |
|
3412 | 3419 | automagic (I had wanted this for a long time). |
|
3413 | 3420 | |
|
3414 | 3421 | * IPython/Magic.py (Magic.magic_files): Added @files as an alias |
|
3415 | 3422 | to @file, since file() is now a builtin and clashes with automagic |
|
3416 | 3423 | for @file. |
|
3417 | 3424 | |
|
3418 | 3425 | * Made some new files: Prompts, CrashHandler, Magic, Logger. All |
|
3419 | 3426 | of this was previously in iplib, which had grown to more than 2000 |
|
3420 | 3427 | lines, way too long. No new functionality, but it makes managing |
|
3421 | 3428 | the code a bit easier. |
|
3422 | 3429 | |
|
3423 | 3430 | * IPython/iplib.py (IPythonCrashHandler.__call__): Added version |
|
3424 | 3431 | information to crash reports. |
|
3425 | 3432 | |
|
3426 | 3433 | 2002-02-12 Fernando Perez <fperez@colorado.edu> |
|
3427 | 3434 | |
|
3428 | 3435 | * Released 0.2.5. |
|
3429 | 3436 | |
|
3430 | 3437 | 2002-02-11 Fernando Perez <fperez@colorado.edu> |
|
3431 | 3438 | |
|
3432 | 3439 | * Wrote a relatively complete Windows installer. It puts |
|
3433 | 3440 | everything in place, creates Start Menu entries and fixes the |
|
3434 | 3441 | color issues. Nothing fancy, but it works. |
|
3435 | 3442 | |
|
3436 | 3443 | 2002-02-10 Fernando Perez <fperez@colorado.edu> |
|
3437 | 3444 | |
|
3438 | 3445 | * IPython/iplib.py (InteractiveShell.safe_execfile): added an |
|
3439 | 3446 | os.path.expanduser() call so that we can type @run ~/myfile.py and |
|
3440 | 3447 | have thigs work as expected. |
|
3441 | 3448 | |
|
3442 | 3449 | * IPython/genutils.py (page): fixed exception handling so things |
|
3443 | 3450 | work both in Unix and Windows correctly. Quitting a pager triggers |
|
3444 | 3451 | an IOError/broken pipe in Unix, and in windows not finding a pager |
|
3445 | 3452 | is also an IOError, so I had to actually look at the return value |
|
3446 | 3453 | of the exception, not just the exception itself. Should be ok now. |
|
3447 | 3454 | |
|
3448 | 3455 | * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme): |
|
3449 | 3456 | modified to allow case-insensitive color scheme changes. |
|
3450 | 3457 | |
|
3451 | 3458 | 2002-02-09 Fernando Perez <fperez@colorado.edu> |
|
3452 | 3459 | |
|
3453 | 3460 | * IPython/genutils.py (native_line_ends): new function to leave |
|
3454 | 3461 | user config files with os-native line-endings. |
|
3455 | 3462 | |
|
3456 | 3463 | * README and manual updates. |
|
3457 | 3464 | |
|
3458 | 3465 | * IPython/genutils.py: fixed unicode bug: use types.StringTypes |
|
3459 | 3466 | instead of StringType to catch Unicode strings. |
|
3460 | 3467 | |
|
3461 | 3468 | * IPython/genutils.py (filefind): fixed bug for paths with |
|
3462 | 3469 | embedded spaces (very common in Windows). |
|
3463 | 3470 | |
|
3464 | 3471 | * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc |
|
3465 | 3472 | files under Windows, so that they get automatically associated |
|
3466 | 3473 | with a text editor. Windows makes it a pain to handle |
|
3467 | 3474 | extension-less files. |
|
3468 | 3475 | |
|
3469 | 3476 | * IPython/iplib.py (InteractiveShell.init_readline): Made the |
|
3470 | 3477 | warning about readline only occur for Posix. In Windows there's no |
|
3471 | 3478 | way to get readline, so why bother with the warning. |
|
3472 | 3479 | |
|
3473 | 3480 | * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__ |
|
3474 | 3481 | for __str__ instead of dir(self), since dir() changed in 2.2. |
|
3475 | 3482 | |
|
3476 | 3483 | * Ported to Windows! Tested on XP, I suspect it should work fine |
|
3477 | 3484 | on NT/2000, but I don't think it will work on 98 et al. That |
|
3478 | 3485 | series of Windows is such a piece of junk anyway that I won't try |
|
3479 | 3486 | porting it there. The XP port was straightforward, showed a few |
|
3480 | 3487 | bugs here and there (fixed all), in particular some string |
|
3481 | 3488 | handling stuff which required considering Unicode strings (which |
|
3482 | 3489 | Windows uses). This is good, but hasn't been too tested :) No |
|
3483 | 3490 | fancy installer yet, I'll put a note in the manual so people at |
|
3484 | 3491 | least make manually a shortcut. |
|
3485 | 3492 | |
|
3486 | 3493 | * IPython/iplib.py (Magic.magic_colors): Unified the color options |
|
3487 | 3494 | into a single one, "colors". This now controls both prompt and |
|
3488 | 3495 | exception color schemes, and can be changed both at startup |
|
3489 | 3496 | (either via command-line switches or via ipythonrc files) and at |
|
3490 | 3497 | runtime, with @colors. |
|
3491 | 3498 | (Magic.magic_run): renamed @prun to @run and removed the old |
|
3492 | 3499 | @run. The two were too similar to warrant keeping both. |
|
3493 | 3500 | |
|
3494 | 3501 | 2002-02-03 Fernando Perez <fperez@colorado.edu> |
|
3495 | 3502 | |
|
3496 | 3503 | * IPython/iplib.py (install_first_time): Added comment on how to |
|
3497 | 3504 | configure the color options for first-time users. Put a <return> |
|
3498 | 3505 | request at the end so that small-terminal users get a chance to |
|
3499 | 3506 | read the startup info. |
|
3500 | 3507 | |
|
3501 | 3508 | 2002-01-23 Fernando Perez <fperez@colorado.edu> |
|
3502 | 3509 | |
|
3503 | 3510 | * IPython/iplib.py (CachedOutput.update): Changed output memory |
|
3504 | 3511 | variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For |
|
3505 | 3512 | input history we still use _i. Did this b/c these variable are |
|
3506 | 3513 | very commonly used in interactive work, so the less we need to |
|
3507 | 3514 | type the better off we are. |
|
3508 | 3515 | (Magic.magic_prun): updated @prun to better handle the namespaces |
|
3509 | 3516 | the file will run in, including a fix for __name__ not being set |
|
3510 | 3517 | before. |
|
3511 | 3518 | |
|
3512 | 3519 | 2002-01-20 Fernando Perez <fperez@colorado.edu> |
|
3513 | 3520 | |
|
3514 | 3521 | * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of |
|
3515 | 3522 | extra garbage for Python 2.2. Need to look more carefully into |
|
3516 | 3523 | this later. |
|
3517 | 3524 | |
|
3518 | 3525 | 2002-01-19 Fernando Perez <fperez@colorado.edu> |
|
3519 | 3526 | |
|
3520 | 3527 | * IPython/iplib.py (InteractiveShell.showtraceback): fixed to |
|
3521 | 3528 | display SyntaxError exceptions properly formatted when they occur |
|
3522 | 3529 | (they can be triggered by imported code). |
|
3523 | 3530 | |
|
3524 | 3531 | 2002-01-18 Fernando Perez <fperez@colorado.edu> |
|
3525 | 3532 | |
|
3526 | 3533 | * IPython/iplib.py (InteractiveShell.safe_execfile): now |
|
3527 | 3534 | SyntaxError exceptions are reported nicely formatted, instead of |
|
3528 | 3535 | spitting out only offset information as before. |
|
3529 | 3536 | (Magic.magic_prun): Added the @prun function for executing |
|
3530 | 3537 | programs with command line args inside IPython. |
|
3531 | 3538 | |
|
3532 | 3539 | 2002-01-16 Fernando Perez <fperez@colorado.edu> |
|
3533 | 3540 | |
|
3534 | 3541 | * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist |
|
3535 | 3542 | to *not* include the last item given in a range. This brings their |
|
3536 | 3543 | behavior in line with Python's slicing: |
|
3537 | 3544 | a[n1:n2] -> a[n1]...a[n2-1] |
|
3538 | 3545 | It may be a bit less convenient, but I prefer to stick to Python's |
|
3539 | 3546 | conventions *everywhere*, so users never have to wonder. |
|
3540 | 3547 | (Magic.magic_macro): Added @macro function to ease the creation of |
|
3541 | 3548 | macros. |
|
3542 | 3549 | |
|
3543 | 3550 | 2002-01-05 Fernando Perez <fperez@colorado.edu> |
|
3544 | 3551 | |
|
3545 | 3552 | * Released 0.2.4. |
|
3546 | 3553 | |
|
3547 | 3554 | * IPython/iplib.py (Magic.magic_pdef): |
|
3548 | 3555 | (InteractiveShell.safe_execfile): report magic lines and error |
|
3549 | 3556 | lines without line numbers so one can easily copy/paste them for |
|
3550 | 3557 | re-execution. |
|
3551 | 3558 | |
|
3552 | 3559 | * Updated manual with recent changes. |
|
3553 | 3560 | |
|
3554 | 3561 | * IPython/iplib.py (Magic.magic_oinfo): added constructor |
|
3555 | 3562 | docstring printing when class? is called. Very handy for knowing |
|
3556 | 3563 | how to create class instances (as long as __init__ is well |
|
3557 | 3564 | documented, of course :) |
|
3558 | 3565 | (Magic.magic_doc): print both class and constructor docstrings. |
|
3559 | 3566 | (Magic.magic_pdef): give constructor info if passed a class and |
|
3560 | 3567 | __call__ info for callable object instances. |
|
3561 | 3568 | |
|
3562 | 3569 | 2002-01-04 Fernando Perez <fperez@colorado.edu> |
|
3563 | 3570 | |
|
3564 | 3571 | * Made deep_reload() off by default. It doesn't always work |
|
3565 | 3572 | exactly as intended, so it's probably safer to have it off. It's |
|
3566 | 3573 | still available as dreload() anyway, so nothing is lost. |
|
3567 | 3574 | |
|
3568 | 3575 | 2002-01-02 Fernando Perez <fperez@colorado.edu> |
|
3569 | 3576 | |
|
3570 | 3577 | * Released 0.2.3 (contacted R.Singh at CU about biopython course, |
|
3571 | 3578 | so I wanted an updated release). |
|
3572 | 3579 | |
|
3573 | 3580 | 2001-12-27 Fernando Perez <fperez@colorado.edu> |
|
3574 | 3581 | |
|
3575 | 3582 | * IPython/iplib.py (InteractiveShell.interact): Added the original |
|
3576 | 3583 | code from 'code.py' for this module in order to change the |
|
3577 | 3584 | handling of a KeyboardInterrupt. This was necessary b/c otherwise |
|
3578 | 3585 | the history cache would break when the user hit Ctrl-C, and |
|
3579 | 3586 | interact() offers no way to add any hooks to it. |
|
3580 | 3587 | |
|
3581 | 3588 | 2001-12-23 Fernando Perez <fperez@colorado.edu> |
|
3582 | 3589 | |
|
3583 | 3590 | * setup.py: added check for 'MANIFEST' before trying to remove |
|
3584 | 3591 | it. Thanks to Sean Reifschneider. |
|
3585 | 3592 | |
|
3586 | 3593 | 2001-12-22 Fernando Perez <fperez@colorado.edu> |
|
3587 | 3594 | |
|
3588 | 3595 | * Released 0.2.2. |
|
3589 | 3596 | |
|
3590 | 3597 | * Finished (reasonably) writing the manual. Later will add the |
|
3591 | 3598 | python-standard navigation stylesheets, but for the time being |
|
3592 | 3599 | it's fairly complete. Distribution will include html and pdf |
|
3593 | 3600 | versions. |
|
3594 | 3601 | |
|
3595 | 3602 | * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu |
|
3596 | 3603 | (MayaVi author). |
|
3597 | 3604 | |
|
3598 | 3605 | 2001-12-21 Fernando Perez <fperez@colorado.edu> |
|
3599 | 3606 | |
|
3600 | 3607 | * Released 0.2.1. Barring any nasty bugs, this is it as far as a |
|
3601 | 3608 | good public release, I think (with the manual and the distutils |
|
3602 | 3609 | installer). The manual can use some work, but that can go |
|
3603 | 3610 | slowly. Otherwise I think it's quite nice for end users. Next |
|
3604 | 3611 | summer, rewrite the guts of it... |
|
3605 | 3612 | |
|
3606 | 3613 | * Changed format of ipythonrc files to use whitespace as the |
|
3607 | 3614 | separator instead of an explicit '='. Cleaner. |
|
3608 | 3615 | |
|
3609 | 3616 | 2001-12-20 Fernando Perez <fperez@colorado.edu> |
|
3610 | 3617 | |
|
3611 | 3618 | * Started a manual in LyX. For now it's just a quick merge of the |
|
3612 | 3619 | various internal docstrings and READMEs. Later it may grow into a |
|
3613 | 3620 | nice, full-blown manual. |
|
3614 | 3621 | |
|
3615 | 3622 | * Set up a distutils based installer. Installation should now be |
|
3616 | 3623 | trivially simple for end-users. |
|
3617 | 3624 | |
|
3618 | 3625 | 2001-12-11 Fernando Perez <fperez@colorado.edu> |
|
3619 | 3626 | |
|
3620 | 3627 | * Released 0.2.0. First public release, announced it at |
|
3621 | 3628 | comp.lang.python. From now on, just bugfixes... |
|
3622 | 3629 | |
|
3623 | 3630 | * Went through all the files, set copyright/license notices and |
|
3624 | 3631 | cleaned up things. Ready for release. |
|
3625 | 3632 | |
|
3626 | 3633 | 2001-12-10 Fernando Perez <fperez@colorado.edu> |
|
3627 | 3634 | |
|
3628 | 3635 | * Changed the first-time installer not to use tarfiles. It's more |
|
3629 | 3636 | robust now and less unix-dependent. Also makes it easier for |
|
3630 | 3637 | people to later upgrade versions. |
|
3631 | 3638 | |
|
3632 | 3639 | * Changed @exit to @abort to reflect the fact that it's pretty |
|
3633 | 3640 | brutal (a sys.exit()). The difference between @abort and Ctrl-D |
|
3634 | 3641 | becomes significant only when IPyhton is embedded: in that case, |
|
3635 | 3642 | C-D closes IPython only, but @abort kills the enclosing program |
|
3636 | 3643 | too (unless it had called IPython inside a try catching |
|
3637 | 3644 | SystemExit). |
|
3638 | 3645 | |
|
3639 | 3646 | * Created Shell module which exposes the actuall IPython Shell |
|
3640 | 3647 | classes, currently the normal and the embeddable one. This at |
|
3641 | 3648 | least offers a stable interface we won't need to change when |
|
3642 | 3649 | (later) the internals are rewritten. That rewrite will be confined |
|
3643 | 3650 | to iplib and ipmaker, but the Shell interface should remain as is. |
|
3644 | 3651 | |
|
3645 | 3652 | * Added embed module which offers an embeddable IPShell object, |
|
3646 | 3653 | useful to fire up IPython *inside* a running program. Great for |
|
3647 | 3654 | debugging or dynamical data analysis. |
|
3648 | 3655 | |
|
3649 | 3656 | 2001-12-08 Fernando Perez <fperez@colorado.edu> |
|
3650 | 3657 | |
|
3651 | 3658 | * Fixed small bug preventing seeing info from methods of defined |
|
3652 | 3659 | objects (incorrect namespace in _ofind()). |
|
3653 | 3660 | |
|
3654 | 3661 | * Documentation cleanup. Moved the main usage docstrings to a |
|
3655 | 3662 | separate file, usage.py (cleaner to maintain, and hopefully in the |
|
3656 | 3663 | future some perlpod-like way of producing interactive, man and |
|
3657 | 3664 | html docs out of it will be found). |
|
3658 | 3665 | |
|
3659 | 3666 | * Added @profile to see your profile at any time. |
|
3660 | 3667 | |
|
3661 | 3668 | * Added @p as an alias for 'print'. It's especially convenient if |
|
3662 | 3669 | using automagic ('p x' prints x). |
|
3663 | 3670 | |
|
3664 | 3671 | * Small cleanups and fixes after a pychecker run. |
|
3665 | 3672 | |
|
3666 | 3673 | * Changed the @cd command to handle @cd - and @cd -<n> for |
|
3667 | 3674 | visiting any directory in _dh. |
|
3668 | 3675 | |
|
3669 | 3676 | * Introduced _dh, a history of visited directories. @dhist prints |
|
3670 | 3677 | it out with numbers. |
|
3671 | 3678 | |
|
3672 | 3679 | 2001-12-07 Fernando Perez <fperez@colorado.edu> |
|
3673 | 3680 | |
|
3674 | 3681 | * Released 0.1.22 |
|
3675 | 3682 | |
|
3676 | 3683 | * Made initialization a bit more robust against invalid color |
|
3677 | 3684 | options in user input (exit, not traceback-crash). |
|
3678 | 3685 | |
|
3679 | 3686 | * Changed the bug crash reporter to write the report only in the |
|
3680 | 3687 | user's .ipython directory. That way IPython won't litter people's |
|
3681 | 3688 | hard disks with crash files all over the place. Also print on |
|
3682 | 3689 | screen the necessary mail command. |
|
3683 | 3690 | |
|
3684 | 3691 | * With the new ultraTB, implemented LightBG color scheme for light |
|
3685 | 3692 | background terminals. A lot of people like white backgrounds, so I |
|
3686 | 3693 | guess we should at least give them something readable. |
|
3687 | 3694 | |
|
3688 | 3695 | 2001-12-06 Fernando Perez <fperez@colorado.edu> |
|
3689 | 3696 | |
|
3690 | 3697 | * Modified the structure of ultraTB. Now there's a proper class |
|
3691 | 3698 | for tables of color schemes which allow adding schemes easily and |
|
3692 | 3699 | switching the active scheme without creating a new instance every |
|
3693 | 3700 | time (which was ridiculous). The syntax for creating new schemes |
|
3694 | 3701 | is also cleaner. I think ultraTB is finally done, with a clean |
|
3695 | 3702 | class structure. Names are also much cleaner (now there's proper |
|
3696 | 3703 | color tables, no need for every variable to also have 'color' in |
|
3697 | 3704 | its name). |
|
3698 | 3705 | |
|
3699 | 3706 | * Broke down genutils into separate files. Now genutils only |
|
3700 | 3707 | contains utility functions, and classes have been moved to their |
|
3701 | 3708 | own files (they had enough independent functionality to warrant |
|
3702 | 3709 | it): ConfigLoader, OutputTrap, Struct. |
|
3703 | 3710 | |
|
3704 | 3711 | 2001-12-05 Fernando Perez <fperez@colorado.edu> |
|
3705 | 3712 | |
|
3706 | 3713 | * IPython turns 21! Released version 0.1.21, as a candidate for |
|
3707 | 3714 | public consumption. If all goes well, release in a few days. |
|
3708 | 3715 | |
|
3709 | 3716 | * Fixed path bug (files in Extensions/ directory wouldn't be found |
|
3710 | 3717 | unless IPython/ was explicitly in sys.path). |
|
3711 | 3718 | |
|
3712 | 3719 | * Extended the FlexCompleter class as MagicCompleter to allow |
|
3713 | 3720 | completion of @-starting lines. |
|
3714 | 3721 | |
|
3715 | 3722 | * Created __release__.py file as a central repository for release |
|
3716 | 3723 | info that other files can read from. |
|
3717 | 3724 | |
|
3718 | 3725 | * Fixed small bug in logging: when logging was turned on in |
|
3719 | 3726 | mid-session, old lines with special meanings (!@?) were being |
|
3720 | 3727 | logged without the prepended comment, which is necessary since |
|
3721 | 3728 | they are not truly valid python syntax. This should make session |
|
3722 | 3729 | restores produce less errors. |
|
3723 | 3730 | |
|
3724 | 3731 | * The namespace cleanup forced me to make a FlexCompleter class |
|
3725 | 3732 | which is nothing but a ripoff of rlcompleter, but with selectable |
|
3726 | 3733 | namespace (rlcompleter only works in __main__.__dict__). I'll try |
|
3727 | 3734 | to submit a note to the authors to see if this change can be |
|
3728 | 3735 | incorporated in future rlcompleter releases (Dec.6: done) |
|
3729 | 3736 | |
|
3730 | 3737 | * More fixes to namespace handling. It was a mess! Now all |
|
3731 | 3738 | explicit references to __main__.__dict__ are gone (except when |
|
3732 | 3739 | really needed) and everything is handled through the namespace |
|
3733 | 3740 | dicts in the IPython instance. We seem to be getting somewhere |
|
3734 | 3741 | with this, finally... |
|
3735 | 3742 | |
|
3736 | 3743 | * Small documentation updates. |
|
3737 | 3744 | |
|
3738 | 3745 | * Created the Extensions directory under IPython (with an |
|
3739 | 3746 | __init__.py). Put the PhysicalQ stuff there. This directory should |
|
3740 | 3747 | be used for all special-purpose extensions. |
|
3741 | 3748 | |
|
3742 | 3749 | * File renaming: |
|
3743 | 3750 | ipythonlib --> ipmaker |
|
3744 | 3751 | ipplib --> iplib |
|
3745 | 3752 | This makes a bit more sense in terms of what these files actually do. |
|
3746 | 3753 | |
|
3747 | 3754 | * Moved all the classes and functions in ipythonlib to ipplib, so |
|
3748 | 3755 | now ipythonlib only has make_IPython(). This will ease up its |
|
3749 | 3756 | splitting in smaller functional chunks later. |
|
3750 | 3757 | |
|
3751 | 3758 | * Cleaned up (done, I think) output of @whos. Better column |
|
3752 | 3759 | formatting, and now shows str(var) for as much as it can, which is |
|
3753 | 3760 | typically what one gets with a 'print var'. |
|
3754 | 3761 | |
|
3755 | 3762 | 2001-12-04 Fernando Perez <fperez@colorado.edu> |
|
3756 | 3763 | |
|
3757 | 3764 | * Fixed namespace problems. Now builtin/IPyhton/user names get |
|
3758 | 3765 | properly reported in their namespace. Internal namespace handling |
|
3759 | 3766 | is finally getting decent (not perfect yet, but much better than |
|
3760 | 3767 | the ad-hoc mess we had). |
|
3761 | 3768 | |
|
3762 | 3769 | * Removed -exit option. If people just want to run a python |
|
3763 | 3770 | script, that's what the normal interpreter is for. Less |
|
3764 | 3771 | unnecessary options, less chances for bugs. |
|
3765 | 3772 | |
|
3766 | 3773 | * Added a crash handler which generates a complete post-mortem if |
|
3767 | 3774 | IPython crashes. This will help a lot in tracking bugs down the |
|
3768 | 3775 | road. |
|
3769 | 3776 | |
|
3770 | 3777 | * Fixed nasty bug in auto-evaluation part of prefilter(). Names |
|
3771 | 3778 | which were boud to functions being reassigned would bypass the |
|
3772 | 3779 | logger, breaking the sync of _il with the prompt counter. This |
|
3773 | 3780 | would then crash IPython later when a new line was logged. |
|
3774 | 3781 | |
|
3775 | 3782 | 2001-12-02 Fernando Perez <fperez@colorado.edu> |
|
3776 | 3783 | |
|
3777 | 3784 | * Made IPython a package. This means people don't have to clutter |
|
3778 | 3785 | their sys.path with yet another directory. Changed the INSTALL |
|
3779 | 3786 | file accordingly. |
|
3780 | 3787 | |
|
3781 | 3788 | * Cleaned up the output of @who_ls, @who and @whos. @who_ls now |
|
3782 | 3789 | sorts its output (so @who shows it sorted) and @whos formats the |
|
3783 | 3790 | table according to the width of the first column. Nicer, easier to |
|
3784 | 3791 | read. Todo: write a generic table_format() which takes a list of |
|
3785 | 3792 | lists and prints it nicely formatted, with optional row/column |
|
3786 | 3793 | separators and proper padding and justification. |
|
3787 | 3794 | |
|
3788 | 3795 | * Released 0.1.20 |
|
3789 | 3796 | |
|
3790 | 3797 | * Fixed bug in @log which would reverse the inputcache list (a |
|
3791 | 3798 | copy operation was missing). |
|
3792 | 3799 | |
|
3793 | 3800 | * Code cleanup. @config was changed to use page(). Better, since |
|
3794 | 3801 | its output is always quite long. |
|
3795 | 3802 | |
|
3796 | 3803 | * Itpl is back as a dependency. I was having too many problems |
|
3797 | 3804 | getting the parametric aliases to work reliably, and it's just |
|
3798 | 3805 | easier to code weird string operations with it than playing %()s |
|
3799 | 3806 | games. It's only ~6k, so I don't think it's too big a deal. |
|
3800 | 3807 | |
|
3801 | 3808 | * Found (and fixed) a very nasty bug with history. !lines weren't |
|
3802 | 3809 | getting cached, and the out of sync caches would crash |
|
3803 | 3810 | IPython. Fixed it by reorganizing the prefilter/handlers/logger |
|
3804 | 3811 | division of labor a bit better. Bug fixed, cleaner structure. |
|
3805 | 3812 | |
|
3806 | 3813 | 2001-12-01 Fernando Perez <fperez@colorado.edu> |
|
3807 | 3814 | |
|
3808 | 3815 | * Released 0.1.19 |
|
3809 | 3816 | |
|
3810 | 3817 | * Added option -n to @hist to prevent line number printing. Much |
|
3811 | 3818 | easier to copy/paste code this way. |
|
3812 | 3819 | |
|
3813 | 3820 | * Created global _il to hold the input list. Allows easy |
|
3814 | 3821 | re-execution of blocks of code by slicing it (inspired by Janko's |
|
3815 | 3822 | comment on 'macros'). |
|
3816 | 3823 | |
|
3817 | 3824 | * Small fixes and doc updates. |
|
3818 | 3825 | |
|
3819 | 3826 | * Rewrote @history function (was @h). Renamed it to @hist, @h is |
|
3820 | 3827 | much too fragile with automagic. Handles properly multi-line |
|
3821 | 3828 | statements and takes parameters. |
|
3822 | 3829 | |
|
3823 | 3830 | 2001-11-30 Fernando Perez <fperez@colorado.edu> |
|
3824 | 3831 | |
|
3825 | 3832 | * Version 0.1.18 released. |
|
3826 | 3833 | |
|
3827 | 3834 | * Fixed nasty namespace bug in initial module imports. |
|
3828 | 3835 | |
|
3829 | 3836 | * Added copyright/license notes to all code files (except |
|
3830 | 3837 | DPyGetOpt). For the time being, LGPL. That could change. |
|
3831 | 3838 | |
|
3832 | 3839 | * Rewrote a much nicer README, updated INSTALL, cleaned up |
|
3833 | 3840 | ipythonrc-* samples. |
|
3834 | 3841 | |
|
3835 | 3842 | * Overall code/documentation cleanup. Basically ready for |
|
3836 | 3843 | release. Only remaining thing: licence decision (LGPL?). |
|
3837 | 3844 | |
|
3838 | 3845 | * Converted load_config to a class, ConfigLoader. Now recursion |
|
3839 | 3846 | control is better organized. Doesn't include the same file twice. |
|
3840 | 3847 | |
|
3841 | 3848 | 2001-11-29 Fernando Perez <fperez@colorado.edu> |
|
3842 | 3849 | |
|
3843 | 3850 | * Got input history working. Changed output history variables from |
|
3844 | 3851 | _p to _o so that _i is for input and _o for output. Just cleaner |
|
3845 | 3852 | convention. |
|
3846 | 3853 | |
|
3847 | 3854 | * Implemented parametric aliases. This pretty much allows the |
|
3848 | 3855 | alias system to offer full-blown shell convenience, I think. |
|
3849 | 3856 | |
|
3850 | 3857 | * Version 0.1.17 released, 0.1.18 opened. |
|
3851 | 3858 | |
|
3852 | 3859 | * dot_ipython/ipythonrc (alias): added documentation. |
|
3853 | 3860 | (xcolor): Fixed small bug (xcolors -> xcolor) |
|
3854 | 3861 | |
|
3855 | 3862 | * Changed the alias system. Now alias is a magic command to define |
|
3856 | 3863 | aliases just like the shell. Rationale: the builtin magics should |
|
3857 | 3864 | be there for things deeply connected to IPython's |
|
3858 | 3865 | architecture. And this is a much lighter system for what I think |
|
3859 | 3866 | is the really important feature: allowing users to define quickly |
|
3860 | 3867 | magics that will do shell things for them, so they can customize |
|
3861 | 3868 | IPython easily to match their work habits. If someone is really |
|
3862 | 3869 | desperate to have another name for a builtin alias, they can |
|
3863 | 3870 | always use __IP.magic_newname = __IP.magic_oldname. Hackish but |
|
3864 | 3871 | works. |
|
3865 | 3872 | |
|
3866 | 3873 | 2001-11-28 Fernando Perez <fperez@colorado.edu> |
|
3867 | 3874 | |
|
3868 | 3875 | * Changed @file so that it opens the source file at the proper |
|
3869 | 3876 | line. Since it uses less, if your EDITOR environment is |
|
3870 | 3877 | configured, typing v will immediately open your editor of choice |
|
3871 | 3878 | right at the line where the object is defined. Not as quick as |
|
3872 | 3879 | having a direct @edit command, but for all intents and purposes it |
|
3873 | 3880 | works. And I don't have to worry about writing @edit to deal with |
|
3874 | 3881 | all the editors, less does that. |
|
3875 | 3882 | |
|
3876 | 3883 | * Version 0.1.16 released, 0.1.17 opened. |
|
3877 | 3884 | |
|
3878 | 3885 | * Fixed some nasty bugs in the page/page_dumb combo that could |
|
3879 | 3886 | crash IPython. |
|
3880 | 3887 | |
|
3881 | 3888 | 2001-11-27 Fernando Perez <fperez@colorado.edu> |
|
3882 | 3889 | |
|
3883 | 3890 | * Version 0.1.15 released, 0.1.16 opened. |
|
3884 | 3891 | |
|
3885 | 3892 | * Finally got ? and ?? to work for undefined things: now it's |
|
3886 | 3893 | possible to type {}.get? and get information about the get method |
|
3887 | 3894 | of dicts, or os.path? even if only os is defined (so technically |
|
3888 | 3895 | os.path isn't). Works at any level. For example, after import os, |
|
3889 | 3896 | os?, os.path?, os.path.abspath? all work. This is great, took some |
|
3890 | 3897 | work in _ofind. |
|
3891 | 3898 | |
|
3892 | 3899 | * Fixed more bugs with logging. The sanest way to do it was to add |
|
3893 | 3900 | to @log a 'mode' parameter. Killed two in one shot (this mode |
|
3894 | 3901 | option was a request of Janko's). I think it's finally clean |
|
3895 | 3902 | (famous last words). |
|
3896 | 3903 | |
|
3897 | 3904 | * Added a page_dumb() pager which does a decent job of paging on |
|
3898 | 3905 | screen, if better things (like less) aren't available. One less |
|
3899 | 3906 | unix dependency (someday maybe somebody will port this to |
|
3900 | 3907 | windows). |
|
3901 | 3908 | |
|
3902 | 3909 | * Fixed problem in magic_log: would lock of logging out if log |
|
3903 | 3910 | creation failed (because it would still think it had succeeded). |
|
3904 | 3911 | |
|
3905 | 3912 | * Improved the page() function using curses to auto-detect screen |
|
3906 | 3913 | size. Now it can make a much better decision on whether to print |
|
3907 | 3914 | or page a string. Option screen_length was modified: a value 0 |
|
3908 | 3915 | means auto-detect, and that's the default now. |
|
3909 | 3916 | |
|
3910 | 3917 | * Version 0.1.14 released, 0.1.15 opened. I think this is ready to |
|
3911 | 3918 | go out. I'll test it for a few days, then talk to Janko about |
|
3912 | 3919 | licences and announce it. |
|
3913 | 3920 | |
|
3914 | 3921 | * Fixed the length of the auto-generated ---> prompt which appears |
|
3915 | 3922 | for auto-parens and auto-quotes. Getting this right isn't trivial, |
|
3916 | 3923 | with all the color escapes, different prompt types and optional |
|
3917 | 3924 | separators. But it seems to be working in all the combinations. |
|
3918 | 3925 | |
|
3919 | 3926 | 2001-11-26 Fernando Perez <fperez@colorado.edu> |
|
3920 | 3927 | |
|
3921 | 3928 | * Wrote a regexp filter to get option types from the option names |
|
3922 | 3929 | string. This eliminates the need to manually keep two duplicate |
|
3923 | 3930 | lists. |
|
3924 | 3931 | |
|
3925 | 3932 | * Removed the unneeded check_option_names. Now options are handled |
|
3926 | 3933 | in a much saner manner and it's easy to visually check that things |
|
3927 | 3934 | are ok. |
|
3928 | 3935 | |
|
3929 | 3936 | * Updated version numbers on all files I modified to carry a |
|
3930 | 3937 | notice so Janko and Nathan have clear version markers. |
|
3931 | 3938 | |
|
3932 | 3939 | * Updated docstring for ultraTB with my changes. I should send |
|
3933 | 3940 | this to Nathan. |
|
3934 | 3941 | |
|
3935 | 3942 | * Lots of small fixes. Ran everything through pychecker again. |
|
3936 | 3943 | |
|
3937 | 3944 | * Made loading of deep_reload an cmd line option. If it's not too |
|
3938 | 3945 | kosher, now people can just disable it. With -nodeep_reload it's |
|
3939 | 3946 | still available as dreload(), it just won't overwrite reload(). |
|
3940 | 3947 | |
|
3941 | 3948 | * Moved many options to the no| form (-opt and -noopt |
|
3942 | 3949 | accepted). Cleaner. |
|
3943 | 3950 | |
|
3944 | 3951 | * Changed magic_log so that if called with no parameters, it uses |
|
3945 | 3952 | 'rotate' mode. That way auto-generated logs aren't automatically |
|
3946 | 3953 | over-written. For normal logs, now a backup is made if it exists |
|
3947 | 3954 | (only 1 level of backups). A new 'backup' mode was added to the |
|
3948 | 3955 | Logger class to support this. This was a request by Janko. |
|
3949 | 3956 | |
|
3950 | 3957 | * Added @logoff/@logon to stop/restart an active log. |
|
3951 | 3958 | |
|
3952 | 3959 | * Fixed a lot of bugs in log saving/replay. It was pretty |
|
3953 | 3960 | broken. Now special lines (!@,/) appear properly in the command |
|
3954 | 3961 | history after a log replay. |
|
3955 | 3962 | |
|
3956 | 3963 | * Tried and failed to implement full session saving via pickle. My |
|
3957 | 3964 | idea was to pickle __main__.__dict__, but modules can't be |
|
3958 | 3965 | pickled. This would be a better alternative to replaying logs, but |
|
3959 | 3966 | seems quite tricky to get to work. Changed -session to be called |
|
3960 | 3967 | -logplay, which more accurately reflects what it does. And if we |
|
3961 | 3968 | ever get real session saving working, -session is now available. |
|
3962 | 3969 | |
|
3963 | 3970 | * Implemented color schemes for prompts also. As for tracebacks, |
|
3964 | 3971 | currently only NoColor and Linux are supported. But now the |
|
3965 | 3972 | infrastructure is in place, based on a generic ColorScheme |
|
3966 | 3973 | class. So writing and activating new schemes both for the prompts |
|
3967 | 3974 | and the tracebacks should be straightforward. |
|
3968 | 3975 | |
|
3969 | 3976 | * Version 0.1.13 released, 0.1.14 opened. |
|
3970 | 3977 | |
|
3971 | 3978 | * Changed handling of options for output cache. Now counter is |
|
3972 | 3979 | hardwired starting at 1 and one specifies the maximum number of |
|
3973 | 3980 | entries *in the outcache* (not the max prompt counter). This is |
|
3974 | 3981 | much better, since many statements won't increase the cache |
|
3975 | 3982 | count. It also eliminated some confusing options, now there's only |
|
3976 | 3983 | one: cache_size. |
|
3977 | 3984 | |
|
3978 | 3985 | * Added 'alias' magic function and magic_alias option in the |
|
3979 | 3986 | ipythonrc file. Now the user can easily define whatever names he |
|
3980 | 3987 | wants for the magic functions without having to play weird |
|
3981 | 3988 | namespace games. This gives IPython a real shell-like feel. |
|
3982 | 3989 | |
|
3983 | 3990 | * Fixed doc/?/?? for magics. Now all work, in all forms (explicit |
|
3984 | 3991 | @ or not). |
|
3985 | 3992 | |
|
3986 | 3993 | This was one of the last remaining 'visible' bugs (that I know |
|
3987 | 3994 | of). I think if I can clean up the session loading so it works |
|
3988 | 3995 | 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first |
|
3989 | 3996 | about licensing). |
|
3990 | 3997 | |
|
3991 | 3998 | 2001-11-25 Fernando Perez <fperez@colorado.edu> |
|
3992 | 3999 | |
|
3993 | 4000 | * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and |
|
3994 | 4001 | there's a cleaner distinction between what ? and ?? show. |
|
3995 | 4002 | |
|
3996 | 4003 | * Added screen_length option. Now the user can define his own |
|
3997 | 4004 | screen size for page() operations. |
|
3998 | 4005 | |
|
3999 | 4006 | * Implemented magic shell-like functions with automatic code |
|
4000 | 4007 | generation. Now adding another function is just a matter of adding |
|
4001 | 4008 | an entry to a dict, and the function is dynamically generated at |
|
4002 | 4009 | run-time. Python has some really cool features! |
|
4003 | 4010 | |
|
4004 | 4011 | * Renamed many options to cleanup conventions a little. Now all |
|
4005 | 4012 | are lowercase, and only underscores where needed. Also in the code |
|
4006 | 4013 | option name tables are clearer. |
|
4007 | 4014 | |
|
4008 | 4015 | * Changed prompts a little. Now input is 'In [n]:' instead of |
|
4009 | 4016 | 'In[n]:='. This allows it the numbers to be aligned with the |
|
4010 | 4017 | Out[n] numbers, and removes usage of ':=' which doesn't exist in |
|
4011 | 4018 | Python (it was a Mathematica thing). The '...' continuation prompt |
|
4012 | 4019 | was also changed a little to align better. |
|
4013 | 4020 | |
|
4014 | 4021 | * Fixed bug when flushing output cache. Not all _p<n> variables |
|
4015 | 4022 | exist, so their deletion needs to be wrapped in a try: |
|
4016 | 4023 | |
|
4017 | 4024 | * Figured out how to properly use inspect.formatargspec() (it |
|
4018 | 4025 | requires the args preceded by *). So I removed all the code from |
|
4019 | 4026 | _get_pdef in Magic, which was just replicating that. |
|
4020 | 4027 | |
|
4021 | 4028 | * Added test to prefilter to allow redefining magic function names |
|
4022 | 4029 | as variables. This is ok, since the @ form is always available, |
|
4023 | 4030 | but whe should allow the user to define a variable called 'ls' if |
|
4024 | 4031 | he needs it. |
|
4025 | 4032 | |
|
4026 | 4033 | * Moved the ToDo information from README into a separate ToDo. |
|
4027 | 4034 | |
|
4028 | 4035 | * General code cleanup and small bugfixes. I think it's close to a |
|
4029 | 4036 | state where it can be released, obviously with a big 'beta' |
|
4030 | 4037 | warning on it. |
|
4031 | 4038 | |
|
4032 | 4039 | * Got the magic function split to work. Now all magics are defined |
|
4033 | 4040 | in a separate class. It just organizes things a bit, and now |
|
4034 | 4041 | Xemacs behaves nicer (it was choking on InteractiveShell b/c it |
|
4035 | 4042 | was too long). |
|
4036 | 4043 | |
|
4037 | 4044 | * Changed @clear to @reset to avoid potential confusions with |
|
4038 | 4045 | the shell command clear. Also renamed @cl to @clear, which does |
|
4039 | 4046 | exactly what people expect it to from their shell experience. |
|
4040 | 4047 | |
|
4041 | 4048 | Added a check to the @reset command (since it's so |
|
4042 | 4049 | destructive, it's probably a good idea to ask for confirmation). |
|
4043 | 4050 | But now reset only works for full namespace resetting. Since the |
|
4044 | 4051 | del keyword is already there for deleting a few specific |
|
4045 | 4052 | variables, I don't see the point of having a redundant magic |
|
4046 | 4053 | function for the same task. |
|
4047 | 4054 | |
|
4048 | 4055 | 2001-11-24 Fernando Perez <fperez@colorado.edu> |
|
4049 | 4056 | |
|
4050 | 4057 | * Updated the builtin docs (esp. the ? ones). |
|
4051 | 4058 | |
|
4052 | 4059 | * Ran all the code through pychecker. Not terribly impressed with |
|
4053 | 4060 | it: lots of spurious warnings and didn't really find anything of |
|
4054 | 4061 | substance (just a few modules being imported and not used). |
|
4055 | 4062 | |
|
4056 | 4063 | * Implemented the new ultraTB functionality into IPython. New |
|
4057 | 4064 | option: xcolors. This chooses color scheme. xmode now only selects |
|
4058 | 4065 | between Plain and Verbose. Better orthogonality. |
|
4059 | 4066 | |
|
4060 | 4067 | * Large rewrite of ultraTB. Much cleaner now, with a separation of |
|
4061 | 4068 | mode and color scheme for the exception handlers. Now it's |
|
4062 | 4069 | possible to have the verbose traceback with no coloring. |
|
4063 | 4070 | |
|
4064 | 4071 | 2001-11-23 Fernando Perez <fperez@colorado.edu> |
|
4065 | 4072 | |
|
4066 | 4073 | * Version 0.1.12 released, 0.1.13 opened. |
|
4067 | 4074 | |
|
4068 | 4075 | * Removed option to set auto-quote and auto-paren escapes by |
|
4069 | 4076 | user. The chances of breaking valid syntax are just too high. If |
|
4070 | 4077 | someone *really* wants, they can always dig into the code. |
|
4071 | 4078 | |
|
4072 | 4079 | * Made prompt separators configurable. |
|
4073 | 4080 | |
|
4074 | 4081 | 2001-11-22 Fernando Perez <fperez@colorado.edu> |
|
4075 | 4082 | |
|
4076 | 4083 | * Small bugfixes in many places. |
|
4077 | 4084 | |
|
4078 | 4085 | * Removed the MyCompleter class from ipplib. It seemed redundant |
|
4079 | 4086 | with the C-p,C-n history search functionality. Less code to |
|
4080 | 4087 | maintain. |
|
4081 | 4088 | |
|
4082 | 4089 | * Moved all the original ipython.py code into ipythonlib.py. Right |
|
4083 | 4090 | now it's just one big dump into a function called make_IPython, so |
|
4084 | 4091 | no real modularity has been gained. But at least it makes the |
|
4085 | 4092 | wrapper script tiny, and since ipythonlib is a module, it gets |
|
4086 | 4093 | compiled and startup is much faster. |
|
4087 | 4094 | |
|
4088 | 4095 | This is a reasobably 'deep' change, so we should test it for a |
|
4089 | 4096 | while without messing too much more with the code. |
|
4090 | 4097 | |
|
4091 | 4098 | 2001-11-21 Fernando Perez <fperez@colorado.edu> |
|
4092 | 4099 | |
|
4093 | 4100 | * Version 0.1.11 released, 0.1.12 opened for further work. |
|
4094 | 4101 | |
|
4095 | 4102 | * Removed dependency on Itpl. It was only needed in one place. It |
|
4096 | 4103 | would be nice if this became part of python, though. It makes life |
|
4097 | 4104 | *a lot* easier in some cases. |
|
4098 | 4105 | |
|
4099 | 4106 | * Simplified the prefilter code a bit. Now all handlers are |
|
4100 | 4107 | expected to explicitly return a value (at least a blank string). |
|
4101 | 4108 | |
|
4102 | 4109 | * Heavy edits in ipplib. Removed the help system altogether. Now |
|
4103 | 4110 | obj?/?? is used for inspecting objects, a magic @doc prints |
|
4104 | 4111 | docstrings, and full-blown Python help is accessed via the 'help' |
|
4105 | 4112 | keyword. This cleans up a lot of code (less to maintain) and does |
|
4106 | 4113 | the job. Since 'help' is now a standard Python component, might as |
|
4107 | 4114 | well use it and remove duplicate functionality. |
|
4108 | 4115 | |
|
4109 | 4116 | Also removed the option to use ipplib as a standalone program. By |
|
4110 | 4117 | now it's too dependent on other parts of IPython to function alone. |
|
4111 | 4118 | |
|
4112 | 4119 | * Fixed bug in genutils.pager. It would crash if the pager was |
|
4113 | 4120 | exited immediately after opening (broken pipe). |
|
4114 | 4121 | |
|
4115 | 4122 | * Trimmed down the VerboseTB reporting a little. The header is |
|
4116 | 4123 | much shorter now and the repeated exception arguments at the end |
|
4117 | 4124 | have been removed. For interactive use the old header seemed a bit |
|
4118 | 4125 | excessive. |
|
4119 | 4126 | |
|
4120 | 4127 | * Fixed small bug in output of @whos for variables with multi-word |
|
4121 | 4128 | types (only first word was displayed). |
|
4122 | 4129 | |
|
4123 | 4130 | 2001-11-17 Fernando Perez <fperez@colorado.edu> |
|
4124 | 4131 | |
|
4125 | 4132 | * Version 0.1.10 released, 0.1.11 opened for further work. |
|
4126 | 4133 | |
|
4127 | 4134 | * Modified dirs and friends. dirs now *returns* the stack (not |
|
4128 | 4135 | prints), so one can manipulate it as a variable. Convenient to |
|
4129 | 4136 | travel along many directories. |
|
4130 | 4137 | |
|
4131 | 4138 | * Fixed bug in magic_pdef: would only work with functions with |
|
4132 | 4139 | arguments with default values. |
|
4133 | 4140 | |
|
4134 | 4141 | 2001-11-14 Fernando Perez <fperez@colorado.edu> |
|
4135 | 4142 | |
|
4136 | 4143 | * Added the PhysicsInput stuff to dot_ipython so it ships as an |
|
4137 | 4144 | example with IPython. Various other minor fixes and cleanups. |
|
4138 | 4145 | |
|
4139 | 4146 | * Version 0.1.9 released, 0.1.10 opened for further work. |
|
4140 | 4147 | |
|
4141 | 4148 | * Added sys.path to the list of directories searched in the |
|
4142 | 4149 | execfile= option. It used to be the current directory and the |
|
4143 | 4150 | user's IPYTHONDIR only. |
|
4144 | 4151 | |
|
4145 | 4152 | 2001-11-13 Fernando Perez <fperez@colorado.edu> |
|
4146 | 4153 | |
|
4147 | 4154 | * Reinstated the raw_input/prefilter separation that Janko had |
|
4148 | 4155 | initially. This gives a more convenient setup for extending the |
|
4149 | 4156 | pre-processor from the outside: raw_input always gets a string, |
|
4150 | 4157 | and prefilter has to process it. We can then redefine prefilter |
|
4151 | 4158 | from the outside and implement extensions for special |
|
4152 | 4159 | purposes. |
|
4153 | 4160 | |
|
4154 | 4161 | Today I got one for inputting PhysicalQuantity objects |
|
4155 | 4162 | (from Scientific) without needing any function calls at |
|
4156 | 4163 | all. Extremely convenient, and it's all done as a user-level |
|
4157 | 4164 | extension (no IPython code was touched). Now instead of: |
|
4158 | 4165 | a = PhysicalQuantity(4.2,'m/s**2') |
|
4159 | 4166 | one can simply say |
|
4160 | 4167 | a = 4.2 m/s**2 |
|
4161 | 4168 | or even |
|
4162 | 4169 | a = 4.2 m/s^2 |
|
4163 | 4170 | |
|
4164 | 4171 | I use this, but it's also a proof of concept: IPython really is |
|
4165 | 4172 | fully user-extensible, even at the level of the parsing of the |
|
4166 | 4173 | command line. It's not trivial, but it's perfectly doable. |
|
4167 | 4174 | |
|
4168 | 4175 | * Added 'add_flip' method to inclusion conflict resolver. Fixes |
|
4169 | 4176 | the problem of modules being loaded in the inverse order in which |
|
4170 | 4177 | they were defined in |
|
4171 | 4178 | |
|
4172 | 4179 | * Version 0.1.8 released, 0.1.9 opened for further work. |
|
4173 | 4180 | |
|
4174 | 4181 | * Added magics pdef, source and file. They respectively show the |
|
4175 | 4182 | definition line ('prototype' in C), source code and full python |
|
4176 | 4183 | file for any callable object. The object inspector oinfo uses |
|
4177 | 4184 | these to show the same information. |
|
4178 | 4185 | |
|
4179 | 4186 | * Version 0.1.7 released, 0.1.8 opened for further work. |
|
4180 | 4187 | |
|
4181 | 4188 | * Separated all the magic functions into a class called Magic. The |
|
4182 | 4189 | InteractiveShell class was becoming too big for Xemacs to handle |
|
4183 | 4190 | (de-indenting a line would lock it up for 10 seconds while it |
|
4184 | 4191 | backtracked on the whole class!) |
|
4185 | 4192 | |
|
4186 | 4193 | FIXME: didn't work. It can be done, but right now namespaces are |
|
4187 | 4194 | all messed up. Do it later (reverted it for now, so at least |
|
4188 | 4195 | everything works as before). |
|
4189 | 4196 | |
|
4190 | 4197 | * Got the object introspection system (magic_oinfo) working! I |
|
4191 | 4198 | think this is pretty much ready for release to Janko, so he can |
|
4192 | 4199 | test it for a while and then announce it. Pretty much 100% of what |
|
4193 | 4200 | I wanted for the 'phase 1' release is ready. Happy, tired. |
|
4194 | 4201 | |
|
4195 | 4202 | 2001-11-12 Fernando Perez <fperez@colorado.edu> |
|
4196 | 4203 | |
|
4197 | 4204 | * Version 0.1.6 released, 0.1.7 opened for further work. |
|
4198 | 4205 | |
|
4199 | 4206 | * Fixed bug in printing: it used to test for truth before |
|
4200 | 4207 | printing, so 0 wouldn't print. Now checks for None. |
|
4201 | 4208 | |
|
4202 | 4209 | * Fixed bug where auto-execs increase the prompt counter by 2 (b/c |
|
4203 | 4210 | they have to call len(str(sys.ps1)) ). But the fix is ugly, it |
|
4204 | 4211 | reaches by hand into the outputcache. Think of a better way to do |
|
4205 | 4212 | this later. |
|
4206 | 4213 | |
|
4207 | 4214 | * Various small fixes thanks to Nathan's comments. |
|
4208 | 4215 | |
|
4209 | 4216 | * Changed magic_pprint to magic_Pprint. This way it doesn't |
|
4210 | 4217 | collide with pprint() and the name is consistent with the command |
|
4211 | 4218 | line option. |
|
4212 | 4219 | |
|
4213 | 4220 | * Changed prompt counter behavior to be fully like |
|
4214 | 4221 | Mathematica's. That is, even input that doesn't return a result |
|
4215 | 4222 | raises the prompt counter. The old behavior was kind of confusing |
|
4216 | 4223 | (getting the same prompt number several times if the operation |
|
4217 | 4224 | didn't return a result). |
|
4218 | 4225 | |
|
4219 | 4226 | * Fixed Nathan's last name in a couple of places (Gray, not Graham). |
|
4220 | 4227 | |
|
4221 | 4228 | * Fixed -Classic mode (wasn't working anymore). |
|
4222 | 4229 | |
|
4223 | 4230 | * Added colored prompts using Nathan's new code. Colors are |
|
4224 | 4231 | currently hardwired, they can be user-configurable. For |
|
4225 | 4232 | developers, they can be chosen in file ipythonlib.py, at the |
|
4226 | 4233 | beginning of the CachedOutput class def. |
|
4227 | 4234 | |
|
4228 | 4235 | 2001-11-11 Fernando Perez <fperez@colorado.edu> |
|
4229 | 4236 | |
|
4230 | 4237 | * Version 0.1.5 released, 0.1.6 opened for further work. |
|
4231 | 4238 | |
|
4232 | 4239 | * Changed magic_env to *return* the environment as a dict (not to |
|
4233 | 4240 | print it). This way it prints, but it can also be processed. |
|
4234 | 4241 | |
|
4235 | 4242 | * Added Verbose exception reporting to interactive |
|
4236 | 4243 | exceptions. Very nice, now even 1/0 at the prompt gives a verbose |
|
4237 | 4244 | traceback. Had to make some changes to the ultraTB file. This is |
|
4238 | 4245 | probably the last 'big' thing in my mental todo list. This ties |
|
4239 | 4246 | in with the next entry: |
|
4240 | 4247 | |
|
4241 | 4248 | * Changed -Xi and -Xf to a single -xmode option. Now all the user |
|
4242 | 4249 | has to specify is Plain, Color or Verbose for all exception |
|
4243 | 4250 | handling. |
|
4244 | 4251 | |
|
4245 | 4252 | * Removed ShellServices option. All this can really be done via |
|
4246 | 4253 | the magic system. It's easier to extend, cleaner and has automatic |
|
4247 | 4254 | namespace protection and documentation. |
|
4248 | 4255 | |
|
4249 | 4256 | 2001-11-09 Fernando Perez <fperez@colorado.edu> |
|
4250 | 4257 | |
|
4251 | 4258 | * Fixed bug in output cache flushing (missing parameter to |
|
4252 | 4259 | __init__). Other small bugs fixed (found using pychecker). |
|
4253 | 4260 | |
|
4254 | 4261 | * Version 0.1.4 opened for bugfixing. |
|
4255 | 4262 | |
|
4256 | 4263 | 2001-11-07 Fernando Perez <fperez@colorado.edu> |
|
4257 | 4264 | |
|
4258 | 4265 | * Version 0.1.3 released, mainly because of the raw_input bug. |
|
4259 | 4266 | |
|
4260 | 4267 | * Fixed NASTY bug in raw_input: input line wasn't properly parsed |
|
4261 | 4268 | and when testing for whether things were callable, a call could |
|
4262 | 4269 | actually be made to certain functions. They would get called again |
|
4263 | 4270 | once 'really' executed, with a resulting double call. A disaster |
|
4264 | 4271 | in many cases (list.reverse() would never work!). |
|
4265 | 4272 | |
|
4266 | 4273 | * Removed prefilter() function, moved its code to raw_input (which |
|
4267 | 4274 | after all was just a near-empty caller for prefilter). This saves |
|
4268 | 4275 | a function call on every prompt, and simplifies the class a tiny bit. |
|
4269 | 4276 | |
|
4270 | 4277 | * Fix _ip to __ip name in magic example file. |
|
4271 | 4278 | |
|
4272 | 4279 | * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should |
|
4273 | 4280 | work with non-gnu versions of tar. |
|
4274 | 4281 | |
|
4275 | 4282 | 2001-11-06 Fernando Perez <fperez@colorado.edu> |
|
4276 | 4283 | |
|
4277 | 4284 | * Version 0.1.2. Just to keep track of the recent changes. |
|
4278 | 4285 | |
|
4279 | 4286 | * Fixed nasty bug in output prompt routine. It used to check 'if |
|
4280 | 4287 | arg != None...'. Problem is, this fails if arg implements a |
|
4281 | 4288 | special comparison (__cmp__) which disallows comparing to |
|
4282 | 4289 | None. Found it when trying to use the PhysicalQuantity module from |
|
4283 | 4290 | ScientificPython. |
|
4284 | 4291 | |
|
4285 | 4292 | 2001-11-05 Fernando Perez <fperez@colorado.edu> |
|
4286 | 4293 | |
|
4287 | 4294 | * Also added dirs. Now the pushd/popd/dirs family functions |
|
4288 | 4295 | basically like the shell, with the added convenience of going home |
|
4289 | 4296 | when called with no args. |
|
4290 | 4297 | |
|
4291 | 4298 | * pushd/popd slightly modified to mimic shell behavior more |
|
4292 | 4299 | closely. |
|
4293 | 4300 | |
|
4294 | 4301 | * Added env,pushd,popd from ShellServices as magic functions. I |
|
4295 | 4302 | think the cleanest will be to port all desired functions from |
|
4296 | 4303 | ShellServices as magics and remove ShellServices altogether. This |
|
4297 | 4304 | will provide a single, clean way of adding functionality |
|
4298 | 4305 | (shell-type or otherwise) to IP. |
|
4299 | 4306 | |
|
4300 | 4307 | 2001-11-04 Fernando Perez <fperez@colorado.edu> |
|
4301 | 4308 | |
|
4302 | 4309 | * Added .ipython/ directory to sys.path. This way users can keep |
|
4303 | 4310 | customizations there and access them via import. |
|
4304 | 4311 | |
|
4305 | 4312 | 2001-11-03 Fernando Perez <fperez@colorado.edu> |
|
4306 | 4313 | |
|
4307 | 4314 | * Opened version 0.1.1 for new changes. |
|
4308 | 4315 | |
|
4309 | 4316 | * Changed version number to 0.1.0: first 'public' release, sent to |
|
4310 | 4317 | Nathan and Janko. |
|
4311 | 4318 | |
|
4312 | 4319 | * Lots of small fixes and tweaks. |
|
4313 | 4320 | |
|
4314 | 4321 | * Minor changes to whos format. Now strings are shown, snipped if |
|
4315 | 4322 | too long. |
|
4316 | 4323 | |
|
4317 | 4324 | * Changed ShellServices to work on __main__ so they show up in @who |
|
4318 | 4325 | |
|
4319 | 4326 | * Help also works with ? at the end of a line: |
|
4320 | 4327 | ?sin and sin? |
|
4321 | 4328 | both produce the same effect. This is nice, as often I use the |
|
4322 | 4329 | tab-complete to find the name of a method, but I used to then have |
|
4323 | 4330 | to go to the beginning of the line to put a ? if I wanted more |
|
4324 | 4331 | info. Now I can just add the ? and hit return. Convenient. |
|
4325 | 4332 | |
|
4326 | 4333 | 2001-11-02 Fernando Perez <fperez@colorado.edu> |
|
4327 | 4334 | |
|
4328 | 4335 | * Python version check (>=2.1) added. |
|
4329 | 4336 | |
|
4330 | 4337 | * Added LazyPython documentation. At this point the docs are quite |
|
4331 | 4338 | a mess. A cleanup is in order. |
|
4332 | 4339 | |
|
4333 | 4340 | * Auto-installer created. For some bizarre reason, the zipfiles |
|
4334 | 4341 | module isn't working on my system. So I made a tar version |
|
4335 | 4342 | (hopefully the command line options in various systems won't kill |
|
4336 | 4343 | me). |
|
4337 | 4344 | |
|
4338 | 4345 | * Fixes to Struct in genutils. Now all dictionary-like methods are |
|
4339 | 4346 | protected (reasonably). |
|
4340 | 4347 | |
|
4341 | 4348 | * Added pager function to genutils and changed ? to print usage |
|
4342 | 4349 | note through it (it was too long). |
|
4343 | 4350 | |
|
4344 | 4351 | * Added the LazyPython functionality. Works great! I changed the |
|
4345 | 4352 | auto-quote escape to ';', it's on home row and next to '. But |
|
4346 | 4353 | both auto-quote and auto-paren (still /) escapes are command-line |
|
4347 | 4354 | parameters. |
|
4348 | 4355 | |
|
4349 | 4356 | |
|
4350 | 4357 | 2001-11-01 Fernando Perez <fperez@colorado.edu> |
|
4351 | 4358 | |
|
4352 | 4359 | * Version changed to 0.0.7. Fairly large change: configuration now |
|
4353 | 4360 | is all stored in a directory, by default .ipython. There, all |
|
4354 | 4361 | config files have normal looking names (not .names) |
|
4355 | 4362 | |
|
4356 | 4363 | * Version 0.0.6 Released first to Lucas and Archie as a test |
|
4357 | 4364 | run. Since it's the first 'semi-public' release, change version to |
|
4358 | 4365 | > 0.0.6 for any changes now. |
|
4359 | 4366 | |
|
4360 | 4367 | * Stuff I had put in the ipplib.py changelog: |
|
4361 | 4368 | |
|
4362 | 4369 | Changes to InteractiveShell: |
|
4363 | 4370 | |
|
4364 | 4371 | - Made the usage message a parameter. |
|
4365 | 4372 | |
|
4366 | 4373 | - Require the name of the shell variable to be given. It's a bit |
|
4367 | 4374 | of a hack, but allows the name 'shell' not to be hardwire in the |
|
4368 | 4375 | magic (@) handler, which is problematic b/c it requires |
|
4369 | 4376 | polluting the global namespace with 'shell'. This in turn is |
|
4370 | 4377 | fragile: if a user redefines a variable called shell, things |
|
4371 | 4378 | break. |
|
4372 | 4379 | |
|
4373 | 4380 | - magic @: all functions available through @ need to be defined |
|
4374 | 4381 | as magic_<name>, even though they can be called simply as |
|
4375 | 4382 | @<name>. This allows the special command @magic to gather |
|
4376 | 4383 | information automatically about all existing magic functions, |
|
4377 | 4384 | even if they are run-time user extensions, by parsing the shell |
|
4378 | 4385 | instance __dict__ looking for special magic_ names. |
|
4379 | 4386 | |
|
4380 | 4387 | - mainloop: added *two* local namespace parameters. This allows |
|
4381 | 4388 | the class to differentiate between parameters which were there |
|
4382 | 4389 | before and after command line initialization was processed. This |
|
4383 | 4390 | way, later @who can show things loaded at startup by the |
|
4384 | 4391 | user. This trick was necessary to make session saving/reloading |
|
4385 | 4392 | really work: ideally after saving/exiting/reloading a session, |
|
4386 | 4393 | *everythin* should look the same, including the output of @who. I |
|
4387 | 4394 | was only able to make this work with this double namespace |
|
4388 | 4395 | trick. |
|
4389 | 4396 | |
|
4390 | 4397 | - added a header to the logfile which allows (almost) full |
|
4391 | 4398 | session restoring. |
|
4392 | 4399 | |
|
4393 | 4400 | - prepend lines beginning with @ or !, with a and log |
|
4394 | 4401 | them. Why? !lines: may be useful to know what you did @lines: |
|
4395 | 4402 | they may affect session state. So when restoring a session, at |
|
4396 | 4403 | least inform the user of their presence. I couldn't quite get |
|
4397 | 4404 | them to properly re-execute, but at least the user is warned. |
|
4398 | 4405 | |
|
4399 | 4406 | * Started ChangeLog. |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now