##// END OF EJS Templates
Major cleanups and changes, see changelog/changeset for full details.
fperez -
Show More
@@ -1,187 +1,221 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 Logger class for IPython's logging facilities.
4 4
5 $Id: Logger.py 958 2005-12-27 23:17:51Z fperez $
5 $Id: Logger.py 966 2005-12-29 08:34:07Z fperez $
6 6 """
7 7
8 8 #*****************************************************************************
9 9 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
10 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
10 # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu>
11 11 #
12 12 # Distributed under the terms of the BSD License. The full license is in
13 13 # the file COPYING, distributed as part of this software.
14 14 #*****************************************************************************
15 15
16 16 #****************************************************************************
17 17 # Modules and globals
18 18
19 19 from IPython import Release
20 20 __author__ = '%s <%s>\n%s <%s>' % \
21 21 ( Release.authors['Janko'] + Release.authors['Fernando'] )
22 22 __license__ = Release.license
23 23
24 24 # Python standard modules
25 25 import glob
26 26 import os
27 import sys
28
29 # Homebrewed
30 from IPython.genutils import *
27 import time
31 28
32 29 #****************************************************************************
33 # FIXME: The logger class shouldn't be a mixin, it throws too many things into
34 # the InteractiveShell namespace. Rather make it a standalone tool, and create
35 # a Logger instance in InteractiveShell that uses it. Doing this will require
36 # tracking down a *lot* of nasty uses of the Logger attributes in
37 # InteractiveShell, but will clean up things quite a bit.
38
39 class Logger:
40 """A Logfile Mixin class with different policies for file creation"""
41
42 # FIXME: once this isn't a mixin, log_ns should just be 'namespace', since the
43 # names won't collide anymore.
44 def __init__(self,log_ns):
30 # FIXME: This class isn't a mixin anymore, but it still needs attributes from
31 # ipython and does input cache management. Finish cleanup later...
32
33 class Logger(object):
34 """A Logfile class with different policies for file creation"""
35
36 def __init__(self,shell,logfname='Logger.log',loghead='',logmode='over'):
37
45 38 self._i00,self._i,self._ii,self._iii = '','','',''
46 self.do_full_cache = 0 # FIXME. There's also a do_full.. in OutputCache
47 self.log_ns = log_ns
48 # defaults
49 self.LOGMODE = 'backup'
50 self.defname = 'logfile'
51
52 def create_log(self,header='',fname='',defname='.Logger.log'):
53 """Generate a new log-file with a default header"""
54 if fname:
55 self.LOG = fname
56 39
57 if self.LOG:
58 self.logfname = self.LOG
59 else:
60 self.logfname = defname
40 # this is the full ipython instance, we need some attributes from it
41 # which won't exist until later. What a mess, clean up later...
42 self.shell = shell
43
44 self.logfname = logfname
45 self.loghead = loghead
46 self.logmode = logmode
47 self.logfile = None
48
49 # whether to also log output
50 self.log_output = False
51
52 # whether to put timestamps before each log entry
53 self.timestamp = False
54
55 # activity control flags
56 self.log_active = False
57
58 # logmode is a validated property
59 def _set_mode(self,mode):
60 if mode not in ['append','backup','global','over','rotate']:
61 raise ValueError,'invalid log mode %s given' % mode
62 self._logmode = mode
63
64 def _get_mode(self):
65 return self._logmode
66
67 logmode = property(_get_mode,_set_mode)
68
69 def logstart(self,logfname=None,loghead=None,logmode=None,
70 log_output=False,timestamp=False):
71 """Generate a new log-file with a default header.
72
73 Raises RuntimeError if the log has already been started"""
74
75 if self.logfile is not None:
76 raise RuntimeError('Log file is already active: %s' %
77 self.logfname)
61 78
62 if self.LOGMODE == 'over':
63 if os.path.isfile(self.logfname):
64 os.remove(self.logfname)
65 self.logfile = open(self.logfname,'w')
66 if self.LOGMODE == 'backup':
67 if os.path.isfile(self.logfname):
79 self.log_active = True
80
81 # The three parameters can override constructor defaults
82 if logfname: self.logfname = logfname
83 if loghead: self.loghead = loghead
84 if logmode: self.logmode = logmode
85 self.timestamp = timestamp
86 self.log_output = log_output
87
88 # init depending on the log mode requested
89 isfile = os.path.isfile
90 logmode = self.logmode
91
92 if logmode == 'append':
93 self.logfile = open(self.logfname,'a')
94
95 elif logmode == 'backup':
96 if isfile(self.logfname):
68 97 backup_logname = self.logfname+'~'
69 98 # Manually remove any old backup, since os.rename may fail
70 99 # under Windows.
71 if os.path.isfile(backup_logname):
100 if isfile(backup_logname):
72 101 os.remove(backup_logname)
73 102 os.rename(self.logfname,backup_logname)
74 103 self.logfile = open(self.logfname,'w')
75 elif self.LOGMODE == 'global':
76 self.logfname = os.path.join(self.home_dir, self.defname)
104
105 elif logmode == 'global':
106 self.logfname = os.path.join(self.shell.home_dir,self.logfname)
77 107 self.logfile = open(self.logfname, 'a')
78 self.LOG = self.logfname
79 elif self.LOGMODE == 'rotate':
80 if os.path.isfile(self.logfname):
81 if os.path.isfile(self.logfname+'.001~'):
108
109 elif logmode == 'over':
110 if isfile(self.logfname):
111 os.remove(self.logfname)
112 self.logfile = open(self.logfname,'w')
113
114 elif logmode == 'rotate':
115 if isfile(self.logfname):
116 if isfile(self.logfname+'.001~'):
82 117 old = glob.glob(self.logfname+'.*~')
83 118 old.sort()
84 119 old.reverse()
85 120 for f in old:
86 121 root, ext = os.path.splitext(f)
87 122 num = int(ext[1:-1])+1
88 123 os.rename(f, root+'.'+`num`.zfill(3)+'~')
89 124 os.rename(self.logfname, self.logfname+'.001~')
90 125 self.logfile = open(self.logfname,'w')
91 elif self.LOGMODE == 'append':
92 self.logfile = open(self.logfname,'a')
93 126
94 if self.LOGMODE != 'append':
95 self.logfile.write(header)
96 self.logfile.flush()
127 if logmode != 'append':
128 self.logfile.write(self.loghead)
97 129
98 def logstart(self, header='',parameter_s = ''):
99 if not hasattr(self, 'LOG'):
100 logfname = self.LOG or parameter_s or './'+self.defname
101 self.create_log(header,logfname)
102 elif parameter_s and hasattr(self,'logfname') and \
103 parameter_s != self.logfname:
104 self.close_log()
105 self.create_log(header,parameter_s)
106
107 self._dolog = 1
130 self.logfile.flush()
108 131
109 132 def switch_log(self,val):
110 """Switch logging on/off. val should be ONLY 0 or 1."""
133 """Switch logging on/off. val should be ONLY a boolean."""
111 134
112 if not val in [0,1]:
135 if val not in [False,True,0,1]:
113 136 raise ValueError, \
114 'Call switch_log ONLY with 0 or 1 as argument, not with:',val
137 'Call switch_log ONLY with a boolean argument, not with:',val
115 138
116 label = {0:'OFF',1:'ON'}
139 label = {0:'OFF',1:'ON',False:'OFF',True:'ON'}
117 140
118 try:
119 _ = self.logfile
120 except AttributeError:
141 if self.logfile is None:
121 142 print """
122 Logging hasn't been started yet (use %logstart for that).
143 Logging hasn't been started yet (use logstart for that).
123 144
124 145 %logon/%logoff are for temporarily starting and stopping logging for a logfile
125 146 which already exists. But you must first start the logging process with
126 147 %logstart (optionally giving a logfile name)."""
127 148
128 149 else:
129 if self._dolog == val:
150 if self.log_active == val:
130 151 print 'Logging is already',label[val]
131 152 else:
132 153 print 'Switching logging',label[val]
133 self._dolog = 1 - self._dolog
154 self.log_active = not self.log_active
155 self.log_active_out = self.log_active
134 156
135 157 def logstate(self):
136 158 """Print a status message about the logger."""
137 try:
138 logfile = self.logfname
139 except:
159 if self.logfile is None:
140 160 print 'Logging has not been activated.'
141 161 else:
142 state = self._dolog and 'active' or 'temporarily suspended'
143 print """
144 File:\t%s
145 Mode:\t%s
146 State:\t%s """ % (logfile,self.LOGMODE,state)
162 state = self.log_active and 'active' or 'temporarily suspended'
163 print 'Filename :',self.logfname
164 print 'Mode :',self.logmode
165 print 'Output logging:',self.log_output
166 print 'Timestamping :',self.timestamp
167 print 'State :',state
147 168
148
149 169 def log(self, line,continuation=None):
150 170 """Write the line to a log and create input cache variables _i*."""
151 171
152 172 # update the auto _i tables
153 173 #print '***logging line',line # dbg
154 #print '***cache_count', self.outputcache.prompt_count # dbg
155 input_hist = self.log_ns['_ih']
174 #print '***cache_count', self.shell.outputcache.prompt_count # dbg
175 input_hist = self.shell.user_ns['_ih']
156 176 if not continuation and line:
157 177 self._iii = self._ii
158 178 self._ii = self._i
159 179 self._i = self._i00
160 180 # put back the final \n of every input line
161 181 self._i00 = line+'\n'
162 182 #print 'Logging input:<%s>' % line # dbg
163 183 input_hist.append(self._i00)
164 184
165 185 # hackish access to top-level namespace to create _i1,_i2... dynamically
166 186 to_main = {'_i':self._i,'_ii':self._ii,'_iii':self._iii}
167 if self.do_full_cache:
168 in_num = self.outputcache.prompt_count
169 # add blank lines if the input cache fell out of sync. This can happen
170 # for embedded instances which get killed via C-D and then get resumed.
187 if self.shell.outputcache.do_full_cache:
188 in_num = self.shell.outputcache.prompt_count
189 # add blank lines if the input cache fell out of sync. This can
190 # happen for embedded instances which get killed via C-D and then
191 # get resumed.
171 192 while in_num >= len(input_hist):
172 193 input_hist.append('\n')
173 194 new_i = '_i%s' % in_num
174 195 if continuation:
175 self._i00 = '%s%s\n' % (self.log_ns[new_i],line)
196 self._i00 = '%s%s\n' % (self.shell.user_ns[new_i],line)
176 197 input_hist[in_num] = self._i00
177 198 to_main[new_i] = self._i00
178 self.log_ns.update(to_main)
179
180 if self._dolog and line:
181 self.logfile.write(line+'\n')
199 self.shell.user_ns.update(to_main)
200 self.log_write(line)
201
202 def log_write(self,data,kind='input'):
203 """Write data to the log file, if active"""
204
205 if self.log_active and data:
206 write = self.logfile.write
207 if kind=='input':
208 if self.timestamp:
209 write(time.strftime('# %a, %d %b %Y %H:%M:%S\n',
210 time.localtime()))
211 write('%s\n' % data)
212 elif kind=='output' and self.log_output:
213 odata = '\n'.join(['#[Out]# %s' % s
214 for s in data.split('\n')])
215 write('%s\n' % odata)
182 216 self.logfile.flush()
183 217
184 218 def close_log(self):
185 if hasattr(self, 'logfile'):
186 self.logfile.close()
187 self.logfname = ''
219 self.logfile.close()
220 self.logfile = None
221 self.logfname = ''
@@ -1,2620 +1,2594 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 965 2005-12-28 23:23:09Z fperez $"""
4 $Id: Magic.py 966 2005-12-29 08:34:07Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
8 8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #*****************************************************************************
13 13
14 14 #****************************************************************************
15 15 # Modules and globals
16 16
17 17 from IPython import Release
18 18 __author__ = '%s <%s>\n%s <%s>' % \
19 19 ( Release.authors['Janko'] + Release.authors['Fernando'] )
20 20 __license__ = Release.license
21 21
22 22 # Python standard modules
23 23 import __builtin__
24 24 import bdb
25 25 import inspect
26 26 import os
27 27 import pdb
28 28 import pydoc
29 29 import sys
30 30 import re
31 31 import tempfile
32 32 import time
33 33 from cStringIO import StringIO
34 34 from getopt import getopt
35 35 from pprint import pprint, pformat
36 36
37 37 # profile isn't bundled by default in Debian for license reasons
38 38 try:
39 39 import profile,pstats
40 40 except ImportError:
41 41 profile = pstats = None
42 42
43 43 # Homebrewed
44 44 from IPython import Debugger, OInspect, wildcard
45 45 from IPython.FakeModule import FakeModule
46 46 from IPython.Itpl import Itpl, itpl, printpl,itplns
47 47 from IPython.PyColorize import Parser
48 48 from IPython.Struct import Struct
49 49 from IPython.genutils import *
50 50
51 # Globals to be set later by Magic constructor
52 MAGIC_PREFIX = ''
53 MAGIC_ESCAPE = ''
54
55 51 #***************************************************************************
56 52 # Utility functions
57 def magic2python(cmd):
58 """Convert a command string of magic syntax to valid Python code."""
59
60 if cmd.startswith('#'+MAGIC_ESCAPE) or \
61 cmd.startswith(MAGIC_ESCAPE):
62 if cmd[0]=='#':
63 cmd = cmd[1:]
64 # we need to return the proper line end later
65 if cmd[-1] == '\n':
66 endl = '\n'
67 else:
68 endl = ''
69 try:
70 func,args = cmd[1:].split(' ',1)
71 except:
72 func,args = cmd[1:].rstrip(),''
73 args = args.replace('"','\\"').replace("'","\\'").rstrip()
74 return '%s%s ("%s")%s' % (MAGIC_PREFIX,func,args,endl)
75 else:
76 return cmd
77
78 53 def on_off(tag):
79 54 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
80 55 return ['OFF','ON'][tag]
81 56
82 57
83 58 #****************************************************************************
84 59 # Utility classes
85 class Macro:
60 class Macro(list):
86 61 """Simple class to store the value of macros as strings.
87 62
88 63 This allows us to later exec them by checking when something is an
89 64 instance of this class."""
90
91 def __init__(self,cmds):
92 """Build a macro from a list of commands."""
93 65
94 # Since the list may include multi-line entries, first make sure that
95 # they've been all broken up before passing it to magic2python
96 cmdlist = map(magic2python,''.join(cmds).split('\n'))
97 self.value = '\n'.join(cmdlist)
98
99 def __str__(self):
100 return self.value
66 def __init__(self,data):
67 list.__init__(self,data)
68 self.value = ''.join(data)
101 69
102 70 #***************************************************************************
103 71 # Main class implementing Magic functionality
104 72 class Magic:
105 73 """Magic functions for InteractiveShell.
106 74
107 75 Shell functions which can be reached as %function_name. All magic
108 76 functions should accept a string, which they can parse for their own
109 77 needs. This can make some functions easier to type, eg `%cd ../`
110 78 vs. `%cd("../")`
111 79
112 80 ALL definitions MUST begin with the prefix magic_. The user won't need it
113 81 at the command line, but it is is needed in the definition. """
114 82
115 83 # class globals
116 84 auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.',
117 85 'Automagic is ON, % prefix NOT needed for magic functions.']
118 86
119 87 #......................................................................
120 88 # some utility functions
121 89
122 90 def __init__(self,shell):
123 # XXX This is hackish, clean up later to avoid these messy globals
124 global MAGIC_PREFIX, MAGIC_ESCAPE
125 91
126 92 self.options_table = {}
127 MAGIC_PREFIX = shell.name+'.magic_'
128 MAGIC_ESCAPE = shell.ESC_MAGIC
129 93 if profile is None:
130 94 self.magic_prun = self.profile_missing_notice
95 self.shell = shell
131 96
132 97 def profile_missing_notice(self, *args, **kwargs):
133 98 error("""\
134 99 The profile module could not be found. If you are a Debian user,
135 100 it has been removed from the standard Debian package because of its non-free
136 101 license. To use profiling, please install"python2.3-profiler" from non-free.""")
137
102
138 103 def default_option(self,fn,optstr):
139 104 """Make an entry in the options_table for fn, with value optstr"""
140 105
141 106 if fn not in self.lsmagic():
142 107 error("%s is not a magic function" % fn)
143 108 self.options_table[fn] = optstr
144 109
145 110 def lsmagic(self):
146 111 """Return a list of currently available magic functions.
147 112
148 113 Gives a list of the bare names after mangling (['ls','cd', ...], not
149 114 ['magic_ls','magic_cd',...]"""
150 115
151 116 # FIXME. This needs a cleanup, in the way the magics list is built.
152 117
153 118 # magics in class definition
154 119 class_magic = lambda fn: fn.startswith('magic_') and \
155 120 callable(Magic.__dict__[fn])
156 121 # in instance namespace (run-time user additions)
157 122 inst_magic = lambda fn: fn.startswith('magic_') and \
158 123 callable(self.__dict__[fn])
159 124 # and bound magics by user (so they can access self):
160 125 inst_bound_magic = lambda fn: fn.startswith('magic_') and \
161 126 callable(self.__class__.__dict__[fn])
162 127 magics = filter(class_magic,Magic.__dict__.keys()) + \
163 128 filter(inst_magic,self.__dict__.keys()) + \
164 129 filter(inst_bound_magic,self.__class__.__dict__.keys())
165 130 out = []
166 131 for fn in magics:
167 132 out.append(fn.replace('magic_','',1))
168 133 out.sort()
169 134 return out
170 135
171 def set_shell(self,shell):
172 self.shell = shell
173 self.alias_table = shell.alias_table
174
175 136 def extract_input_slices(self,slices):
176 137 """Return as a string a set of input history slices.
177 138
178 139 The set of slices is given as a list of strings (like ['1','4:8','9'],
179 140 since this function is for use by magic functions which get their
180 141 arguments as strings."""
181 142
182 143 cmds = []
183 144 for chunk in slices:
184 145 if ':' in chunk:
185 146 ini,fin = map(int,chunk.split(':'))
186 147 else:
187 148 ini = int(chunk)
188 149 fin = ini+1
189 150 cmds.append(self.shell.input_hist[ini:fin])
190 151 return cmds
191 152
192 153 def _ofind(self,oname):
193 154 """Find an object in the available namespaces.
194 155
195 156 self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic
196 157
197 158 Has special code to detect magic functions.
198 159 """
199 160
200 161 oname = oname.strip()
201 162
202 163 # Namespaces to search in:
203 164 user_ns = self.shell.user_ns
204 165 internal_ns = self.shell.internal_ns
205 166 builtin_ns = __builtin__.__dict__
206 167 alias_ns = self.shell.alias_table
207 168
208 169 # Put them in a list. The order is important so that we find things in
209 170 # the same order that Python finds them.
210 171 namespaces = [ ('Interactive',user_ns),
211 172 ('IPython internal',internal_ns),
212 173 ('Python builtin',builtin_ns),
213 174 ('Alias',alias_ns),
214 175 ]
215 176
216 177 # initialize results to 'null'
217 178 found = 0; obj = None; ospace = None; ds = None;
218 179 ismagic = 0; isalias = 0
219 180
220 181 # Look for the given name by splitting it in parts. If the head is
221 182 # found, then we look for all the remaining parts as members, and only
222 183 # declare success if we can find them all.
223 184 oname_parts = oname.split('.')
224 185 oname_head, oname_rest = oname_parts[0],oname_parts[1:]
225 186 for nsname,ns in namespaces:
226 187 try:
227 188 obj = ns[oname_head]
228 189 except KeyError:
229 190 continue
230 191 else:
231 192 for part in oname_rest:
232 193 try:
233 194 obj = getattr(obj,part)
234 195 except:
235 196 # Blanket except b/c some badly implemented objects
236 197 # allow __getattr__ to raise exceptions other than
237 198 # AttributeError, which then crashes IPython.
238 199 break
239 200 else:
240 201 # If we finish the for loop (no break), we got all members
241 202 found = 1
242 203 ospace = nsname
243 204 if ns == alias_ns:
244 205 isalias = 1
245 206 break # namespace loop
246 207
247 208 # Try to see if it's magic
248 209 if not found:
249 210 if oname.startswith(self.shell.ESC_MAGIC):
250 211 oname = oname[1:]
251 212 obj = getattr(self,'magic_'+oname,None)
252 213 if obj is not None:
253 214 found = 1
254 215 ospace = 'IPython internal'
255 216 ismagic = 1
256 217
257 218 # Last try: special-case some literals like '', [], {}, etc:
258 219 if not found and oname_head in ["''",'""','[]','{}','()']:
259 220 obj = eval(oname_head)
260 221 found = 1
261 222 ospace = 'Interactive'
262 223
263 224 return {'found':found, 'obj':obj, 'namespace':ospace,
264 225 'ismagic':ismagic, 'isalias':isalias}
265 226
266 227 def arg_err(self,func):
267 228 """Print docstring if incorrect arguments were passed"""
268 229 print 'Error in arguments:'
269 230 print OInspect.getdoc(func)
270 231
271 232
272 233 def format_latex(self,str):
273 234 """Format a string for latex inclusion."""
274 235
275 236 # Characters that need to be escaped for latex:
276 237 escape_re = re.compile(r'(%|_|\$)',re.MULTILINE)
277 238 # Magic command names as headers:
278 239 cmd_name_re = re.compile(r'^(%s.*?):' % self.shell.ESC_MAGIC,
279 240 re.MULTILINE)
280 241 # Magic commands
281 242 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % self.shell.ESC_MAGIC,
282 243 re.MULTILINE)
283 244 # Paragraph continue
284 245 par_re = re.compile(r'\\$',re.MULTILINE)
285 246
286 247 str = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',str)
287 248 str = cmd_re.sub(r'\\texttt{\g<cmd>}',str)
288 249 str = par_re.sub(r'\\\\',str)
289 250 str = escape_re.sub(r'\\\1',str)
290 251 return str
291 252
292 253 def format_screen(self,str):
293 254 """Format a string for screen printing.
294 255
295 256 This removes some latex-type format codes."""
296 257 # Paragraph continue
297 258 par_re = re.compile(r'\\$',re.MULTILINE)
298 259 str = par_re.sub('',str)
299 260 return str
300 261
301 262 def parse_options(self,arg_str,opt_str,*long_opts,**kw):
302 263 """Parse options passed to an argument string.
303 264
304 265 The interface is similar to that of getopt(), but it returns back a
305 266 Struct with the options as keys and the stripped argument string still
306 267 as a string.
307 268
308 269 arg_str is quoted as a true sys.argv vector by using shlex.split.
309 270 This allows us to easily expand variables, glob files, quote
310 271 arguments, etc.
311 272
312 273 Options:
313 274 -mode: default 'string'. If given as 'list', the argument string is
314 275 returned as a list (split on whitespace) instead of a string.
315 276
316 277 -list_all: put all option values in lists. Normally only options
317 278 appearing more than once are put in a list."""
318 279
319 280 # inject default options at the beginning of the input line
320 281 caller = sys._getframe(1).f_code.co_name.replace('magic_','')
321 282 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
322 283
323 284 mode = kw.get('mode','string')
324 285 if mode not in ['string','list']:
325 286 raise ValueError,'incorrect mode given: %s' % mode
326 287 # Get options
327 288 list_all = kw.get('list_all',0)
328 289
329 290 # Check if we have more than one argument to warrant extra processing:
330 291 odict = {} # Dictionary with options
331 292 args = arg_str.split()
332 293 if len(args) >= 1:
333 294 # If the list of inputs only has 0 or 1 thing in it, there's no
334 295 # need to look for options
335 296 argv = shlex_split(arg_str)
336 297 # Do regular option processing
337 298 opts,args = getopt(argv,opt_str,*long_opts)
338 299 for o,a in opts:
339 300 if o.startswith('--'):
340 301 o = o[2:]
341 302 else:
342 303 o = o[1:]
343 304 try:
344 305 odict[o].append(a)
345 306 except AttributeError:
346 307 odict[o] = [odict[o],a]
347 308 except KeyError:
348 309 if list_all:
349 310 odict[o] = [a]
350 311 else:
351 312 odict[o] = a
352 313
353 314 # Prepare opts,args for return
354 315 opts = Struct(odict)
355 316 if mode == 'string':
356 317 args = ' '.join(args)
357 318
358 319 return opts,args
359 320
360 321 #......................................................................
361 322 # And now the actual magic functions
362 323
363 324 # Functions for IPython shell work (vars,funcs, config, etc)
364 325 def magic_lsmagic(self, parameter_s = ''):
365 326 """List currently available magic functions."""
366 327 mesc = self.shell.ESC_MAGIC
367 328 print 'Available magic functions:\n'+mesc+\
368 329 (' '+mesc).join(self.lsmagic())
369 330 print '\n' + Magic.auto_status[self.shell.rc.automagic]
370 331 return None
371 332
372 333 def magic_magic(self, parameter_s = ''):
373 334 """Print information about the magic function system."""
374 335
375 336 mode = ''
376 337 try:
377 338 if parameter_s.split()[0] == '-latex':
378 339 mode = 'latex'
379 340 except:
380 341 pass
381 342
382 343 magic_docs = []
383 344 for fname in self.lsmagic():
384 345 mname = 'magic_' + fname
385 346 for space in (Magic,self,self.__class__):
386 347 try:
387 348 fn = space.__dict__[mname]
388 349 except KeyError:
389 350 pass
390 351 else:
391 352 break
392 353 magic_docs.append('%s%s:\n\t%s\n' %(self.shell.ESC_MAGIC,
393 354 fname,fn.__doc__))
394 355 magic_docs = ''.join(magic_docs)
395 356
396 357 if mode == 'latex':
397 358 print self.format_latex(magic_docs)
398 359 return
399 360 else:
400 361 magic_docs = self.format_screen(magic_docs)
401 362
402 363 outmsg = """
403 364 IPython's 'magic' functions
404 365 ===========================
405 366
406 367 The magic function system provides a series of functions which allow you to
407 368 control the behavior of IPython itself, plus a lot of system-type
408 369 features. All these functions are prefixed with a % character, but parameters
409 370 are given without parentheses or quotes.
410 371
411 372 NOTE: If you have 'automagic' enabled (via the command line option or with the
412 373 %automagic function), you don't need to type in the % explicitly. By default,
413 374 IPython ships with automagic on, so you should only rarely need the % escape.
414 375
415 376 Example: typing '%cd mydir' (without the quotes) changes you working directory
416 377 to 'mydir', if it exists.
417 378
418 379 You can define your own magic functions to extend the system. See the supplied
419 380 ipythonrc and example-magic.py files for details (in your ipython
420 381 configuration directory, typically $HOME/.ipython/).
421 382
422 383 You can also define your own aliased names for magic functions. In your
423 384 ipythonrc file, placing a line like:
424 385
425 386 execute __IPYTHON__.magic_pf = __IPYTHON__.magic_profile
426 387
427 388 will define %pf as a new name for %profile.
428 389
429 390 You can also call magics in code using the ipmagic() function, which IPython
430 391 automatically adds to the builtin namespace. Type 'ipmagic?' for details.
431 392
432 393 For a list of the available magic functions, use %lsmagic. For a description
433 394 of any of them, type %magic_name?, e.g. '%cd?'.
434 395
435 396 Currently the magic system has the following functions:\n"""
436 397
437 398 mesc = self.shell.ESC_MAGIC
438 399 outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):"
439 400 "\n\n%s%s\n\n%s" % (outmsg,
440 401 magic_docs,mesc,mesc,
441 402 (' '+mesc).join(self.lsmagic()),
442 403 Magic.auto_status[self.shell.rc.automagic] ) )
443 404
444 405 page(outmsg,screen_lines=self.shell.rc.screen_length)
445 406
446 407 def magic_automagic(self, parameter_s = ''):
447 408 """Make magic functions callable without having to type the initial %.
448 409
449 410 Toggles on/off (when off, you must call it as %automagic, of
450 411 course). Note that magic functions have lowest priority, so if there's
451 412 a variable whose name collides with that of a magic fn, automagic
452 413 won't work for that function (you get the variable instead). However,
453 414 if you delete the variable (del var), the previously shadowed magic
454 415 function becomes visible to automagic again."""
455 416
456 417 rc = self.shell.rc
457 418 rc.automagic = not rc.automagic
458 419 print '\n' + Magic.auto_status[rc.automagic]
459 420
460 421 def magic_autocall(self, parameter_s = ''):
461 422 """Make functions callable without having to type parentheses.
462 423
463 424 This toggles the autocall command line option on and off."""
464 425
465 426 rc = self.shell.rc
466 427 rc.autocall = not rc.autocall
467 428 print "Automatic calling is:",['OFF','ON'][rc.autocall]
468 429
469 430 def magic_autoindent(self, parameter_s = ''):
470 431 """Toggle autoindent on/off (if available)."""
471 432
472 433 self.shell.set_autoindent()
473 434 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
474 435
475 436 def magic_system_verbose(self, parameter_s = ''):
476 437 """Toggle verbose printing of system calls on/off."""
477 438
478 439 self.shell.rc_set_toggle('system_verbose')
479 440 print "System verbose printing is:",\
480 441 ['OFF','ON'][self.shell.rc.system_verbose]
481 442
482 443 def magic_history(self, parameter_s = ''):
483 444 """Print input history (_i<n> variables), with most recent last.
484 445
485 446 %history [-n] -> print at most 40 inputs (some may be multi-line)\\
486 447 %history [-n] n -> print at most n inputs\\
487 448 %history [-n] n1 n2 -> print inputs between n1 and n2 (n2 not included)\\
488 449
489 450 Each input's number <n> is shown, and is accessible as the
490 451 automatically generated variable _i<n>. Multi-line statements are
491 452 printed starting at a new line for easy copy/paste.
492 453
493 454 If option -n is used, input numbers are not printed. This is useful if
494 455 you want to get a printout of many lines which can be directly pasted
495 456 into a text editor.
496 457
497 458 This feature is only available if numbered prompts are in use."""
498 459
499 if not self.do_full_cache:
460 if not self.shell.outputcache.do_full_cache:
500 461 print 'This feature is only available if numbered prompts are in use.'
501 462 return
502 463 opts,args = self.parse_options(parameter_s,'n',mode='list')
503 464
504 465 default_length = 40
505 466 if len(args) == 0:
506 final = self.outputcache.prompt_count
467 final = self.shell.outputcache.prompt_count
507 468 init = max(1,final-default_length)
508 469 elif len(args) == 1:
509 final = self.outputcache.prompt_count
470 final = self.shell.outputcache.prompt_count
510 471 init = max(1,final-int(args[0]))
511 472 elif len(args) == 2:
512 473 init,final = map(int,args)
513 474 else:
514 475 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
515 476 print self.magic_hist.__doc__
516 477 return
517 478 width = len(str(final))
518 479 line_sep = ['','\n']
519 480 input_hist = self.shell.input_hist
520 481 print_nums = not opts.has_key('n')
521 482 for in_num in range(init,final):
522 483 inline = input_hist[in_num]
523 484 multiline = inline.count('\n') > 1
524 485 if print_nums:
525 486 print str(in_num).ljust(width)+':'+ line_sep[multiline],
526 487 if inline.startswith('#'+self.shell.ESC_MAGIC) or \
527 488 inline.startswith('#!'):
528 489 print inline[1:],
529 490 else:
530 491 print inline,
531 492
532 493 def magic_hist(self, parameter_s=''):
533 494 """Alternate name for %history."""
534 495 return self.magic_history(parameter_s)
535 496
536 497 def magic_p(self, parameter_s=''):
537 498 """Just a short alias for Python's 'print'."""
538 499 exec 'print ' + parameter_s in self.shell.user_ns
539 500
540 501 def magic_r(self, parameter_s=''):
541 502 """Repeat previous input.
542 503
543 504 If given an argument, repeats the previous command which starts with
544 505 the same string, otherwise it just repeats the previous input.
545 506
546 507 Shell escaped commands (with ! as first character) are not recognized
547 508 by this system, only pure python code and magic commands.
548 509 """
549 510
550 511 start = parameter_s.strip()
551 512 esc_magic = self.shell.ESC_MAGIC
552 513 # Identify magic commands even if automagic is on (which means
553 514 # the in-memory version is different from that typed by the user).
554 515 if self.shell.rc.automagic:
555 516 start_magic = esc_magic+start
556 517 else:
557 518 start_magic = start
558 519 # Look through the input history in reverse
559 520 for n in range(len(self.shell.input_hist)-2,0,-1):
560 521 input = self.shell.input_hist[n]
561 522 # skip plain 'r' lines so we don't recurse to infinity
562 523 if input != 'ipmagic("r")\n' and \
563 524 (input.startswith(start) or input.startswith(start_magic)):
564 525 #print 'match',`input` # dbg
565 if input.startswith(esc_magic):
566 input = magic2python(input)
567 #print 'modified',`input` # dbg
568 526 print 'Executing:',input,
569 exec input in self.shell.user_ns
527 self.shell.runlines(input)
570 528 return
571 529 print 'No previous input matching `%s` found.' % start
572 530
573 531 def magic_page(self, parameter_s=''):
574 532 """Pretty print the object and display it through a pager.
575 533
576 534 If no parameter is given, use _ (last output)."""
577 535 # After a function contributed by Olivier Aubert, slightly modified.
578 536
579 537 oname = parameter_s and parameter_s or '_'
580 538 info = self._ofind(oname)
581 539 if info['found']:
582 540 page(pformat(info['obj']))
583 541 else:
584 542 print 'Object `%s` not found' % oname
585 543
586 544 def magic_profile(self, parameter_s=''):
587 545 """Print your currently active IPyhton profile."""
588 546 if self.shell.rc.profile:
589 547 printpl('Current IPython profile: $self.shell.rc.profile.')
590 548 else:
591 549 print 'No profile active.'
592 550
593 551 def _inspect(self,meth,oname,**kw):
594 552 """Generic interface to the inspector system.
595 553
596 554 This function is meant to be called by pdef, pdoc & friends."""
597 555
598 556 oname = oname.strip()
599 557 info = Struct(self._ofind(oname))
600 558 if info.found:
601 559 pmethod = getattr(self.shell.inspector,meth)
602 560 formatter = info.ismagic and self.format_screen or None
603 561 if meth == 'pdoc':
604 562 pmethod(info.obj,oname,formatter)
605 563 elif meth == 'pinfo':
606 564 pmethod(info.obj,oname,formatter,info,**kw)
607 565 else:
608 566 pmethod(info.obj,oname)
609 567 else:
610 568 print 'Object `%s` not found.' % oname
611 569 return 'not found' # so callers can take other action
612 570
613 571 def magic_pdef(self, parameter_s=''):
614 572 """Print the definition header for any callable object.
615 573
616 574 If the object is a class, print the constructor information."""
617 575 self._inspect('pdef',parameter_s)
618 576
619 577 def magic_pdoc(self, parameter_s=''):
620 578 """Print the docstring for an object.
621 579
622 580 If the given object is a class, it will print both the class and the
623 581 constructor docstrings."""
624 582 self._inspect('pdoc',parameter_s)
625 583
626 584 def magic_psource(self, parameter_s=''):
627 585 """Print (or run through pager) the source code for an object."""
628 586 self._inspect('psource',parameter_s)
629 587
630 588 def magic_pfile(self, parameter_s=''):
631 589 """Print (or run through pager) the file where an object is defined.
632 590
633 591 The file opens at the line where the object definition begins. IPython
634 592 will honor the environment variable PAGER if set, and otherwise will
635 593 do its best to print the file in a convenient form.
636 594
637 595 If the given argument is not an object currently defined, IPython will
638 596 try to interpret it as a filename (automatically adding a .py extension
639 597 if needed). You can thus use %pfile as a syntax highlighting code
640 598 viewer."""
641 599
642 600 # first interpret argument as an object name
643 601 out = self._inspect('pfile',parameter_s)
644 602 # if not, try the input as a filename
645 603 if out == 'not found':
646 604 try:
647 605 filename = get_py_filename(parameter_s)
648 606 except IOError,msg:
649 607 print msg
650 608 return
651 609 page(self.shell.inspector.format(file(filename).read()))
652 610
653 611 def magic_pinfo(self, parameter_s=''):
654 612 """Provide detailed information about an object.
655 613
656 614 '%pinfo object' is just a synonym for object? or ?object."""
657 615
658 616 #print 'pinfo par: <%s>' % parameter_s # dbg
659 617
660 618 # detail_level: 0 -> obj? , 1 -> obj??
661 619 detail_level = 0
662 620 # We need to detect if we got called as 'pinfo pinfo foo', which can
663 621 # happen if the user types 'pinfo foo?' at the cmd line.
664 622 pinfo,qmark1,oname,qmark2 = \
665 623 re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups()
666 624 if pinfo or qmark1 or qmark2:
667 625 detail_level = 1
668 626 if "*" in oname:
669 627 self.magic_psearch(oname)
670 628 else:
671 629 self._inspect('pinfo',oname,detail_level=detail_level)
672 630
673 631 def magic_psearch(self, parameter_s=''):
674 632 """Search for object in namespaces by wildcard.
675 633
676 634 %psearch [options] PATTERN [OBJECT TYPE]
677 635
678 636 Note: ? can be used as a synonym for %psearch, at the beginning or at
679 637 the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the
680 638 rest of the command line must be unchanged (options come first), so
681 639 for example the following forms are equivalent
682 640
683 641 %psearch -i a* function
684 642 -i a* function?
685 643 ?-i a* function
686 644
687 645 Arguments:
688 646
689 647 PATTERN
690 648
691 649 where PATTERN is a string containing * as a wildcard similar to its
692 650 use in a shell. The pattern is matched in all namespaces on the
693 651 search path. By default objects starting with a single _ are not
694 652 matched, many IPython generated objects have a single
695 653 underscore. The default is case insensitive matching. Matching is
696 654 also done on the attributes of objects and not only on the objects
697 655 in a module.
698 656
699 657 [OBJECT TYPE]
700 658
701 659 Is the name of a python type from the types module. The name is
702 660 given in lowercase without the ending type, ex. StringType is
703 661 written string. By adding a type here only objects matching the
704 662 given type are matched. Using all here makes the pattern match all
705 663 types (this is the default).
706 664
707 665 Options:
708 666
709 667 -a: makes the pattern match even objects whose names start with a
710 668 single underscore. These names are normally ommitted from the
711 669 search.
712 670
713 671 -i/-c: make the pattern case insensitive/sensitive. If neither of
714 672 these options is given, the default is read from your ipythonrc
715 673 file. The option name which sets this value is
716 674 'wildcards_case_sensitive'. If this option is not specified in your
717 675 ipythonrc file, IPython's internal default is to do a case sensitive
718 676 search.
719 677
720 678 -e/-s NAMESPACE: exclude/search a given namespace. The pattern you
721 679 specifiy can be searched in any of the following namespaces:
722 680 'builtin', 'user', 'user_global','internal', 'alias', where
723 681 'builtin' and 'user' are the search defaults. Note that you should
724 682 not use quotes when specifying namespaces.
725 683
726 684 'Builtin' contains the python module builtin, 'user' contains all
727 685 user data, 'alias' only contain the shell aliases and no python
728 686 objects, 'internal' contains objects used by IPython. The
729 687 'user_global' namespace is only used by embedded IPython instances,
730 688 and it contains module-level globals. You can add namespaces to the
731 689 search with -s or exclude them with -e (these options can be given
732 690 more than once).
733 691
734 692 Examples:
735 693
736 694 %psearch a* -> objects beginning with an a
737 695 %psearch -e builtin a* -> objects NOT in the builtin space starting in a
738 696 %psearch a* function -> all functions beginning with an a
739 697 %psearch re.e* -> objects beginning with an e in module re
740 698 %psearch r*.e* -> objects that start with e in modules starting in r
741 699 %psearch r*.* string -> all strings in modules beginning with r
742 700
743 701 Case sensitve search:
744 702
745 703 %psearch -c a* list all object beginning with lower case a
746 704
747 705 Show objects beginning with a single _:
748 706
749 707 %psearch -a _* list objects beginning with a single underscore"""
750 708
751 709 # default namespaces to be searched
752 710 def_search = ['user','builtin']
753 711
754 712 # Process options/args
755 713 opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True)
756 714 opt = opts.get
757 715 shell = self.shell
758 716 psearch = shell.inspector.psearch
759 717
760 718 # select case options
761 719 if opts.has_key('i'):
762 720 ignore_case = True
763 721 elif opts.has_key('c'):
764 722 ignore_case = False
765 723 else:
766 724 ignore_case = not shell.rc.wildcards_case_sensitive
767 725
768 726 # Build list of namespaces to search from user options
769 727 def_search.extend(opt('s',[]))
770 728 ns_exclude = ns_exclude=opt('e',[])
771 729 ns_search = [nm for nm in def_search if nm not in ns_exclude]
772 730
773 731 # Call the actual search
774 732 try:
775 733 psearch(args,shell.ns_table,ns_search,
776 734 show_all=opt('a'),ignore_case=ignore_case)
777 735 except:
778 736 shell.showtraceback()
779 737
780 738 def magic_who_ls(self, parameter_s=''):
781 739 """Return a sorted list of all interactive variables.
782 740
783 741 If arguments are given, only variables of types matching these
784 742 arguments are returned."""
785 743
786 744 user_ns = self.shell.user_ns
787 745 out = []
788 746 typelist = parameter_s.split()
789 747 for i in self.shell.user_ns.keys():
790 748 if not (i.startswith('_') or i.startswith('_i')) \
791 and not (self.internal_ns.has_key(i) or
792 self.user_config_ns.has_key(i)):
749 and not (self.shell.internal_ns.has_key(i) or
750 self.shell.user_config_ns.has_key(i)):
793 751 if typelist:
794 752 if type(user_ns[i]).__name__ in typelist:
795 753 out.append(i)
796 754 else:
797 755 out.append(i)
798 756 out.sort()
799 757 return out
800 758
801 759 def magic_who(self, parameter_s=''):
802 760 """Print all interactive variables, with some minimal formatting.
803 761
804 762 If any arguments are given, only variables whose type matches one of
805 763 these are printed. For example:
806 764
807 765 %who function str
808 766
809 767 will only list functions and strings, excluding all other types of
810 768 variables. To find the proper type names, simply use type(var) at a
811 769 command line to see how python prints type names. For example:
812 770
813 771 In [1]: type('hello')\\
814 772 Out[1]: <type 'str'>
815 773
816 774 indicates that the type name for strings is 'str'.
817 775
818 776 %who always excludes executed names loaded through your configuration
819 777 file and things which are internal to IPython.
820 778
821 779 This is deliberate, as typically you may load many modules and the
822 780 purpose of %who is to show you only what you've manually defined."""
823 781
824 782 varlist = self.magic_who_ls(parameter_s)
825 783 if not varlist:
826 784 print 'Interactive namespace is empty.'
827 785 return
828 786
829 787 # if we have variables, move on...
830 788
831 789 # stupid flushing problem: when prompts have no separators, stdout is
832 790 # getting lost. I'm starting to think this is a python bug. I'm having
833 791 # to force a flush with a print because even a sys.stdout.flush
834 792 # doesn't seem to do anything!
835 793
836 794 count = 0
837 795 for i in varlist:
838 796 print i+'\t',
839 797 count += 1
840 798 if count > 8:
841 799 count = 0
842 800 print
843 801 sys.stdout.flush() # FIXME. Why the hell isn't this flushing???
844 802
845 803 print # well, this does force a flush at the expense of an extra \n
846 804
847 805 def magic_whos(self, parameter_s=''):
848 806 """Like %who, but gives some extra information about each variable.
849 807
850 808 The same type filtering of %who can be applied here.
851 809
852 810 For all variables, the type is printed. Additionally it prints:
853 811
854 812 - For {},[],(): their length.
855 813
856 814 - For Numeric arrays, a summary with shape, number of elements,
857 815 typecode and size in memory.
858 816
859 817 - Everything else: a string representation, snipping their middle if
860 818 too long."""
861 819
862 820 varnames = self.magic_who_ls(parameter_s)
863 821 if not varnames:
864 822 print 'Interactive namespace is empty.'
865 823 return
866 824
867 825 # if we have variables, move on...
868 826
869 827 # for these types, show len() instead of data:
870 828 seq_types = [types.DictType,types.ListType,types.TupleType]
871 829
872 830 # for Numeric arrays, display summary info
873 831 try:
874 832 import Numeric
875 833 except ImportError:
876 834 array_type = None
877 835 else:
878 836 array_type = Numeric.ArrayType.__name__
879 837
880 838 # Find all variable names and types so we can figure out column sizes
881 839 get_vars = lambda i: self.shell.user_ns[i]
882 840 type_name = lambda v: type(v).__name__
883 841 varlist = map(get_vars,varnames)
884 842 typelist = map(type_name,varlist)
885 843 # column labels and # of spaces as separator
886 844 varlabel = 'Variable'
887 845 typelabel = 'Type'
888 846 datalabel = 'Data/Info'
889 847 colsep = 3
890 848 # variable format strings
891 849 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
892 850 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
893 851 aformat = "%s: %s elems, type `%s`, %s bytes"
894 852 # find the size of the columns to format the output nicely
895 853 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
896 854 typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep
897 855 # table header
898 856 print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \
899 857 ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1)
900 858 # and the table itself
901 859 kb = 1024
902 860 Mb = 1048576 # kb**2
903 861 for vname,var,vtype in zip(varnames,varlist,typelist):
904 862 print itpl(vformat),
905 863 if vtype in seq_types:
906 864 print len(var)
907 865 elif vtype==array_type:
908 866 vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1]
909 867 vsize = Numeric.size(var)
910 868 vbytes = vsize*var.itemsize()
911 869 if vbytes < 100000:
912 870 print aformat % (vshape,vsize,var.typecode(),vbytes)
913 871 else:
914 872 print aformat % (vshape,vsize,var.typecode(),vbytes),
915 873 if vbytes < Mb:
916 874 print '(%s kb)' % (vbytes/kb,)
917 875 else:
918 876 print '(%s Mb)' % (vbytes/Mb,)
919 877 else:
920 878 vstr = str(var)
921 879 if len(vstr) < 50:
922 880 print vstr
923 881 else:
924 882 printpl(vfmt_short)
925 883
926 884 def magic_reset(self, parameter_s=''):
927 885 """Resets the namespace by removing all names defined by the user.
928 886
929 887 Input/Output history are left around in case you need them."""
930 888
931 889 ans = raw_input(
932 890 "Once deleted, variables cannot be recovered. Proceed (y/n)? ")
933 891 if not ans.lower() == 'y':
934 892 print 'Nothing done.'
935 893 return
936 894 user_ns = self.shell.user_ns
937 895 for i in self.magic_who_ls():
938 896 del(user_ns[i])
939 897
940 898 def magic_config(self,parameter_s=''):
941 899 """Show IPython's internal configuration."""
942 900
943 901 page('Current configuration structure:\n'+
944 902 pformat(self.shell.rc.dict()))
945 903
946 904 def magic_logstart(self,parameter_s=''):
947 905 """Start logging anywhere in a session.
948 906
949 %logstart [log_name [log_mode]]
907 %logstart [-o|-t] [log_name [log_mode]]
950 908
951 If no name is given, it defaults to a file named 'ipython.log' in your
909 If no name is given, it defaults to a file named 'ipython_log.py' in your
952 910 current directory, in 'rotate' mode (see below).
953 911
954 912 '%logstart name' saves to file 'name' in 'backup' mode. It saves your
955 913 history up to that point and then continues logging.
956 914
957 915 %logstart takes a second optional parameter: logging mode. This can be one
958 916 of (note that the modes are given unquoted):\\
959 over: overwrite existing log.\\
960 backup: rename (if exists) to name~ and start name.\\
961 917 append: well, that says it.\\
918 backup: rename (if exists) to name~ and start name.\\
919 global: single logfile in your home dir, appended to.\\
920 over : overwrite existing log.\\
962 921 rotate: create rotating logs name.1~, name.2~, etc.
963 """
964 922
965 #FIXME. This function should all be moved to the Logger class.
923 Options:
924
925 -o: log also IPython's output. In this mode, all commands which
926 generate an Out[NN] prompt are recorded to the logfile, right after
927 their corresponding input line. The output lines are always
928 prepended with a #[Out]# marker, so that the log remains valid
929 Python code.
930
931 -t: put timestamps before each input line logged (these are put in
932 comments)."""
966 933
967 valid_modes = qw('over backup append rotate')
968 if self.LOG:
969 print 'Logging is already in place. Logfile:',self.LOG
970 return
934 opts,par = self.parse_options(parameter_s,'ot')
935 log_output = 'o' in opts
936 timestamp = 't' in opts
971 937
972 par = parameter_s.strip()
973 if not par:
974 logname = self.LOGDEF
975 logmode = 'rotate' # use rotate for the auto-generated logs
976 else:
938 rc = self.shell.rc
939 logger = self.shell.logger
940
941 # if no args are given, the defaults set in the logger constructor by
942 # ipytohn remain valid
943 if par:
977 944 try:
978 logname,logmode = par.split()
945 logfname,logmode = par.split()
979 946 except:
980 try:
981 logname = par
982 logmode = 'backup'
983 except:
984 warn('Usage: %log [log_name [log_mode]]')
985 return
986 if not logmode in valid_modes:
987 warn('Logging NOT activated.\n'
988 'Usage: %log [log_name [log_mode]]\n'
989 'Valid modes: '+str(valid_modes))
990 return
991
992 # If we made it this far, I think we're ok:
993 print 'Activating auto-logging.'
994 print 'Current session state plus future input saved to:',logname
995 print 'Logging mode: ',logmode
996 # put logname into rc struct as if it had been called on the command line,
997 # so it ends up saved in the log header
998 # Save it in case we need to restore it...
999 old_logfile = self.shell.rc.opts.get('logfile','')
1000 logname = os.path.expanduser(logname)
1001 self.shell.rc.opts.logfile = logname
1002 self.LOGMODE = logmode # FIXME: this should be set through a function.
947 logfname = par
948 logmode = 'backup'
949 else:
950 logfname = logger.logfname
951 logmode = logger.logmode
952 # put logfname into rc struct as if it had been called on the command
953 # line, so it ends up saved in the log header Save it in case we need
954 # to restore it...
955 old_logfile = rc.opts.get('logfile','')
956 if logfname:
957 logfname = os.path.expanduser(logfname)
958 rc.opts.logfile = logfname
959 loghead = self.shell.loghead_tpl % (rc.opts,rc.args)
1003 960 try:
1004 header = str(self.LOGHEAD)
1005 self.create_log(header,logname)
1006 self.logstart(header,logname)
961 started = logger.logstart(logfname,loghead,logmode,
962 log_output,timestamp)
1007 963 except:
1008 self.LOG = '' # we are NOT logging, something went wrong
1009 self.shell.rc.opts.logfile = old_logfile
1010 warn("Couldn't start log: "+str(sys.exc_info()[1]))
1011 else: # log input history up to this point
1012 self.logfile.write(self.shell.user_ns['_ih'][1:])
1013 self.logfile.flush()
1014
964 rc.opts.logfile = old_logfile
965 warn("Couldn't start log: %s" % sys.exc_info()[1])
966 else:
967 # log input history up to this point, optionally interleaving
968 # output if requested
969
970 if timestamp:
971 # disable timestamping for the previous history, since we've
972 # lost those already (no time machine here).
973 logger.timestamp = False
974 if log_output:
975 log_write = logger.log_write
976 input_hist = self.shell.input_hist
977 output_hist = self.shell.output_hist
978 for n in range(1,len(input_hist)-1):
979 log_write(input_hist[n].rstrip())
980 if n in output_hist:
981 log_write(repr(output_hist[n]),'output')
982 else:
983 logger.log_write(self.shell.input_hist[1:])
984 if timestamp:
985 # re-enable timestamping
986 logger.timestamp = True
987
988 print ('Activating auto-logging. '
989 'Current session state plus future input saved.')
990 logger.logstate()
991
1015 992 def magic_logoff(self,parameter_s=''):
1016 993 """Temporarily stop logging.
1017 994
1018 995 You must have previously started logging."""
1019 self.switch_log(0)
996 self.shell.logger.switch_log(0)
1020 997
1021 998 def magic_logon(self,parameter_s=''):
1022 999 """Restart logging.
1023 1000
1024 1001 This function is for restarting logging which you've temporarily
1025 1002 stopped with %logoff. For starting logging for the first time, you
1026 1003 must use the %logstart function, which allows you to specify an
1027 1004 optional log filename."""
1028 1005
1029 self.switch_log(1)
1006 self.shell.logger.switch_log(1)
1030 1007
1031 1008 def magic_logstate(self,parameter_s=''):
1032 1009 """Print the status of the logging system."""
1033 1010
1034 self.logstate()
1011 self.shell.logger.logstate()
1035 1012
1036 1013 def magic_pdb(self, parameter_s=''):
1037 1014 """Control the calling of the pdb interactive debugger.
1038 1015
1039 1016 Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without
1040 1017 argument it works as a toggle.
1041 1018
1042 1019 When an exception is triggered, IPython can optionally call the
1043 1020 interactive pdb debugger after the traceback printout. %pdb toggles
1044 1021 this feature on and off."""
1045 1022
1046 1023 par = parameter_s.strip().lower()
1047 1024
1048 1025 if par:
1049 1026 try:
1050 pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1027 new_pdb = {'off':0,'0':0,'on':1,'1':1}[par]
1051 1028 except KeyError:
1052 print 'Incorrect argument. Use on/1, off/0, or nothing for a toggle.'
1029 print ('Incorrect argument. Use on/1, off/0, '
1030 'or nothing for a toggle.')
1053 1031 return
1054 else:
1055 self.shell.InteractiveTB.call_pdb = pdb
1056 1032 else:
1033 # toggle
1057 1034 new_pdb = not self.shell.InteractiveTB.call_pdb
1058 self.shell.InteractiveTB.call_pdb = new_pdb
1059 if self.shell.isthreaded:
1060 try:
1061 self.sys_excepthook.call_pdb = new_pdb
1062 except:
1063 warn('Failed to activate pdb for threaded exception handler')
1064
1065 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1066
1067 1035
1036 # set on the shell
1037 self.shell.call_pdb = new_pdb
1038 print 'Automatic pdb calling has been turned',on_off(new_pdb)
1068 1039
1069 1040 def magic_prun(self, parameter_s ='',user_mode=1,
1070 1041 opts=None,arg_lst=None,prog_ns=None):
1071 1042
1072 1043 """Run a statement through the python code profiler.
1073 1044
1074 1045 Usage:\\
1075 1046 %prun [options] statement
1076 1047
1077 1048 The given statement (which doesn't require quote marks) is run via the
1078 1049 python profiler in a manner similar to the profile.run() function.
1079 1050 Namespaces are internally managed to work correctly; profile.run
1080 1051 cannot be used in IPython because it makes certain assumptions about
1081 1052 namespaces which do not hold under IPython.
1082 1053
1083 1054 Options:
1084 1055
1085 1056 -l <limit>: you can place restrictions on what or how much of the
1086 1057 profile gets printed. The limit value can be:
1087 1058
1088 1059 * A string: only information for function names containing this string
1089 1060 is printed.
1090 1061
1091 1062 * An integer: only these many lines are printed.
1092 1063
1093 1064 * A float (between 0 and 1): this fraction of the report is printed
1094 1065 (for example, use a limit of 0.4 to see the topmost 40% only).
1095 1066
1096 1067 You can combine several limits with repeated use of the option. For
1097 1068 example, '-l __init__ -l 5' will print only the topmost 5 lines of
1098 1069 information about class constructors.
1099 1070
1100 1071 -r: return the pstats.Stats object generated by the profiling. This
1101 1072 object has all the information about the profile in it, and you can
1102 1073 later use it for further analysis or in other functions.
1103 1074
1104 1075 Since magic functions have a particular form of calling which prevents
1105 1076 you from writing something like:\\
1106 1077 In [1]: p = %prun -r print 4 # invalid!\\
1107 1078 you must instead use IPython's automatic variables to assign this:\\
1108 1079 In [1]: %prun -r print 4 \\
1109 1080 Out[1]: <pstats.Stats instance at 0x8222cec>\\
1110 1081 In [2]: stats = _
1111 1082
1112 1083 If you really need to assign this value via an explicit function call,
1113 1084 you can always tap directly into the true name of the magic function
1114 1085 by using the ipmagic function (which IPython automatically adds to the
1115 1086 builtins):\\
1116 1087 In [3]: stats = ipmagic('prun','-r print 4')
1117 1088
1118 1089 You can type ipmagic? for more details on ipmagic.
1119 1090
1120 1091 -s <key>: sort profile by given key. You can provide more than one key
1121 1092 by using the option several times: '-s key1 -s key2 -s key3...'. The
1122 1093 default sorting key is 'time'.
1123 1094
1124 1095 The following is copied verbatim from the profile documentation
1125 1096 referenced below:
1126 1097
1127 1098 When more than one key is provided, additional keys are used as
1128 1099 secondary criteria when the there is equality in all keys selected
1129 1100 before them.
1130 1101
1131 1102 Abbreviations can be used for any key names, as long as the
1132 1103 abbreviation is unambiguous. The following are the keys currently
1133 1104 defined:
1134 1105
1135 1106 Valid Arg Meaning\\
1136 1107 "calls" call count\\
1137 1108 "cumulative" cumulative time\\
1138 1109 "file" file name\\
1139 1110 "module" file name\\
1140 1111 "pcalls" primitive call count\\
1141 1112 "line" line number\\
1142 1113 "name" function name\\
1143 1114 "nfl" name/file/line\\
1144 1115 "stdname" standard name\\
1145 1116 "time" internal time
1146 1117
1147 1118 Note that all sorts on statistics are in descending order (placing
1148 1119 most time consuming items first), where as name, file, and line number
1149 1120 searches are in ascending order (i.e., alphabetical). The subtle
1150 1121 distinction between "nfl" and "stdname" is that the standard name is a
1151 1122 sort of the name as printed, which means that the embedded line
1152 1123 numbers get compared in an odd way. For example, lines 3, 20, and 40
1153 1124 would (if the file names were the same) appear in the string order
1154 1125 "20" "3" and "40". In contrast, "nfl" does a numeric compare of the
1155 1126 line numbers. In fact, sort_stats("nfl") is the same as
1156 1127 sort_stats("name", "file", "line").
1157 1128
1158 1129 -T <filename>: save profile results as shown on screen to a text
1159 1130 file. The profile is still shown on screen.
1160 1131
1161 1132 -D <filename>: save (via dump_stats) profile statistics to given
1162 1133 filename. This data is in a format understod by the pstats module, and
1163 1134 is generated by a call to the dump_stats() method of profile
1164 1135 objects. The profile is still shown on screen.
1165 1136
1166 1137 If you want to run complete programs under the profiler's control, use
1167 1138 '%run -p [prof_opts] filename.py [args to program]' where prof_opts
1168 1139 contains profiler specific options as described here.
1169 1140
1170 1141 You can read the complete documentation for the profile module with:\\
1171 1142 In [1]: import profile; profile.help() """
1172 1143
1173 1144 opts_def = Struct(D=[''],l=[],s=['time'],T=[''])
1174 1145 # protect user quote marks
1175 1146 parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")
1176 1147
1177 1148 if user_mode: # regular user call
1178 1149 opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
1179 1150 list_all=1)
1180 1151 namespace = self.shell.user_ns
1181 1152 else: # called to run a program by %run -p
1182 1153 try:
1183 1154 filename = get_py_filename(arg_lst[0])
1184 1155 except IOError,msg:
1185 1156 error(msg)
1186 1157 return
1187 1158
1188 1159 arg_str = 'execfile(filename,prog_ns)'
1189 1160 namespace = locals()
1190 1161
1191 1162 opts.merge(opts_def)
1192 1163
1193 1164 prof = profile.Profile()
1194 1165 try:
1195 1166 prof = prof.runctx(arg_str,namespace,namespace)
1196 1167 sys_exit = ''
1197 1168 except SystemExit:
1198 1169 sys_exit = """*** SystemExit exception caught in code being profiled."""
1199 1170
1200 1171 stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s)
1201 1172
1202 1173 lims = opts.l
1203 1174 if lims:
1204 1175 lims = [] # rebuild lims with ints/floats/strings
1205 1176 for lim in opts.l:
1206 1177 try:
1207 1178 lims.append(int(lim))
1208 1179 except ValueError:
1209 1180 try:
1210 1181 lims.append(float(lim))
1211 1182 except ValueError:
1212 1183 lims.append(lim)
1213 1184
1214 1185 # trap output
1215 1186 sys_stdout = sys.stdout
1216 1187 stdout_trap = StringIO()
1217 1188 try:
1218 1189 sys.stdout = stdout_trap
1219 1190 stats.print_stats(*lims)
1220 1191 finally:
1221 1192 sys.stdout = sys_stdout
1222 1193 output = stdout_trap.getvalue()
1223 1194 output = output.rstrip()
1224 1195
1225 1196 page(output,screen_lines=self.shell.rc.screen_length)
1226 1197 print sys_exit,
1227 1198
1228 1199 dump_file = opts.D[0]
1229 1200 text_file = opts.T[0]
1230 1201 if dump_file:
1231 1202 prof.dump_stats(dump_file)
1232 1203 print '\n*** Profile stats marshalled to file',\
1233 1204 `dump_file`+'.',sys_exit
1234 1205 if text_file:
1235 1206 file(text_file,'w').write(output)
1236 1207 print '\n*** Profile printout saved to text file',\
1237 1208 `text_file`+'.',sys_exit
1238 1209
1239 1210 if opts.has_key('r'):
1240 1211 return stats
1241 1212 else:
1242 1213 return None
1243 1214
1244 1215 def magic_run(self, parameter_s ='',runner=None):
1245 1216 """Run the named file inside IPython as a program.
1246 1217
1247 1218 Usage:\\
1248 1219 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
1249 1220
1250 1221 Parameters after the filename are passed as command-line arguments to
1251 1222 the program (put in sys.argv). Then, control returns to IPython's
1252 1223 prompt.
1253 1224
1254 1225 This is similar to running at a system prompt:\\
1255 1226 $ python file args\\
1256 1227 but with the advantage of giving you IPython's tracebacks, and of
1257 1228 loading all variables into your interactive namespace for further use
1258 1229 (unless -p is used, see below).
1259 1230
1260 1231 The file is executed in a namespace initially consisting only of
1261 1232 __name__=='__main__' and sys.argv constructed as indicated. It thus
1262 1233 sees its environment as if it were being run as a stand-alone
1263 1234 program. But after execution, the IPython interactive namespace gets
1264 1235 updated with all variables defined in the program (except for __name__
1265 1236 and sys.argv). This allows for very convenient loading of code for
1266 1237 interactive work, while giving each program a 'clean sheet' to run in.
1267 1238
1268 1239 Options:
1269 1240
1270 1241 -n: __name__ is NOT set to '__main__', but to the running file's name
1271 1242 without extension (as python does under import). This allows running
1272 1243 scripts and reloading the definitions in them without calling code
1273 1244 protected by an ' if __name__ == "__main__" ' clause.
1274 1245
1275 1246 -i: run the file in IPython's namespace instead of an empty one. This
1276 1247 is useful if you are experimenting with code written in a text editor
1277 1248 which depends on variables defined interactively.
1278 1249
1279 1250 -e: ignore sys.exit() calls or SystemExit exceptions in the script
1280 1251 being run. This is particularly useful if IPython is being used to
1281 1252 run unittests, which always exit with a sys.exit() call. In such
1282 1253 cases you are interested in the output of the test results, not in
1283 1254 seeing a traceback of the unittest module.
1284 1255
1285 1256 -t: print timing information at the end of the run. IPython will give
1286 1257 you an estimated CPU time consumption for your script, which under
1287 1258 Unix uses the resource module to avoid the wraparound problems of
1288 1259 time.clock(). Under Unix, an estimate of time spent on system tasks
1289 1260 is also given (for Windows platforms this is reported as 0.0).
1290 1261
1291 1262 If -t is given, an additional -N<N> option can be given, where <N>
1292 1263 must be an integer indicating how many times you want the script to
1293 1264 run. The final timing report will include total and per run results.
1294 1265
1295 1266 For example (testing the script uniq_stable.py):
1296 1267
1297 1268 In [1]: run -t uniq_stable
1298 1269
1299 1270 IPython CPU timings (estimated):\\
1300 1271 User : 0.19597 s.\\
1301 1272 System: 0.0 s.\\
1302 1273
1303 1274 In [2]: run -t -N5 uniq_stable
1304 1275
1305 1276 IPython CPU timings (estimated):\\
1306 1277 Total runs performed: 5\\
1307 1278 Times : Total Per run\\
1308 1279 User : 0.910862 s, 0.1821724 s.\\
1309 1280 System: 0.0 s, 0.0 s.
1310 1281
1311 1282 -d: run your program under the control of pdb, the Python debugger.
1312 1283 This allows you to execute your program step by step, watch variables,
1313 1284 etc. Internally, what IPython does is similar to calling:
1314 1285
1315 1286 pdb.run('execfile("YOURFILENAME")')
1316 1287
1317 1288 with a breakpoint set on line 1 of your file. You can change the line
1318 1289 number for this automatic breakpoint to be <N> by using the -bN option
1319 1290 (where N must be an integer). For example:
1320 1291
1321 1292 %run -d -b40 myscript
1322 1293
1323 1294 will set the first breakpoint at line 40 in myscript.py. Note that
1324 1295 the first breakpoint must be set on a line which actually does
1325 1296 something (not a comment or docstring) for it to stop execution.
1326 1297
1327 1298 When the pdb debugger starts, you will see a (Pdb) prompt. You must
1328 1299 first enter 'c' (without qoutes) to start execution up to the first
1329 1300 breakpoint.
1330 1301
1331 1302 Entering 'help' gives information about the use of the debugger. You
1332 1303 can easily see pdb's full documentation with "import pdb;pdb.help()"
1333 1304 at a prompt.
1334 1305
1335 1306 -p: run program under the control of the Python profiler module (which
1336 1307 prints a detailed report of execution times, function calls, etc).
1337 1308
1338 1309 You can pass other options after -p which affect the behavior of the
1339 1310 profiler itself. See the docs for %prun for details.
1340 1311
1341 1312 In this mode, the program's variables do NOT propagate back to the
1342 1313 IPython interactive namespace (because they remain in the namespace
1343 1314 where the profiler executes them).
1344 1315
1345 1316 Internally this triggers a call to %prun, see its documentation for
1346 1317 details on the options available specifically for profiling."""
1347 1318
1348 1319 # get arguments and set sys.argv for program to be run.
1349 1320 opts,arg_lst = self.parse_options(parameter_s,'nidtN:b:pD:l:rs:T:e',
1350 1321 mode='list',list_all=1)
1351 1322
1352 1323 try:
1353 1324 filename = get_py_filename(arg_lst[0])
1354 1325 except IndexError:
1355 1326 warn('you must provide at least a filename.')
1356 1327 print '\n%run:\n',OInspect.getdoc(self.magic_run)
1357 1328 return
1358 1329 except IOError,msg:
1359 1330 error(msg)
1360 1331 return
1361 1332
1362 1333 # Control the response to exit() calls made by the script being run
1363 1334 exit_ignore = opts.has_key('e')
1364 1335
1365 1336 # Make sure that the running script gets a proper sys.argv as if it
1366 1337 # were run from a system shell.
1367 1338 save_argv = sys.argv # save it for later restoring
1368 1339 sys.argv = [filename]+ arg_lst[1:] # put in the proper filename
1369 1340
1370 1341 if opts.has_key('i'):
1371 1342 prog_ns = self.shell.user_ns
1372 1343 __name__save = self.shell.user_ns['__name__']
1373 1344 prog_ns['__name__'] = '__main__'
1374 1345 else:
1375 1346 if opts.has_key('n'):
1376 1347 name = os.path.splitext(os.path.basename(filename))[0]
1377 1348 else:
1378 1349 name = '__main__'
1379 1350 prog_ns = {'__name__':name}
1380 1351
1381 1352 # pickle fix. See iplib for an explanation
1382 1353 sys.modules[prog_ns['__name__']] = FakeModule(prog_ns)
1383 1354
1384 1355 stats = None
1385 1356 try:
1386 1357 if opts.has_key('p'):
1387 1358 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1388 1359 else:
1389 1360 if opts.has_key('d'):
1390 1361 deb = Debugger.Pdb(self.shell.rc.colors)
1391 1362 # reset Breakpoint state, which is moronically kept
1392 1363 # in a class
1393 1364 bdb.Breakpoint.next = 1
1394 1365 bdb.Breakpoint.bplist = {}
1395 1366 bdb.Breakpoint.bpbynumber = [None]
1396 1367 # Set an initial breakpoint to stop execution
1397 1368 maxtries = 10
1398 1369 bp = int(opts.get('b',[1])[0])
1399 1370 checkline = deb.checkline(filename,bp)
1400 1371 if not checkline:
1401 1372 for bp in range(bp+1,bp+maxtries+1):
1402 1373 if deb.checkline(filename,bp):
1403 1374 break
1404 1375 else:
1405 1376 msg = ("\nI failed to find a valid line to set "
1406 1377 "a breakpoint\n"
1407 1378 "after trying up to line: %s.\n"
1408 1379 "Please set a valid breakpoint manually "
1409 1380 "with the -b option." % bp)
1410 1381 error(msg)
1411 1382 return
1412 1383 # if we find a good linenumber, set the breakpoint
1413 1384 deb.do_break('%s:%s' % (filename,bp))
1414 1385 # Start file run
1415 1386 print "NOTE: Enter 'c' at the",
1416 1387 print "ipdb> prompt to start your script."
1417 1388 try:
1418 1389 deb.run('execfile("%s")' % filename,prog_ns)
1419 1390 except:
1420 1391 etype, value, tb = sys.exc_info()
1421 1392 # Skip three frames in the traceback: the %run one,
1422 1393 # one inside bdb.py, and the command-line typed by the
1423 1394 # user (run by exec in pdb itself).
1424 1395 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1425 1396 else:
1426 1397 if runner is None:
1427 1398 runner = self.shell.safe_execfile
1428 1399 if opts.has_key('t'):
1429 1400 try:
1430 1401 nruns = int(opts['N'][0])
1431 1402 if nruns < 1:
1432 1403 error('Number of runs must be >=1')
1433 1404 return
1434 1405 except (KeyError):
1435 1406 nruns = 1
1436 1407 if nruns == 1:
1437 1408 t0 = clock2()
1438 1409 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1439 1410 t1 = clock2()
1440 1411 t_usr = t1[0]-t0[0]
1441 1412 t_sys = t1[1]-t1[1]
1442 1413 print "\nIPython CPU timings (estimated):"
1443 1414 print " User : %10s s." % t_usr
1444 1415 print " System: %10s s." % t_sys
1445 1416 else:
1446 1417 runs = range(nruns)
1447 1418 t0 = clock2()
1448 1419 for nr in runs:
1449 1420 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1450 1421 t1 = clock2()
1451 1422 t_usr = t1[0]-t0[0]
1452 1423 t_sys = t1[1]-t1[1]
1453 1424 print "\nIPython CPU timings (estimated):"
1454 1425 print "Total runs performed:",nruns
1455 1426 print " Times : %10s %10s" % ('Total','Per run')
1456 1427 print " User : %10s s, %10s s." % (t_usr,t_usr/nruns)
1457 1428 print " System: %10s s, %10s s." % (t_sys,t_sys/nruns)
1458 1429
1459 1430 else:
1460 1431 runner(filename,prog_ns,prog_ns,exit_ignore=exit_ignore)
1461 1432 if opts.has_key('i'):
1462 1433 self.shell.user_ns['__name__'] = __name__save
1463 1434 else:
1464 1435 # update IPython interactive namespace
1465 1436 del prog_ns['__name__']
1466 1437 self.shell.user_ns.update(prog_ns)
1467 1438 finally:
1468 1439 sys.argv = save_argv
1469 1440 return stats
1470 1441
1471 1442 def magic_runlog(self, parameter_s =''):
1472 1443 """Run files as logs.
1473 1444
1474 1445 Usage:\\
1475 1446 %runlog file1 file2 ...
1476 1447
1477 1448 Run the named files (treating them as log files) in sequence inside
1478 1449 the interpreter, and return to the prompt. This is much slower than
1479 1450 %run because each line is executed in a try/except block, but it
1480 1451 allows running files with syntax errors in them.
1481 1452
1482 1453 Normally IPython will guess when a file is one of its own logfiles, so
1483 1454 you can typically use %run even for logs. This shorthand allows you to
1484 1455 force any file to be treated as a log file."""
1485 1456
1486 1457 for f in parameter_s.split():
1487 1458 self.shell.safe_execfile(f,self.shell.user_ns,
1488 1459 self.shell.user_ns,islog=1)
1489 1460
1490 1461 def magic_time(self,parameter_s = ''):
1491 1462 """Time execution of a Python statement or expression.
1492 1463
1493 1464 The CPU and wall clock times are printed, and the value of the
1494 1465 expression (if any) is returned. Note that under Win32, system time
1495 1466 is always reported as 0, since it can not be measured.
1496 1467
1497 1468 This function provides very basic timing functionality. In Python
1498 1469 2.3, the timeit module offers more control and sophistication, but for
1499 1470 now IPython supports Python 2.2, so we can not rely on timeit being
1500 1471 present.
1501 1472
1502 1473 Some examples:
1503 1474
1504 1475 In [1]: time 2**128
1505 1476 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1506 1477 Wall time: 0.00
1507 1478 Out[1]: 340282366920938463463374607431768211456L
1508 1479
1509 1480 In [2]: n = 1000000
1510 1481
1511 1482 In [3]: time sum(range(n))
1512 1483 CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s
1513 1484 Wall time: 1.37
1514 1485 Out[3]: 499999500000L
1515 1486
1516 1487 In [4]: time print 'hello world'
1517 1488 hello world
1518 1489 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
1519 1490 Wall time: 0.00
1520 1491 """
1521 1492
1522 1493 # fail immediately if the given expression can't be compiled
1523 1494 try:
1524 1495 mode = 'eval'
1525 1496 code = compile(parameter_s,'<timed eval>',mode)
1526 1497 except SyntaxError:
1527 1498 mode = 'exec'
1528 1499 code = compile(parameter_s,'<timed exec>',mode)
1529 1500 # skew measurement as little as possible
1530 1501 glob = self.shell.user_ns
1531 1502 clk = clock2
1532 1503 wtime = time.time
1533 1504 # time execution
1534 1505 wall_st = wtime()
1535 1506 if mode=='eval':
1536 1507 st = clk()
1537 1508 out = eval(code,glob)
1538 1509 end = clk()
1539 1510 else:
1540 1511 st = clk()
1541 1512 exec code in glob
1542 1513 end = clk()
1543 1514 out = None
1544 1515 wall_end = wtime()
1545 1516 # Compute actual times and report
1546 1517 wall_time = wall_end-wall_st
1547 1518 cpu_user = end[0]-st[0]
1548 1519 cpu_sys = end[1]-st[1]
1549 1520 cpu_tot = cpu_user+cpu_sys
1550 1521 print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \
1551 1522 (cpu_user,cpu_sys,cpu_tot)
1552 1523 print "Wall time: %.2f" % wall_time
1553 1524 return out
1554 1525
1555 1526 def magic_macro(self,parameter_s = ''):
1556 1527 """Define a set of input lines as a macro for future re-execution.
1557 1528
1558 1529 Usage:\\
1559 1530 %macro name n1:n2 n3:n4 ... n5 .. n6 ...
1560 1531
1561 1532 This will define a global variable called `name` which is a string
1562 1533 made of joining the slices and lines you specify (n1,n2,... numbers
1563 1534 above) from your input history into a single string. This variable
1564 1535 acts like an automatic function which re-executes those lines as if
1565 1536 you had typed them. You just type 'name' at the prompt and the code
1566 1537 executes.
1567 1538
1568 1539 Note that the slices use the standard Python slicing notation (5:8
1569 1540 means include lines numbered 5,6,7).
1570 1541
1571 1542 For example, if your history contains (%hist prints it):
1572 1543
1573 1544 44: x=1\\
1574 1545 45: y=3\\
1575 1546 46: z=x+y\\
1576 1547 47: print x\\
1577 1548 48: a=5\\
1578 1549 49: print 'x',x,'y',y\\
1579 1550
1580 1551 you can create a macro with lines 44 through 47 (included) and line 49
1581 1552 called my_macro with:
1582 1553
1583 1554 In [51]: %macro my_macro 44:48 49
1584 1555
1585 1556 Now, typing `my_macro` (without quotes) will re-execute all this code
1586 1557 in one pass.
1587 1558
1588 1559 You don't need to give the line-numbers in order, and any given line
1589 1560 number can appear multiple times. You can assemble macros with any
1590 1561 lines from your input history in any order.
1591 1562
1592 1563 The macro is a simple object which holds its value in an attribute,
1593 1564 but IPython's display system checks for macros and executes them as
1594 1565 code instead of printing them when you type their name.
1595 1566
1596 1567 You can view a macro's contents by explicitly printing it with:
1597 1568
1598 1569 'print macro_name'.
1599 1570
1600 1571 For one-off cases which DON'T contain magic function calls in them you
1601 1572 can obtain similar results by explicitly executing slices from your
1602 1573 input history with:
1603 1574
1604 1575 In [60]: exec In[44:48]+In[49]"""
1605 1576
1606 1577 args = parameter_s.split()
1607 1578 name,ranges = args[0], args[1:]
1608 1579 #print 'rng',ranges # dbg
1609 cmds = self.extract_input_slices(ranges)
1610 macro = Macro(cmds)
1580 lines = self.extract_input_slices(ranges)
1581 macro = Macro(lines)
1611 1582 self.shell.user_ns.update({name:macro})
1612 1583 print 'Macro `%s` created. To execute, type its name (without quotes).' % name
1613 1584 print 'Macro contents:'
1614 print str(macro).rstrip(),
1585 print macro
1615 1586
1616 1587 def magic_save(self,parameter_s = ''):
1617 1588 """Save a set of lines to a given filename.
1618 1589
1619 1590 Usage:\\
1620 1591 %save filename n1:n2 n3:n4 ... n5 .. n6 ...
1621 1592
1622 1593 This function uses the same syntax as %macro for line extraction, but
1623 1594 instead of creating a macro it saves the resulting string to the
1624 1595 filename you specify.
1625 1596
1626 1597 It adds a '.py' extension to the file if you don't do so yourself, and
1627 1598 it asks for confirmation before overwriting existing files."""
1628 1599
1629 1600 args = parameter_s.split()
1630 1601 fname,ranges = args[0], args[1:]
1631 1602 if not fname.endswith('.py'):
1632 1603 fname += '.py'
1633 1604 if os.path.isfile(fname):
1634 1605 ans = raw_input('File `%s` exists. Overwrite (y/[N])? ' % fname)
1635 1606 if ans.lower() not in ['y','yes']:
1636 1607 print 'Operation cancelled.'
1637 1608 return
1638 1609 cmds = ''.join(self.extract_input_slices(ranges))
1639 1610 f = file(fname,'w')
1640 1611 f.write(cmds)
1641 1612 f.close()
1642 1613 print 'The following commands were written to file `%s`:' % fname
1643 1614 print cmds
1644 1615
1645 1616 def magic_ed(self,parameter_s = ''):
1646 1617 """Alias to %edit."""
1647 1618 return self.magic_edit(parameter_s)
1648 1619
1649 1620 def magic_edit(self,parameter_s = '',last_call=['','']):
1650 1621 """Bring up an editor and execute the resulting code.
1651 1622
1652 1623 Usage:
1653 1624 %edit [options] [args]
1654 1625
1655 1626 %edit runs IPython's editor hook. The default version of this hook is
1656 1627 set to call the __IPYTHON__.rc.editor command. This is read from your
1657 1628 environment variable $EDITOR. If this isn't found, it will default to
1658 1629 vi under Linux/Unix and to notepad under Windows. See the end of this
1659 1630 docstring for how to change the editor hook.
1660 1631
1661 1632 You can also set the value of this editor via the command line option
1662 1633 '-editor' or in your ipythonrc file. This is useful if you wish to use
1663 1634 specifically for IPython an editor different from your typical default
1664 1635 (and for Windows users who typically don't set environment variables).
1665 1636
1666 1637 This command allows you to conveniently edit multi-line code right in
1667 1638 your IPython session.
1668 1639
1669 1640 If called without arguments, %edit opens up an empty editor with a
1670 1641 temporary file and will execute the contents of this file when you
1671 1642 close it (don't forget to save it!).
1672 1643
1673 1644 Options:
1674 1645
1675 1646 -p: this will call the editor with the same data as the previous time
1676 1647 it was used, regardless of how long ago (in your current session) it
1677 1648 was.
1678 1649
1679 1650 -x: do not execute the edited code immediately upon exit. This is
1680 1651 mainly useful if you are editing programs which need to be called with
1681 1652 command line arguments, which you can then do using %run.
1682 1653
1683 1654 Arguments:
1684 1655
1685 1656 If arguments are given, the following possibilites exist:
1686 1657
1687 1658 - The arguments are numbers or pairs of colon-separated numbers (like
1688 1659 1 4:8 9). These are interpreted as lines of previous input to be
1689 1660 loaded into the editor. The syntax is the same of the %macro command.
1690 1661
1691 1662 - If the argument doesn't start with a number, it is evaluated as a
1692 1663 variable and its contents loaded into the editor. You can thus edit
1693 1664 any string which contains python code (including the result of
1694 1665 previous edits).
1695 1666
1696 1667 - If the argument is the name of an object (other than a string),
1697 1668 IPython will try to locate the file where it was defined and open the
1698 1669 editor at the point where it is defined. You can use `%edit function`
1699 1670 to load an editor exactly at the point where 'function' is defined,
1700 1671 edit it and have the file be executed automatically.
1701 1672
1702 1673 Note: opening at an exact line is only supported under Unix, and some
1703 1674 editors (like kedit and gedit up to Gnome 2.8) do not understand the
1704 1675 '+NUMBER' parameter necessary for this feature. Good editors like
1705 1676 (X)Emacs, vi, jed, pico and joe all do.
1706 1677
1707 1678 - If the argument is not found as a variable, IPython will look for a
1708 1679 file with that name (adding .py if necessary) and load it into the
1709 1680 editor. It will execute its contents with execfile() when you exit,
1710 1681 loading any code in the file into your interactive namespace.
1711 1682
1712 1683 After executing your code, %edit will return as output the code you
1713 1684 typed in the editor (except when it was an existing file). This way
1714 1685 you can reload the code in further invocations of %edit as a variable,
1715 1686 via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of
1716 1687 the output.
1717 1688
1718 1689 Note that %edit is also available through the alias %ed.
1719 1690
1720 1691 This is an example of creating a simple function inside the editor and
1721 1692 then modifying it. First, start up the editor:
1722 1693
1723 1694 In [1]: ed\\
1724 1695 Editing... done. Executing edited code...\\
1725 1696 Out[1]: 'def foo():\\n print "foo() was defined in an editing session"\\n'
1726 1697
1727 1698 We can then call the function foo():
1728 1699
1729 1700 In [2]: foo()\\
1730 1701 foo() was defined in an editing session
1731 1702
1732 1703 Now we edit foo. IPython automatically loads the editor with the
1733 1704 (temporary) file where foo() was previously defined:
1734 1705
1735 1706 In [3]: ed foo\\
1736 1707 Editing... done. Executing edited code...
1737 1708
1738 1709 And if we call foo() again we get the modified version:
1739 1710
1740 1711 In [4]: foo()\\
1741 1712 foo() has now been changed!
1742 1713
1743 1714 Here is an example of how to edit a code snippet successive
1744 1715 times. First we call the editor:
1745 1716
1746 1717 In [8]: ed\\
1747 1718 Editing... done. Executing edited code...\\
1748 1719 hello\\
1749 1720 Out[8]: "print 'hello'\\n"
1750 1721
1751 1722 Now we call it again with the previous output (stored in _):
1752 1723
1753 1724 In [9]: ed _\\
1754 1725 Editing... done. Executing edited code...\\
1755 1726 hello world\\
1756 1727 Out[9]: "print 'hello world'\\n"
1757 1728
1758 1729 Now we call it with the output #8 (stored in _8, also as Out[8]):
1759 1730
1760 1731 In [10]: ed _8\\
1761 1732 Editing... done. Executing edited code...\\
1762 1733 hello again\\
1763 1734 Out[10]: "print 'hello again'\\n"
1764 1735
1765 1736
1766 1737 Changing the default editor hook:
1767 1738
1768 1739 If you wish to write your own editor hook, you can put it in a
1769 1740 configuration file which you load at startup time. The default hook
1770 1741 is defined in the IPython.hooks module, and you can use that as a
1771 1742 starting example for further modifications. That file also has
1772 1743 general instructions on how to set a new hook for use once you've
1773 1744 defined it."""
1774 1745
1775 1746 # FIXME: This function has become a convoluted mess. It needs a
1776 1747 # ground-up rewrite with clean, simple logic.
1777 1748
1778 1749 def make_filename(arg):
1779 1750 "Make a filename from the given args"
1780 1751 try:
1781 1752 filename = get_py_filename(arg)
1782 1753 except IOError:
1783 1754 if args.endswith('.py'):
1784 1755 filename = arg
1785 1756 else:
1786 1757 filename = None
1787 1758 return filename
1788 1759
1789 1760 # custom exceptions
1790 1761 class DataIsObject(Exception): pass
1791 1762
1792 1763 opts,args = self.parse_options(parameter_s,'px')
1793 1764
1794 1765 # Default line number value
1795 1766 lineno = None
1796 1767 if opts.has_key('p'):
1797 1768 args = '_%s' % last_call[0]
1798 1769 if not self.shell.user_ns.has_key(args):
1799 1770 args = last_call[1]
1800 1771
1801 1772 # use last_call to remember the state of the previous call, but don't
1802 1773 # let it be clobbered by successive '-p' calls.
1803 1774 try:
1804 1775 last_call[0] = self.shell.outputcache.prompt_count
1805 1776 if not opts.has_key('p'):
1806 1777 last_call[1] = parameter_s
1807 1778 except:
1808 1779 pass
1809 1780
1810 1781 # by default this is done with temp files, except when the given
1811 1782 # arg is a filename
1812 1783 use_temp = 1
1813 1784
1814 1785 if re.match(r'\d',args):
1815 1786 # Mode where user specifies ranges of lines, like in %macro.
1816 1787 # This means that you can't edit files whose names begin with
1817 1788 # numbers this way. Tough.
1818 1789 ranges = args.split()
1819 1790 data = ''.join(self.extract_input_slices(ranges))
1820 1791 elif args.endswith('.py'):
1821 1792 filename = make_filename(args)
1822 1793 data = ''
1823 1794 use_temp = 0
1824 1795 elif args:
1825 1796 try:
1826 1797 # Load the parameter given as a variable. If not a string,
1827 1798 # process it as an object instead (below)
1828 1799
1829 1800 #print '*** args',args,'type',type(args) # dbg
1830 1801 data = eval(args,self.shell.user_ns)
1831 1802 if not type(data) in StringTypes:
1832 1803 raise DataIsObject
1833 1804 except (NameError,SyntaxError):
1834 1805 # given argument is not a variable, try as a filename
1835 1806 filename = make_filename(args)
1836 1807 if filename is None:
1837 1808 warn("Argument given (%s) can't be found as a variable "
1838 1809 "or as a filename." % args)
1839 1810 return
1840 1811 data = ''
1841 1812 use_temp = 0
1842 1813 except DataIsObject:
1843 1814 # For objects, try to edit the file where they are defined
1844 1815 try:
1845 1816 filename = inspect.getabsfile(data)
1846 1817 datafile = 1
1847 1818 except TypeError:
1848 1819 filename = make_filename(args)
1849 1820 datafile = 1
1850 1821 warn('Could not find file where `%s` is defined.\n'
1851 1822 'Opening a file named `%s`' % (args,filename))
1852 1823 # Now, make sure we can actually read the source (if it was in
1853 1824 # a temp file it's gone by now).
1854 1825 if datafile:
1855 1826 try:
1856 1827 lineno = inspect.getsourcelines(data)[1]
1857 1828 except IOError:
1858 1829 filename = make_filename(args)
1859 1830 if filename is None:
1860 1831 warn('The file `%s` where `%s` was defined cannot '
1861 1832 'be read.' % (filename,data))
1862 1833 return
1863 1834 use_temp = 0
1864 1835 else:
1865 1836 data = ''
1866 1837
1867 1838 if use_temp:
1868 1839 filename = tempfile.mktemp('.py')
1869 1840 self.shell.tempfiles.append(filename)
1870 1841
1871 1842 if data and use_temp:
1872 1843 tmp_file = open(filename,'w')
1873 1844 tmp_file.write(data)
1874 1845 tmp_file.close()
1875 1846
1876 1847 # do actual editing here
1877 1848 print 'Editing...',
1878 1849 sys.stdout.flush()
1879 1850 self.shell.hooks.editor(filename,lineno)
1880 1851 if opts.has_key('x'): # -x prevents actual execution
1881 1852 print
1882 1853 else:
1883 1854 print 'done. Executing edited code...'
1884 1855 try:
1885 1856 self.shell.safe_execfile(filename,self.shell.user_ns)
1886 1857 except IOError,msg:
1887 1858 if msg.filename == filename:
1888 1859 warn('File not found. Did you forget to save?')
1889 1860 return
1890 1861 else:
1891 1862 self.shell.showtraceback()
1892 1863 except:
1893 1864 self.shell.showtraceback()
1894 1865 if use_temp:
1895 1866 contents = open(filename).read()
1896 1867 return contents
1897 1868
1898 1869 def magic_xmode(self,parameter_s = ''):
1899 1870 """Switch modes for the exception handlers.
1900 1871
1901 1872 Valid modes: Plain, Context and Verbose.
1902 1873
1903 1874 If called without arguments, acts as a toggle."""
1904 1875
1905 1876 def xmode_switch_err(name):
1906 1877 warn('Error changing %s exception modes.\n%s' %
1907 1878 (name,sys.exc_info()[1]))
1908 1879
1880 shell = self.shell
1909 1881 new_mode = parameter_s.strip().capitalize()
1910 1882 try:
1911 self.InteractiveTB.set_mode(mode=new_mode)
1912 print 'Exception reporting mode:',self.InteractiveTB.mode
1883 shell.InteractiveTB.set_mode(mode=new_mode)
1884 print 'Exception reporting mode:',shell.InteractiveTB.mode
1913 1885 except:
1914 1886 xmode_switch_err('user')
1915 1887
1916 1888 # threaded shells use a special handler in sys.excepthook
1917 if self.isthreaded:
1889 if shell.isthreaded:
1918 1890 try:
1919 self.shell.sys_excepthook.set_mode(mode=new_mode)
1891 shell.sys_excepthook.set_mode(mode=new_mode)
1920 1892 except:
1921 1893 xmode_switch_err('threaded')
1922 1894
1923 1895 def magic_colors(self,parameter_s = ''):
1924 1896 """Switch color scheme for prompts, info system and exception handlers.
1925 1897
1926 1898 Currently implemented schemes: NoColor, Linux, LightBG.
1927 1899
1928 1900 Color scheme names are not case-sensitive."""
1929 1901
1930 1902 def color_switch_err(name):
1931 1903 warn('Error changing %s color schemes.\n%s' %
1932 1904 (name,sys.exc_info()[1]))
1933 1905
1934 1906
1935 1907 new_scheme = parameter_s.strip()
1936 1908 if not new_scheme:
1937 1909 print 'You must specify a color scheme.'
1938 1910 return
1939 1911 # Under Windows, check for Gary Bishop's readline, which is necessary
1940 1912 # for ANSI coloring
1941 1913 if os.name in ['nt','dos']:
1942 1914 try:
1943 1915 import readline
1944 1916 except ImportError:
1945 1917 has_readline = 0
1946 1918 else:
1947 1919 try:
1948 1920 readline.GetOutputFile()
1949 1921 except AttributeError:
1950 1922 has_readline = 0
1951 1923 else:
1952 1924 has_readline = 1
1953 1925 if not has_readline:
1954 1926 msg = """\
1955 1927 Proper color support under MS Windows requires Gary Bishop's readline library.
1956 1928 You can find it at:
1957 1929 http://sourceforge.net/projects/uncpythontools
1958 1930 Gary's readline needs the ctypes module, from:
1959 1931 http://starship.python.net/crew/theller/ctypes
1960 1932
1961 1933 Defaulting color scheme to 'NoColor'"""
1962 1934 new_scheme = 'NoColor'
1963 1935 warn(msg)
1936 # local shortcut
1937 shell = self.shell
1964 1938
1965 1939 # Set prompt colors
1966 1940 try:
1967 self.shell.outputcache.set_colors(new_scheme)
1941 shell.outputcache.set_colors(new_scheme)
1968 1942 except:
1969 1943 color_switch_err('prompt')
1970 1944 else:
1971 self.shell.rc.colors = \
1972 self.shell.outputcache.color_table.active_scheme_name
1945 shell.rc.colors = \
1946 shell.outputcache.color_table.active_scheme_name
1973 1947 # Set exception colors
1974 1948 try:
1975 self.shell.InteractiveTB.set_colors(scheme = new_scheme)
1976 self.shell.SyntaxTB.set_colors(scheme = new_scheme)
1949 shell.InteractiveTB.set_colors(scheme = new_scheme)
1950 shell.SyntaxTB.set_colors(scheme = new_scheme)
1977 1951 except:
1978 1952 color_switch_err('exception')
1979 1953
1980 1954 # threaded shells use a verbose traceback in sys.excepthook
1981 if self.isthreaded:
1955 if shell.isthreaded:
1982 1956 try:
1983 self.shell.sys_excepthook.set_colors(scheme=new_scheme)
1957 shell.sys_excepthook.set_colors(scheme=new_scheme)
1984 1958 except:
1985 1959 color_switch_err('system exception handler')
1986 1960
1987 1961 # Set info (for 'object?') colors
1988 if self.shell.rc.color_info:
1962 if shell.rc.color_info:
1989 1963 try:
1990 self.shell.inspector.set_active_scheme(new_scheme)
1964 shell.inspector.set_active_scheme(new_scheme)
1991 1965 except:
1992 1966 color_switch_err('object inspector')
1993 1967 else:
1994 self.shell.inspector.set_active_scheme('NoColor')
1968 shell.inspector.set_active_scheme('NoColor')
1995 1969
1996 1970 def magic_color_info(self,parameter_s = ''):
1997 1971 """Toggle color_info.
1998 1972
1999 1973 The color_info configuration parameter controls whether colors are
2000 1974 used for displaying object details (by things like %psource, %pfile or
2001 1975 the '?' system). This function toggles this value with each call.
2002 1976
2003 1977 Note that unless you have a fairly recent pager (less works better
2004 1978 than more) in your system, using colored object information displays
2005 1979 will not work properly. Test it and see."""
2006 1980
2007 1981 self.shell.rc.color_info = 1 - self.shell.rc.color_info
2008 1982 self.magic_colors(self.shell.rc.colors)
2009 1983 print 'Object introspection functions have now coloring:',
2010 1984 print ['OFF','ON'][self.shell.rc.color_info]
2011 1985
2012 1986 def magic_Pprint(self, parameter_s=''):
2013 1987 """Toggle pretty printing on/off."""
2014 1988
2015 1989 self.shell.outputcache.Pprint = 1 - self.shell.outputcache.Pprint
2016 1990 print 'Pretty printing has been turned', \
2017 1991 ['OFF','ON'][self.shell.outputcache.Pprint]
2018 1992
2019 1993 def magic_exit(self, parameter_s=''):
2020 1994 """Exit IPython, confirming if configured to do so.
2021 1995
2022 1996 You can configure whether IPython asks for confirmation upon exit by
2023 1997 setting the confirm_exit flag in the ipythonrc file."""
2024 1998
2025 1999 self.shell.exit()
2026 2000
2027 2001 def magic_quit(self, parameter_s=''):
2028 2002 """Exit IPython, confirming if configured to do so (like %exit)"""
2029 2003
2030 2004 self.shell.exit()
2031 2005
2032 2006 def magic_Exit(self, parameter_s=''):
2033 2007 """Exit IPython without confirmation."""
2034 2008
2035 2009 self.shell.exit_now = True
2036 2010
2037 2011 def magic_Quit(self, parameter_s=''):
2038 2012 """Exit IPython without confirmation (like %Exit)."""
2039 2013
2040 2014 self.shell.exit_now = True
2041 2015
2042 2016 #......................................................................
2043 2017 # Functions to implement unix shell-type things
2044 2018
2045 2019 def magic_alias(self, parameter_s = ''):
2046 2020 """Define an alias for a system command.
2047 2021
2048 2022 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
2049 2023
2050 2024 Then, typing 'alias_name params' will execute the system command 'cmd
2051 2025 params' (from your underlying operating system).
2052 2026
2053 2027 Aliases have lower precedence than magic functions and Python normal
2054 2028 variables, so if 'foo' is both a Python variable and an alias, the
2055 2029 alias can not be executed until 'del foo' removes the Python variable.
2056 2030
2057 2031 You can use the %l specifier in an alias definition to represent the
2058 2032 whole line when the alias is called. For example:
2059 2033
2060 2034 In [2]: alias all echo "Input in brackets: <%l>"\\
2061 2035 In [3]: all hello world\\
2062 2036 Input in brackets: <hello world>
2063 2037
2064 2038 You can also define aliases with parameters using %s specifiers (one
2065 2039 per parameter):
2066 2040
2067 2041 In [1]: alias parts echo first %s second %s\\
2068 2042 In [2]: %parts A B\\
2069 2043 first A second B\\
2070 2044 In [3]: %parts A\\
2071 2045 Incorrect number of arguments: 2 expected.\\
2072 2046 parts is an alias to: 'echo first %s second %s'
2073 2047
2074 2048 Note that %l and %s are mutually exclusive. You can only use one or
2075 2049 the other in your aliases.
2076 2050
2077 2051 Aliases expand Python variables just like system calls using ! or !!
2078 2052 do: all expressions prefixed with '$' get expanded. For details of
2079 2053 the semantic rules, see PEP-215:
2080 2054 http://www.python.org/peps/pep-0215.html. This is the library used by
2081 2055 IPython for variable expansion. If you want to access a true shell
2082 2056 variable, an extra $ is necessary to prevent its expansion by IPython:
2083 2057
2084 2058 In [6]: alias show echo\\
2085 2059 In [7]: PATH='A Python string'\\
2086 2060 In [8]: show $PATH\\
2087 2061 A Python string\\
2088 2062 In [9]: show $$PATH\\
2089 2063 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
2090 2064
2091 2065 You can use the alias facility to acess all of $PATH. See the %rehash
2092 2066 and %rehashx functions, which automatically create aliases for the
2093 2067 contents of your $PATH.
2094 2068
2095 2069 If called with no parameters, %alias prints the current alias table."""
2096 2070
2097 2071 par = parameter_s.strip()
2098 2072 if not par:
2099 2073 if self.shell.rc.automagic:
2100 2074 prechar = ''
2101 2075 else:
2102 2076 prechar = self.shell.ESC_MAGIC
2103 2077 print 'Alias\t\tSystem Command\n'+'-'*30
2104 2078 atab = self.shell.alias_table
2105 2079 aliases = atab.keys()
2106 2080 aliases.sort()
2107 2081 for alias in aliases:
2108 2082 print prechar+alias+'\t\t'+atab[alias][1]
2109 2083 print '-'*30+'\nTotal number of aliases:',len(aliases)
2110 2084 return
2111 2085 try:
2112 2086 alias,cmd = par.split(None,1)
2113 2087 except:
2114 2088 print OInspect.getdoc(self.magic_alias)
2115 2089 else:
2116 2090 nargs = cmd.count('%s')
2117 2091 if nargs>0 and cmd.find('%l')>=0:
2118 2092 error('The %s and %l specifiers are mutually exclusive '
2119 2093 'in alias definitions.')
2120 2094 else: # all looks OK
2121 2095 self.shell.alias_table[alias] = (nargs,cmd)
2122 2096 self.shell.alias_table_validate(verbose=1)
2123 2097 # end magic_alias
2124 2098
2125 2099 def magic_unalias(self, parameter_s = ''):
2126 2100 """Remove an alias"""
2127 2101
2128 2102 aname = parameter_s.strip()
2129 2103 if aname in self.shell.alias_table:
2130 2104 del self.shell.alias_table[aname]
2131 2105
2132 2106 def magic_rehash(self, parameter_s = ''):
2133 2107 """Update the alias table with all entries in $PATH.
2134 2108
2135 2109 This version does no checks on execute permissions or whether the
2136 2110 contents of $PATH are truly files (instead of directories or something
2137 2111 else). For such a safer (but slower) version, use %rehashx."""
2138 2112
2139 2113 # This function (and rehashx) manipulate the alias_table directly
2140 2114 # rather than calling magic_alias, for speed reasons. A rehash on a
2141 2115 # typical Linux box involves several thousand entries, so efficiency
2142 2116 # here is a top concern.
2143 2117
2144 2118 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2145 2119 alias_table = self.shell.alias_table
2146 2120 for pdir in path:
2147 2121 for ff in os.listdir(pdir):
2148 2122 # each entry in the alias table must be (N,name), where
2149 2123 # N is the number of positional arguments of the alias.
2150 2124 alias_table[ff] = (0,ff)
2151 2125 # Make sure the alias table doesn't contain keywords or builtins
2152 2126 self.shell.alias_table_validate()
2153 2127 # Call again init_auto_alias() so we get 'rm -i' and other modified
2154 2128 # aliases since %rehash will probably clobber them
2155 2129 self.shell.init_auto_alias()
2156 2130
2157 2131 def magic_rehashx(self, parameter_s = ''):
2158 2132 """Update the alias table with all executable files in $PATH.
2159 2133
2160 2134 This version explicitly checks that every entry in $PATH is a file
2161 2135 with execute access (os.X_OK), so it is much slower than %rehash.
2162 2136
2163 2137 Under Windows, it checks executability as a match agains a
2164 2138 '|'-separated string of extensions, stored in the IPython config
2165 2139 variable win_exec_ext. This defaults to 'exe|com|bat'. """
2166 2140
2167 2141 path = filter(os.path.isdir,os.environ['PATH'].split(os.pathsep))
2168 2142 alias_table = self.shell.alias_table
2169 2143
2170 2144 if os.name == 'posix':
2171 2145 isexec = lambda fname:os.path.isfile(fname) and \
2172 2146 os.access(fname,os.X_OK)
2173 2147 else:
2174 2148
2175 2149 try:
2176 2150 winext = os.environ['pathext'].replace(';','|').replace('.','')
2177 2151 except KeyError:
2178 2152 winext = 'exe|com|bat'
2179 2153
2180 2154 execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
2181 2155 isexec = lambda fname:os.path.isfile(fname) and execre.match(fname)
2182 2156 savedir = os.getcwd()
2183 2157 try:
2184 2158 # write the whole loop for posix/Windows so we don't have an if in
2185 2159 # the innermost part
2186 2160 if os.name == 'posix':
2187 2161 for pdir in path:
2188 2162 os.chdir(pdir)
2189 2163 for ff in os.listdir(pdir):
2190 2164 if isexec(ff):
2191 2165 # each entry in the alias table must be (N,name),
2192 2166 # where N is the number of positional arguments of the
2193 2167 # alias.
2194 2168 alias_table[ff] = (0,ff)
2195 2169 else:
2196 2170 for pdir in path:
2197 2171 os.chdir(pdir)
2198 2172 for ff in os.listdir(pdir):
2199 2173 if isexec(ff):
2200 2174 alias_table[execre.sub(r'\1',ff)] = (0,ff)
2201 2175 # Make sure the alias table doesn't contain keywords or builtins
2202 2176 self.shell.alias_table_validate()
2203 2177 # Call again init_auto_alias() so we get 'rm -i' and other
2204 2178 # modified aliases since %rehashx will probably clobber them
2205 2179 self.shell.init_auto_alias()
2206 2180 finally:
2207 2181 os.chdir(savedir)
2208 2182
2209 2183 def magic_pwd(self, parameter_s = ''):
2210 2184 """Return the current working directory path."""
2211 2185 return os.getcwd()
2212 2186
2213 2187 def magic_cd(self, parameter_s=''):
2214 2188 """Change the current working directory.
2215 2189
2216 2190 This command automatically maintains an internal list of directories
2217 2191 you visit during your IPython session, in the variable _dh. The
2218 2192 command %dhist shows this history nicely formatted.
2219 2193
2220 2194 Usage:
2221 2195
2222 2196 cd 'dir': changes to directory 'dir'.
2223 2197
2224 2198 cd -: changes to the last visited directory.
2225 2199
2226 2200 cd -<n>: changes to the n-th directory in the directory history.
2227 2201
2228 2202 cd -b <bookmark_name>: jump to a bookmark set by %bookmark
2229 2203 (note: cd <bookmark_name> is enough if there is no
2230 2204 directory <bookmark_name>, but a bookmark with the name exists.)
2231 2205
2232 2206 Options:
2233 2207
2234 2208 -q: quiet. Do not print the working directory after the cd command is
2235 2209 executed. By default IPython's cd command does print this directory,
2236 2210 since the default prompts do not display path information.
2237 2211
2238 2212 Note that !cd doesn't work for this purpose because the shell where
2239 2213 !command runs is immediately discarded after executing 'command'."""
2240 2214
2241 2215 parameter_s = parameter_s.strip()
2242 2216 bkms = self.shell.persist.get("bookmarks",{})
2243 2217
2244 2218 numcd = re.match(r'(-)(\d+)$',parameter_s)
2245 2219 # jump in directory history by number
2246 2220 if numcd:
2247 2221 nn = int(numcd.group(2))
2248 2222 try:
2249 2223 ps = self.shell.user_ns['_dh'][nn]
2250 2224 except IndexError:
2251 2225 print 'The requested directory does not exist in history.'
2252 2226 return
2253 2227 else:
2254 2228 opts = {}
2255 2229 else:
2256 2230 opts,ps = self.parse_options(parameter_s,'qb',mode='string')
2257 2231 # jump to previous
2258 2232 if ps == '-':
2259 2233 try:
2260 2234 ps = self.shell.user_ns['_dh'][-2]
2261 2235 except IndexError:
2262 2236 print 'No previous directory to change to.'
2263 2237 return
2264 2238 # jump to bookmark
2265 2239 elif opts.has_key('b') or (bkms.has_key(ps) and not os.path.isdir(ps)):
2266 2240 if bkms.has_key(ps):
2267 2241 target = bkms[ps]
2268 2242 print '(bookmark:%s) -> %s' % (ps,target)
2269 2243 ps = target
2270 2244 else:
2271 2245 if bkms:
2272 2246 error("Bookmark '%s' not found. "
2273 2247 "Use '%bookmark -l' to see your bookmarks." % ps)
2274 2248 else:
2275 2249 print "Bookmarks not set - use %bookmark <bookmarkname>"
2276 2250 return
2277 2251
2278 2252 # at this point ps should point to the target dir
2279 2253 if ps:
2280 2254 try:
2281 2255 os.chdir(os.path.expanduser(ps))
2282 2256 except OSError:
2283 2257 print sys.exc_info()[1]
2284 2258 else:
2285 2259 self.shell.user_ns['_dh'].append(os.getcwd())
2286 2260 else:
2287 os.chdir(self.home_dir)
2261 os.chdir(self.shell.home_dir)
2288 2262 self.shell.user_ns['_dh'].append(os.getcwd())
2289 2263 if not 'q' in opts:
2290 2264 print self.shell.user_ns['_dh'][-1]
2291 2265
2292 2266 def magic_dhist(self, parameter_s=''):
2293 2267 """Print your history of visited directories.
2294 2268
2295 2269 %dhist -> print full history\\
2296 2270 %dhist n -> print last n entries only\\
2297 2271 %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\
2298 2272
2299 2273 This history is automatically maintained by the %cd command, and
2300 2274 always available as the global list variable _dh. You can use %cd -<n>
2301 2275 to go to directory number <n>."""
2302 2276
2303 2277 dh = self.shell.user_ns['_dh']
2304 2278 if parameter_s:
2305 2279 try:
2306 2280 args = map(int,parameter_s.split())
2307 2281 except:
2308 2282 self.arg_err(Magic.magic_dhist)
2309 2283 return
2310 2284 if len(args) == 1:
2311 2285 ini,fin = max(len(dh)-(args[0]),0),len(dh)
2312 2286 elif len(args) == 2:
2313 2287 ini,fin = args
2314 2288 else:
2315 2289 self.arg_err(Magic.magic_dhist)
2316 2290 return
2317 2291 else:
2318 2292 ini,fin = 0,len(dh)
2319 2293 nlprint(dh,
2320 2294 header = 'Directory history (kept in _dh)',
2321 2295 start=ini,stop=fin)
2322 2296
2323 2297 def magic_env(self, parameter_s=''):
2324 2298 """List environment variables."""
2325 2299
2326 # environ is an instance of UserDict
2327 2300 return os.environ.data
2328 2301
2329 2302 def magic_pushd(self, parameter_s=''):
2330 2303 """Place the current dir on stack and change directory.
2331 2304
2332 2305 Usage:\\
2333 2306 %pushd ['dirname']
2334 2307
2335 2308 %pushd with no arguments does a %pushd to your home directory.
2336 2309 """
2337 2310 if parameter_s == '': parameter_s = '~'
2338 if len(self.dir_stack)>0 and os.path.expanduser(parameter_s) != \
2339 os.path.expanduser(self.dir_stack[0]):
2311 dir_s = self.shell.dir_stack
2312 if len(dir_s)>0 and os.path.expanduser(parameter_s) != \
2313 os.path.expanduser(self.shell.dir_stack[0]):
2340 2314 try:
2341 2315 self.magic_cd(parameter_s)
2342 self.dir_stack.insert(0,os.getcwd().replace(self.home_dir,'~'))
2316 dir_s.insert(0,os.getcwd().replace(self.home_dir,'~'))
2343 2317 self.magic_dirs()
2344 2318 except:
2345 2319 print 'Invalid directory'
2346 2320 else:
2347 2321 print 'You are already there!'
2348 2322
2349 2323 def magic_popd(self, parameter_s=''):
2350 2324 """Change to directory popped off the top of the stack.
2351 2325 """
2352 if len (self.dir_stack) > 1:
2353 self.dir_stack.pop(0)
2354 self.magic_cd(self.dir_stack[0])
2355 print self.dir_stack[0]
2326 if len (self.shell.dir_stack) > 1:
2327 self.shell.dir_stack.pop(0)
2328 self.magic_cd(self.shell.dir_stack[0])
2329 print self.shell.dir_stack[0]
2356 2330 else:
2357 2331 print "You can't remove the starting directory from the stack:",\
2358 self.dir_stack
2332 self.shell.dir_stack
2359 2333
2360 2334 def magic_dirs(self, parameter_s=''):
2361 2335 """Return the current directory stack."""
2362 2336
2363 return self.dir_stack[:]
2337 return self.shell.dir_stack[:]
2364 2338
2365 2339 def magic_sc(self, parameter_s=''):
2366 2340 """Shell capture - execute a shell command and capture its output.
2367 2341
2368 2342 %sc [options] varname=command
2369 2343
2370 2344 IPython will run the given command using commands.getoutput(), and
2371 2345 will then update the user's interactive namespace with a variable
2372 2346 called varname, containing the value of the call. Your command can
2373 2347 contain shell wildcards, pipes, etc.
2374 2348
2375 2349 The '=' sign in the syntax is mandatory, and the variable name you
2376 2350 supply must follow Python's standard conventions for valid names.
2377 2351
2378 2352 Options:
2379 2353
2380 2354 -l: list output. Split the output on newlines into a list before
2381 2355 assigning it to the given variable. By default the output is stored
2382 2356 as a single string.
2383 2357
2384 2358 -v: verbose. Print the contents of the variable.
2385 2359
2386 2360 In most cases you should not need to split as a list, because the
2387 2361 returned value is a special type of string which can automatically
2388 2362 provide its contents either as a list (split on newlines) or as a
2389 2363 space-separated string. These are convenient, respectively, either
2390 2364 for sequential processing or to be passed to a shell command.
2391 2365
2392 2366 For example:
2393 2367
2394 2368 # Capture into variable a
2395 2369 In [9]: sc a=ls *py
2396 2370
2397 2371 # a is a string with embedded newlines
2398 2372 In [10]: a
2399 2373 Out[10]: 'setup.py\nwin32_manual_post_install.py'
2400 2374
2401 2375 # which can be seen as a list:
2402 2376 In [11]: a.l
2403 2377 Out[11]: ['setup.py', 'win32_manual_post_install.py']
2404 2378
2405 2379 # or as a whitespace-separated string:
2406 2380 In [12]: a.s
2407 2381 Out[12]: 'setup.py win32_manual_post_install.py'
2408 2382
2409 2383 # a.s is useful to pass as a single command line:
2410 2384 In [13]: !wc -l $a.s
2411 2385 146 setup.py
2412 2386 130 win32_manual_post_install.py
2413 2387 276 total
2414 2388
2415 2389 # while the list form is useful to loop over:
2416 2390 In [14]: for f in a.l:
2417 2391 ....: !wc -l $f
2418 2392 ....:
2419 2393 146 setup.py
2420 2394 130 win32_manual_post_install.py
2421 2395
2422 2396 Similiarly, the lists returned by the -l option are also special, in
2423 2397 the sense that you can equally invoke the .s attribute on them to
2424 2398 automatically get a whitespace-separated string from their contents:
2425 2399
2426 2400 In [1]: sc -l b=ls *py
2427 2401
2428 2402 In [2]: b
2429 2403 Out[2]: ['setup.py', 'win32_manual_post_install.py']
2430 2404
2431 2405 In [3]: b.s
2432 2406 Out[3]: 'setup.py win32_manual_post_install.py'
2433 2407
2434 2408 In summary, both the lists and strings used for ouptut capture have
2435 2409 the following special attributes:
2436 2410
2437 2411 .l (or .list) : value as list.
2438 2412 .n (or .nlstr): value as newline-separated string.
2439 2413 .s (or .spstr): value as space-separated string.
2440 2414 """
2441 2415
2442 2416 opts,args = self.parse_options(parameter_s,'lv')
2443 2417 # Try to get a variable name and command to run
2444 2418 try:
2445 2419 # the variable name must be obtained from the parse_options
2446 2420 # output, which uses shlex.split to strip options out.
2447 2421 var,_ = args.split('=',1)
2448 2422 var = var.strip()
2449 2423 # But the the command has to be extracted from the original input
2450 2424 # parameter_s, not on what parse_options returns, to avoid the
2451 2425 # quote stripping which shlex.split performs on it.
2452 2426 _,cmd = parameter_s.split('=',1)
2453 2427 except ValueError:
2454 2428 var,cmd = '',''
2455 2429 if not var:
2456 2430 error('you must specify a variable to assign the command to.')
2457 2431 return
2458 2432 # If all looks ok, proceed
2459 2433 out,err = self.shell.getoutputerror(cmd)
2460 2434 if err:
2461 2435 print >> Term.cerr,err
2462 2436 if opts.has_key('l'):
2463 2437 out = SList(out.split('\n'))
2464 2438 else:
2465 2439 out = LSString(out)
2466 2440 if opts.has_key('v'):
2467 2441 print '%s ==\n%s' % (var,pformat(out))
2468 2442 self.shell.user_ns.update({var:out})
2469 2443
2470 2444 def magic_sx(self, parameter_s=''):
2471 2445 """Shell execute - run a shell command and capture its output.
2472 2446
2473 2447 %sx command
2474 2448
2475 2449 IPython will run the given command using commands.getoutput(), and
2476 2450 return the result formatted as a list (split on '\\n'). Since the
2477 2451 output is _returned_, it will be stored in ipython's regular output
2478 2452 cache Out[N] and in the '_N' automatic variables.
2479 2453
2480 2454 Notes:
2481 2455
2482 2456 1) If an input line begins with '!!', then %sx is automatically
2483 2457 invoked. That is, while:
2484 2458 !ls
2485 2459 causes ipython to simply issue system('ls'), typing
2486 2460 !!ls
2487 2461 is a shorthand equivalent to:
2488 2462 %sx ls
2489 2463
2490 2464 2) %sx differs from %sc in that %sx automatically splits into a list,
2491 2465 like '%sc -l'. The reason for this is to make it as easy as possible
2492 2466 to process line-oriented shell output via further python commands.
2493 2467 %sc is meant to provide much finer control, but requires more
2494 2468 typing.
2495 2469
2496 2470 3) Just like %sc -l, this is a list with special attributes:
2497 2471
2498 2472 .l (or .list) : value as list.
2499 2473 .n (or .nlstr): value as newline-separated string.
2500 2474 .s (or .spstr): value as whitespace-separated string.
2501 2475
2502 2476 This is very useful when trying to use such lists as arguments to
2503 2477 system commands."""
2504 2478
2505 2479 if parameter_s:
2506 2480 out,err = self.shell.getoutputerror(parameter_s)
2507 2481 if err:
2508 2482 print >> Term.cerr,err
2509 2483 return SList(out.split('\n'))
2510 2484
2511 2485 def magic_bg(self, parameter_s=''):
2512 2486 """Run a job in the background, in a separate thread.
2513 2487
2514 2488 For example,
2515 2489
2516 2490 %bg myfunc(x,y,z=1)
2517 2491
2518 2492 will execute 'myfunc(x,y,z=1)' in a background thread. As soon as the
2519 2493 execution starts, a message will be printed indicating the job
2520 2494 number. If your job number is 5, you can use
2521 2495
2522 2496 myvar = jobs.result(5) or myvar = jobs[5].result
2523 2497
2524 2498 to assign this result to variable 'myvar'.
2525 2499
2526 2500 IPython has a job manager, accessible via the 'jobs' object. You can
2527 2501 type jobs? to get more information about it, and use jobs.<TAB> to see
2528 2502 its attributes. All attributes not starting with an underscore are
2529 2503 meant for public use.
2530 2504
2531 2505 In particular, look at the jobs.new() method, which is used to create
2532 2506 new jobs. This magic %bg function is just a convenience wrapper
2533 2507 around jobs.new(), for expression-based jobs. If you want to create a
2534 2508 new job with an explicit function object and arguments, you must call
2535 2509 jobs.new() directly.
2536 2510
2537 2511 The jobs.new docstring also describes in detail several important
2538 2512 caveats associated with a thread-based model for background job
2539 2513 execution. Type jobs.new? for details.
2540 2514
2541 2515 You can check the status of all jobs with jobs.status().
2542 2516
2543 2517 The jobs variable is set by IPython into the Python builtin namespace.
2544 2518 If you ever declare a variable named 'jobs', you will shadow this
2545 2519 name. You can either delete your global jobs variable to regain
2546 2520 access to the job manager, or make a new name and assign it manually
2547 2521 to the manager (stored in IPython's namespace). For example, to
2548 2522 assign the job manager to the Jobs name, use:
2549 2523
2550 2524 Jobs = __builtins__.jobs"""
2551 2525
2552 2526 self.shell.jobs.new(parameter_s,self.shell.user_ns)
2553 2527
2554 2528 def magic_bookmark(self, parameter_s=''):
2555 2529 """Manage IPython's bookmark system.
2556 2530
2557 2531 %bookmark <name> - set bookmark to current dir
2558 2532 %bookmark <name> <dir> - set bookmark to <dir>
2559 2533 %bookmark -l - list all bookmarks
2560 2534 %bookmark -d <name> - remove bookmark
2561 2535 %bookmark -r - remove all bookmarks
2562 2536
2563 2537 You can later on access a bookmarked folder with:
2564 2538 %cd -b <name>
2565 2539 or simply '%cd <name>' if there is no directory called <name> AND
2566 2540 there is such a bookmark defined.
2567 2541
2568 2542 Your bookmarks persist through IPython sessions, but they are
2569 2543 associated with each profile."""
2570 2544
2571 2545 opts,args = self.parse_options(parameter_s,'drl',mode='list')
2572 2546 if len(args) > 2:
2573 2547 error('You can only give at most two arguments')
2574 2548 return
2575 2549
2576 2550 bkms = self.shell.persist.get('bookmarks',{})
2577 2551
2578 2552 if opts.has_key('d'):
2579 2553 try:
2580 2554 todel = args[0]
2581 2555 except IndexError:
2582 2556 error('You must provide a bookmark to delete')
2583 2557 else:
2584 2558 try:
2585 2559 del bkms[todel]
2586 2560 except:
2587 2561 error("Can't delete bookmark '%s'" % todel)
2588 2562 elif opts.has_key('r'):
2589 2563 bkms = {}
2590 2564 elif opts.has_key('l'):
2591 2565 bks = bkms.keys()
2592 2566 bks.sort()
2593 2567 if bks:
2594 2568 size = max(map(len,bks))
2595 2569 else:
2596 2570 size = 0
2597 2571 fmt = '%-'+str(size)+'s -> %s'
2598 2572 print 'Current bookmarks:'
2599 2573 for bk in bks:
2600 2574 print fmt % (bk,bkms[bk])
2601 2575 else:
2602 2576 if not args:
2603 2577 error("You must specify the bookmark name")
2604 2578 elif len(args)==1:
2605 2579 bkms[args[0]] = os.getcwd()
2606 2580 elif len(args)==2:
2607 2581 bkms[args[0]] = args[1]
2608 self.persist['bookmarks'] = bkms
2582 self.shell.persist['bookmarks'] = bkms
2609 2583
2610 2584 def magic_pycat(self, parameter_s=''):
2611 2585 """Show a syntax-highlighted file through a pager.
2612 2586
2613 2587 This magic is similar to the cat utility, but it will assume the file
2614 2588 to be Python source and will show it with syntax highlighting. """
2615 2589
2616 2590 filename = get_py_filename(parameter_s)
2617 2591 page(self.shell.colorize(file_read(filename)),
2618 2592 screen_lines=self.shell.rc.screen_length)
2619 2593
2620 2594 # end Magic
@@ -1,578 +1,583 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 Classes for handling input/output prompts.
4 4
5 $Id: Prompts.py 960 2005-12-28 06:51:01Z fperez $"""
5 $Id: Prompts.py 966 2005-12-29 08:34:07Z fperez $"""
6 6
7 7 #*****************************************************************************
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 from IPython import Release
15 15 __author__ = '%s <%s>' % Release.authors['Fernando']
16 16 __license__ = Release.license
17 17 __version__ = Release.version
18 18
19 19 #****************************************************************************
20 20 # Required modules
21 21 import __builtin__
22 22 import os
23 23 import socket
24 24 import sys
25 25 import time
26 26 from pprint import pprint,pformat
27 27
28 28 # IPython's own
29 29 from IPython.genutils import *
30 30 from IPython.Struct import Struct
31 31 from IPython.Magic import Macro
32 32 from IPython.Itpl import ItplNS
33 33 from IPython import ColorANSI
34 34
35 35 #****************************************************************************
36 36 #Color schemes for Prompts.
37 37
38 38 PromptColors = ColorANSI.ColorSchemeTable()
39 39 InputColors = ColorANSI.InputTermColors # just a shorthand
40 40 Colors = ColorANSI.TermColors # just a shorthand
41 41
42 42 PromptColors.add_scheme(ColorANSI.ColorScheme(
43 43 'NoColor',
44 44 in_prompt = InputColors.NoColor, # Input prompt
45 45 in_number = InputColors.NoColor, # Input prompt number
46 46 in_prompt2 = InputColors.NoColor, # Continuation prompt
47 47 in_normal = InputColors.NoColor, # color off (usu. Colors.Normal)
48 48
49 49 out_prompt = Colors.NoColor, # Output prompt
50 50 out_number = Colors.NoColor, # Output prompt number
51 51
52 52 normal = Colors.NoColor # color off (usu. Colors.Normal)
53 53 ))
54 54
55 55 # make some schemes as instances so we can copy them for modification easily:
56 56 __PColLinux = ColorANSI.ColorScheme(
57 57 'Linux',
58 58 in_prompt = InputColors.Green,
59 59 in_number = InputColors.LightGreen,
60 60 in_prompt2 = InputColors.Green,
61 61 in_normal = InputColors.Normal, # color off (usu. Colors.Normal)
62 62
63 63 out_prompt = Colors.Red,
64 64 out_number = Colors.LightRed,
65 65
66 66 normal = Colors.Normal
67 67 )
68 68 # Don't forget to enter it into the table!
69 69 PromptColors.add_scheme(__PColLinux)
70 70
71 71 # Slightly modified Linux for light backgrounds
72 72 __PColLightBG = __PColLinux.copy('LightBG')
73 73
74 74 __PColLightBG.colors.update(
75 75 in_prompt = InputColors.Blue,
76 76 in_number = InputColors.LightBlue,
77 77 in_prompt2 = InputColors.Blue
78 78 )
79 79 PromptColors.add_scheme(__PColLightBG)
80 80
81 81 del Colors,InputColors
82 82
83 83 #-----------------------------------------------------------------------------
84 84 def multiple_replace(dict, text):
85 85 """ Replace in 'text' all occurences of any key in the given
86 86 dictionary by its corresponding value. Returns the new string."""
87 87
88 88 # Function by Xavier Defrang, originally found at:
89 89 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81330
90 90
91 91 # Create a regular expression from the dictionary keys
92 92 regex = re.compile("(%s)" % "|".join(map(re.escape, dict.keys())))
93 93 # For each match, look-up corresponding value in dictionary
94 94 return regex.sub(lambda mo: dict[mo.string[mo.start():mo.end()]], text)
95 95
96 96 #-----------------------------------------------------------------------------
97 97 # Special characters that can be used in prompt templates, mainly bash-like
98 98
99 99 # If $HOME isn't defined (Windows), make it an absurd string so that it can
100 100 # never be expanded out into '~'. Basically anything which can never be a
101 101 # reasonable directory name will do, we just want the $HOME -> '~' operation
102 102 # to become a no-op. We pre-compute $HOME here so it's not done on every
103 103 # prompt call.
104 104
105 105 # FIXME:
106 106
107 107 # - This should be turned into a class which does proper namespace management,
108 108 # since the prompt specials need to be evaluated in a certain namespace.
109 109 # Currently it's just globals, which need to be managed manually by code
110 110 # below.
111 111
112 112 # - I also need to split up the color schemes from the prompt specials
113 113 # somehow. I don't have a clean design for that quite yet.
114 114
115 115 HOME = os.environ.get("HOME","//////:::::ZZZZZ,,,~~~")
116 116
117 117 # We precompute a few more strings here for the prompt_specials, which are
118 118 # fixed once ipython starts. This reduces the runtime overhead of computing
119 119 # prompt strings.
120 120 USER = os.environ.get("USER")
121 121 HOSTNAME = socket.gethostname()
122 122 HOSTNAME_SHORT = HOSTNAME.split(".")[0]
123 123 ROOT_SYMBOL = "$#"[os.name=='nt' or os.getuid()==0]
124 124
125 125 prompt_specials_color = {
126 126 # Prompt/history count
127 127 '%n' : '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}',
128 128 '\\#': '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}',
129 129 # Prompt/history count, with the actual digits replaced by dots. Used
130 130 # mainly in continuation prompts (prompt_in2)
131 131 '\\D': '${"."*len(str(self.cache.prompt_count))}',
132 132 # Current working directory
133 133 '\\w': '${os.getcwd()}',
134 134 # Current time
135 135 '\\t' : '${time.strftime("%H:%M:%S")}',
136 136 # Basename of current working directory.
137 137 # (use os.sep to make this portable across OSes)
138 138 '\\W' : '${os.getcwd().split("%s")[-1]}' % os.sep,
139 139 # These X<N> are an extension to the normal bash prompts. They return
140 140 # N terms of the path, after replacing $HOME with '~'
141 141 '\\X0': '${os.getcwd().replace("%s","~")}' % HOME,
142 142 '\\X1': '${self.cwd_filt(1)}',
143 143 '\\X2': '${self.cwd_filt(2)}',
144 144 '\\X3': '${self.cwd_filt(3)}',
145 145 '\\X4': '${self.cwd_filt(4)}',
146 146 '\\X5': '${self.cwd_filt(5)}',
147 147 # Y<N> are similar to X<N>, but they show '~' if it's the directory
148 148 # N+1 in the list. Somewhat like %cN in tcsh.
149 149 '\\Y0': '${self.cwd_filt2(0)}',
150 150 '\\Y1': '${self.cwd_filt2(1)}',
151 151 '\\Y2': '${self.cwd_filt2(2)}',
152 152 '\\Y3': '${self.cwd_filt2(3)}',
153 153 '\\Y4': '${self.cwd_filt2(4)}',
154 154 '\\Y5': '${self.cwd_filt2(5)}',
155 155 # Hostname up to first .
156 156 '\\h': HOSTNAME_SHORT,
157 157 # Full hostname
158 158 '\\H': HOSTNAME,
159 159 # Username of current user
160 160 '\\u': USER,
161 161 # Escaped '\'
162 162 '\\\\': '\\',
163 163 # Newline
164 164 '\\n': '\n',
165 165 # Carriage return
166 166 '\\r': '\r',
167 167 # Release version
168 168 '\\v': __version__,
169 169 # Root symbol ($ or #)
170 170 '\\$': ROOT_SYMBOL,
171 171 }
172 172
173 173 # A copy of the prompt_specials dictionary but with all color escapes removed,
174 174 # so we can correctly compute the prompt length for the auto_rewrite method.
175 175 prompt_specials_nocolor = prompt_specials_color.copy()
176 176 prompt_specials_nocolor['%n'] = '${self.cache.prompt_count}'
177 177 prompt_specials_nocolor['\\#'] = '${self.cache.prompt_count}'
178 178
179 179 # Add in all the InputTermColors color escapes as valid prompt characters.
180 180 # They all get added as \\C_COLORNAME, so that we don't have any conflicts
181 181 # with a color name which may begin with a letter used by any other of the
182 182 # allowed specials. This of course means that \\C will never be allowed for
183 183 # anything else.
184 184 input_colors = ColorANSI.InputTermColors
185 185 for _color in dir(input_colors):
186 186 if _color[0] != '_':
187 187 c_name = '\\C_'+_color
188 188 prompt_specials_color[c_name] = getattr(input_colors,_color)
189 189 prompt_specials_nocolor[c_name] = ''
190 190
191 191 # we default to no color for safety. Note that prompt_specials is a global
192 192 # variable used by all prompt objects.
193 193 prompt_specials = prompt_specials_nocolor
194 194
195 195 #-----------------------------------------------------------------------------
196 196 def str_safe(arg):
197 197 """Convert to a string, without ever raising an exception.
198 198
199 199 If str(arg) fails, <ERROR: ... > is returned, where ... is the exception
200 200 error message."""
201 201
202 202 try:
203 203 out = str(arg)
204 204 except UnicodeError:
205 205 try:
206 206 out = arg.encode('utf_8','replace')
207 207 except Exception,msg:
208 208 # let's keep this little duplication here, so that the most common
209 209 # case doesn't suffer from a double try wrapping.
210 210 out = '<ERROR: %s>' % msg
211 211 except Exception,msg:
212 212 out = '<ERROR: %s>' % msg
213 213 return out
214 214
215 215 class BasePrompt:
216 216 """Interactive prompt similar to Mathematica's."""
217 217 def __init__(self,cache,sep,prompt,pad_left=False):
218 218
219 219 # Hack: we access information about the primary prompt through the
220 220 # cache argument. We need this, because we want the secondary prompt
221 221 # to be aligned with the primary one. Color table info is also shared
222 222 # by all prompt classes through the cache. Nice OO spaghetti code!
223 223 self.cache = cache
224 224 self.sep = sep
225 225
226 226 # regexp to count the number of spaces at the end of a prompt
227 227 # expression, useful for prompt auto-rewriting
228 228 self.rspace = re.compile(r'(\s*)$')
229 229 # Flag to left-pad prompt strings to match the length of the primary
230 230 # prompt
231 231 self.pad_left = pad_left
232 232 # Set template to create each actual prompt (where numbers change)
233 233 self.p_template = prompt
234 234 self.set_p_str()
235 235
236 236 def set_p_str(self):
237 237 """ Set the interpolating prompt strings.
238 238
239 239 This must be called every time the color settings change, because the
240 240 prompt_specials global may have changed."""
241 241
242 242 import os,time # needed in locals for prompt string handling
243 243 loc = locals()
244 244 self.p_str = ItplNS('%s%s%s' %
245 245 ('${self.sep}${self.col_p}',
246 246 multiple_replace(prompt_specials, self.p_template),
247 247 '${self.col_norm}'),self.cache.user_ns,loc)
248 248
249 249 self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor,
250 250 self.p_template),
251 251 self.cache.user_ns,loc)
252 252
253 253 def write(self,msg): # dbg
254 254 sys.stdout.write(msg)
255 255 return ''
256 256
257 257 def __str__(self):
258 258 """Return a string form of the prompt.
259 259
260 260 This for is useful for continuation and output prompts, since it is
261 261 left-padded to match lengths with the primary one (if the
262 262 self.pad_left attribute is set)."""
263 263
264 264 out_str = str_safe(self.p_str)
265 265 if self.pad_left:
266 266 # We must find the amount of padding required to match lengths,
267 267 # taking the color escapes (which are invisible on-screen) into
268 268 # account.
269 269 esc_pad = len(out_str) - len(str_safe(self.p_str_nocolor))
270 270 format = '%%%ss' % (len(str(self.cache.last_prompt))+esc_pad)
271 271 return format % out_str
272 272 else:
273 273 return out_str
274 274
275 275 # these path filters are put in as methods so that we can control the
276 276 # namespace where the prompt strings get evaluated
277 277 def cwd_filt(self,depth):
278 278 """Return the last depth elements of the current working directory.
279 279
280 280 $HOME is always replaced with '~'.
281 281 If depth==0, the full path is returned."""
282 282
283 283 cwd = os.getcwd().replace(HOME,"~")
284 284 out = os.sep.join(cwd.split(os.sep)[-depth:])
285 285 if out:
286 286 return out
287 287 else:
288 288 return os.sep
289 289
290 290 def cwd_filt2(self,depth):
291 291 """Return the last depth elements of the current working directory.
292 292
293 293 $HOME is always replaced with '~'.
294 294 If depth==0, the full path is returned."""
295 295
296 296 cwd = os.getcwd().replace(HOME,"~").split(os.sep)
297 297 if '~' in cwd and len(cwd) == depth+1:
298 298 depth += 1
299 299 out = os.sep.join(cwd[-depth:])
300 300 if out:
301 301 return out
302 302 else:
303 303 return os.sep
304 304
305 305 class Prompt1(BasePrompt):
306 306 """Input interactive prompt similar to Mathematica's."""
307 307
308 308 def __init__(self,cache,sep='\n',prompt='In [\\#]: ',pad_left=True):
309 309 BasePrompt.__init__(self,cache,sep,prompt,pad_left)
310 310
311 311 def set_colors(self):
312 312 self.set_p_str()
313 313 Colors = self.cache.color_table.active_colors # shorthand
314 314 self.col_p = Colors.in_prompt
315 315 self.col_num = Colors.in_number
316 316 self.col_norm = Colors.in_normal
317 317 # We need a non-input version of these escapes for the '--->'
318 318 # auto-call prompts used in the auto_rewrite() method.
319 319 self.col_p_ni = self.col_p.replace('\001','').replace('\002','')
320 320 self.col_norm_ni = Colors.normal
321 321
322 322 def __str__(self):
323 323 self.cache.prompt_count += 1
324 324 self.cache.last_prompt = str_safe(self.p_str_nocolor).split('\n')[-1]
325 325 return str_safe(self.p_str)
326 326
327 327 def auto_rewrite(self):
328 328 """Print a string of the form '--->' which lines up with the previous
329 329 input string. Useful for systems which re-write the user input when
330 330 handling automatically special syntaxes."""
331 331
332 332 curr = str(self.cache.last_prompt)
333 333 nrspaces = len(self.rspace.search(curr).group())
334 334 return '%s%s>%s%s' % (self.col_p_ni,'-'*(len(curr)-nrspaces-1),
335 335 ' '*nrspaces,self.col_norm_ni)
336 336
337 337 class PromptOut(BasePrompt):
338 338 """Output interactive prompt similar to Mathematica's."""
339 339
340 340 def __init__(self,cache,sep='',prompt='Out[\\#]: ',pad_left=True):
341 341 BasePrompt.__init__(self,cache,sep,prompt,pad_left)
342 342 if not self.p_template:
343 343 self.__str__ = lambda: ''
344 344
345 345 def set_colors(self):
346 346 self.set_p_str()
347 347 Colors = self.cache.color_table.active_colors # shorthand
348 348 self.col_p = Colors.out_prompt
349 349 self.col_num = Colors.out_number
350 350 self.col_norm = Colors.normal
351 351
352 352 class Prompt2(BasePrompt):
353 353 """Interactive continuation prompt."""
354 354
355 355 def __init__(self,cache,prompt=' .\\D.: ',pad_left=True):
356 356 self.cache = cache
357 357 self.p_template = prompt
358 358 self.pad_left = pad_left
359 359 self.set_p_str()
360 360
361 361 def set_p_str(self):
362 362 import os,time # needed in locals for prompt string handling
363 363 loc = locals()
364 364 self.p_str = ItplNS('%s%s%s' %
365 365 ('${self.col_p2}',
366 366 multiple_replace(prompt_specials, self.p_template),
367 367 '$self.col_norm'),
368 368 self.cache.user_ns,loc)
369 369 self.p_str_nocolor = ItplNS(multiple_replace(prompt_specials_nocolor,
370 370 self.p_template),
371 371 self.cache.user_ns,loc)
372 372
373 373 def set_colors(self):
374 374 self.set_p_str()
375 375 Colors = self.cache.color_table.active_colors
376 376 self.col_p2 = Colors.in_prompt2
377 377 self.col_norm = Colors.in_normal
378 378 # FIXME (2004-06-16) HACK: prevent crashes for users who haven't
379 379 # updated their prompt_in2 definitions. Remove eventually.
380 380 self.col_p = Colors.out_prompt
381 381 self.col_num = Colors.out_number
382 382
383 383 #-----------------------------------------------------------------------------
384 384 class CachedOutput:
385 385 """Class for printing output from calculations while keeping a cache of
386 386 reults. It dynamically creates global variables prefixed with _ which
387 387 contain these results.
388 388
389 389 Meant to be used as a sys.displayhook replacement, providing numbered
390 390 prompts and cache services.
391 391
392 392 Initialize with initial and final values for cache counter (this defines
393 393 the maximum size of the cache."""
394 394
395 def __init__(self,cache_size,Pprint,colors='NoColor',input_sep='\n',
396 output_sep='\n',output_sep2='',user_ns={},
397 ps1 = None, ps2 = None,ps_out = None,
398 input_hist = None,pad_left=True):
395 def __init__(self,shell,cache_size,Pprint,
396 colors='NoColor',input_sep='\n',
397 output_sep='\n',output_sep2='',
398 ps1 = None, ps2 = None,ps_out = None,pad_left=True):
399 399
400 400 cache_size_min = 20
401 401 if cache_size <= 0:
402 402 self.do_full_cache = 0
403 403 cache_size = 0
404 404 elif cache_size < cache_size_min:
405 405 self.do_full_cache = 0
406 406 cache_size = 0
407 407 warn('caching was disabled (min value for cache size is %s).' %
408 408 cache_size_min,level=3)
409 409 else:
410 410 self.do_full_cache = 1
411 411
412 412 self.cache_size = cache_size
413 413 self.input_sep = input_sep
414 414
415 415 # we need a reference to the user-level namespace
416 self.user_ns = user_ns
416 self.shell = shell
417 self.user_ns = shell.user_ns
417 418 # and to the user's input
418 self.input_hist = input_hist
419 self.input_hist = shell.input_hist
420 # and to the user's logger, for logging output
421 self.logger = shell.logger
419 422
420 423 # Set input prompt strings and colors
421 424 if cache_size == 0:
422 425 if ps1.find('%n') > -1 or ps1.find('\\#') > -1: ps1 = '>>> '
423 426 if ps2.find('%n') > -1 or ps2.find('\\#') > -1: ps2 = '... '
424 427 self.ps1_str = self._set_prompt_str(ps1,'In [\\#]: ','>>> ')
425 428 self.ps2_str = self._set_prompt_str(ps2,' .\\D.: ','... ')
426 429 self.ps_out_str = self._set_prompt_str(ps_out,'Out[\\#]: ','')
427 430
428 431 self.color_table = PromptColors
429 432 self.prompt1 = Prompt1(self,sep=input_sep,prompt=self.ps1_str,
430 433 pad_left=pad_left)
431 434 self.prompt2 = Prompt2(self,prompt=self.ps2_str,pad_left=pad_left)
432 435 self.prompt_out = PromptOut(self,sep='',prompt=self.ps_out_str,
433 436 pad_left=pad_left)
434 437 self.set_colors(colors)
435 438
436 439 # other more normal stuff
437 440 # b/c each call to the In[] prompt raises it by 1, even the first.
438 441 self.prompt_count = 0
439 442 self.cache_count = 1
440 443 # Store the last prompt string each time, we need it for aligning
441 444 # continuation and auto-rewrite prompts
442 445 self.last_prompt = ''
443 446 self.entries = [None] # output counter starts at 1 for the user
444 447 self.Pprint = Pprint
445 448 self.output_sep = output_sep
446 449 self.output_sep2 = output_sep2
447 450 self._,self.__,self.___ = '','',''
448 451 self.pprint_types = map(type,[(),[],{}])
449 452
450 453 # these are deliberately global:
451 454 to_user_ns = {'_':self._,'__':self.__,'___':self.___}
452 455 self.user_ns.update(to_user_ns)
453 456
454 457 def _set_prompt_str(self,p_str,cache_def,no_cache_def):
455 458 if p_str is None:
456 459 if self.do_full_cache:
457 460 return cache_def
458 461 else:
459 462 return no_cache_def
460 463 else:
461 464 return p_str
462 465
463 466 def set_colors(self,colors):
464 467 """Set the active color scheme and configure colors for the three
465 468 prompt subsystems."""
466 469
467 470 # FIXME: the prompt_specials global should be gobbled inside this
468 471 # class instead. Do it when cleaning up the whole 3-prompt system.
469 472 global prompt_specials
470 473 if colors.lower()=='nocolor':
471 474 prompt_specials = prompt_specials_nocolor
472 475 else:
473 476 prompt_specials = prompt_specials_color
474 477
475 478 self.color_table.set_active_scheme(colors)
476 479 self.prompt1.set_colors()
477 480 self.prompt2.set_colors()
478 481 self.prompt_out.set_colors()
479 482
480 483 def __call__(self,arg=None):
481 484 """Printing with history cache management.
482 485
483 486 This is invoked everytime the interpreter needs to print, and is
484 487 activated by setting the variable sys.displayhook to it."""
485 488
486 489 # If something injected a '_' variable in __builtin__, delete
487 490 # ipython's automatic one so we don't clobber that. gettext() in
488 491 # particular uses _, so we need to stay away from it.
489 492 if '_' in __builtin__.__dict__:
490 493 try:
491 494 del self.user_ns['_']
492 495 except KeyError:
493 496 pass
494 497 if arg is not None:
495 498 cout_write = Term.cout.write # fast lookup
496 499 # first handle the cache and counters
497 500 # but avoid recursive reference when displaying _oh/Out
498 501 if arg is not self.user_ns['_oh']:
499 502 self.update(arg)
500 503 # do not print output if input ends in ';'
501 504 if self.input_hist[self.prompt_count].endswith(';\n'):
502 505 return
503 506 # don't use print, puts an extra space
504 507 cout_write(self.output_sep)
505 508 if self.do_full_cache:
506 509 cout_write(str(self.prompt_out))
507 510
508 511 if isinstance(arg,Macro):
509 512 print 'Executing Macro...'
510 513 # in case the macro takes a long time to execute
511 514 Term.cout.flush()
512 exec arg.value in self.user_ns
515 self.shell.runlines(arg.value)
513 516 return None
514 517
515 518 # and now call a possibly user-defined print mechanism
516 519 self.display(arg)
520 if self.logger.log_output:
521 self.logger.log_write(repr(arg),'output')
517 522 cout_write(self.output_sep2)
518 523 Term.cout.flush()
519 524
520 525 def _display(self,arg):
521 526 """Default printer method, uses pprint.
522 527
523 528 This can be over-ridden by the users to implement special formatting
524 529 of certain types of output."""
525 530
526 531 if self.Pprint:
527 532 out = pformat(arg)
528 533 if '\n' in out:
529 534 # So that multi-line strings line up with the left column of
530 535 # the screen, instead of having the output prompt mess up
531 536 # their first line.
532 537 Term.cout.write('\n')
533 538 print >>Term.cout, out
534 539 else:
535 540 print >>Term.cout, arg
536 541
537 542 # Assign the default display method:
538 543 display = _display
539 544
540 545 def update(self,arg):
541 546 #print '***cache_count', self.cache_count # dbg
542 547 if self.cache_count >= self.cache_size and self.do_full_cache:
543 548 self.flush()
544 549 # Don't overwrite '_' and friends if '_' is in __builtin__ (otherwise
545 550 # we cause buggy behavior for things like gettext).
546 551 if '_' not in __builtin__.__dict__:
547 552 self.___ = self.__
548 553 self.__ = self._
549 554 self._ = arg
550 555 self.user_ns.update({'_':self._,'__':self.__,'___':self.___})
551 556
552 557 # hackish access to top-level namespace to create _1,_2... dynamically
553 558 to_main = {}
554 559 if self.do_full_cache:
555 560 self.cache_count += 1
556 561 self.entries.append(arg)
557 562 new_result = '_'+`self.prompt_count`
558 563 to_main[new_result] = self.entries[-1]
559 564 self.user_ns.update(to_main)
560 565 self.user_ns['_oh'][self.prompt_count] = arg
561 566
562 567 def flush(self):
563 568 if not self.do_full_cache:
564 569 raise ValueError,"You shouldn't have reached the cache flush "\
565 570 "if full caching is not enabled!"
566 571 warn('Output cache limit (currently '+\
567 572 `self.cache_count`+' entries) hit.\n'
568 573 'Flushing cache and resetting history counter...\n'
569 574 'The only history variables available will be _,__,___ and _1\n'
570 575 'with the current result.')
571 576 # delete auto-generated vars from global namespace
572 577 for n in range(1,self.prompt_count + 1):
573 578 key = '_'+`n`
574 579 try:
575 580 del self.user_ns[key]
576 581 except: pass
577 582 self.prompt_count = 1
578 583 self.cache_count = 1
@@ -1,1997 +1,2060 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 965 2005-12-28 23:23:09Z fperez $
9 $Id: iplib.py 966 2005-12-29 08:34:07Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
13 13 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
14 14 # Copyright (C) 2001-2005 Fernando Perez. <fperez@colorado.edu>
15 15 #
16 16 # Distributed under the terms of the BSD License. The full license is in
17 17 # the file COPYING, distributed as part of this software.
18 18 #
19 19 # Note: this code originally subclassed code.InteractiveConsole from the
20 20 # Python standard library. Over time, all of that class has been copied
21 21 # verbatim here for modifications which could not be accomplished by
22 22 # subclassing. At this point, there are no dependencies at all on the code
23 23 # module anymore (it is not even imported). The Python License (sec. 2)
24 24 # allows for this, but it's always nice to acknowledge credit where credit is
25 25 # due.
26 26 #*****************************************************************************
27 27
28 28 #****************************************************************************
29 29 # Modules and globals
30 30
31 31 from __future__ import generators # for 2.2 backwards-compatibility
32 32
33 33 from IPython import Release
34 34 __author__ = '%s <%s>\n%s <%s>' % \
35 35 ( Release.authors['Janko'] + Release.authors['Fernando'] )
36 36 __license__ = Release.license
37 37 __version__ = Release.version
38 38
39 39 # Python standard modules
40 40 import __main__
41 41 import __builtin__
42 42 import StringIO
43 43 import bdb
44 44 import cPickle as pickle
45 45 import codeop
46 46 import exceptions
47 47 import glob
48 48 import inspect
49 49 import keyword
50 50 import new
51 51 import os
52 52 import pdb
53 53 import pydoc
54 54 import re
55 55 import shutil
56 56 import string
57 57 import sys
58 58 import traceback
59 59 import types
60 60
61 61 from pprint import pprint, pformat
62 62
63 63 # IPython's own modules
64 64 import IPython
65 65 from IPython import OInspect,PyColorize,ultraTB
66 66 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
67 67 from IPython.FakeModule import FakeModule
68 68 from IPython.Itpl import Itpl,itpl,printpl,ItplNS,itplns
69 69 from IPython.Logger import Logger
70 from IPython.Magic import Magic,magic2python
70 from IPython.Magic import Magic
71 from IPython.Prompts import CachedOutput
71 72 from IPython.Struct import Struct
72 73 from IPython.background_jobs import BackgroundJobManager
73 74 from IPython.usage import cmd_line_usage,interactive_usage
74 75 from IPython.genutils import *
75 76
76 77 # store the builtin raw_input globally, and use this always, in case user code
77 78 # overwrites it (like wx.py.PyShell does)
78 79 raw_input_original = raw_input
79 80
80 81 #****************************************************************************
81 82 # Some utility function definitions
82 83
83 84 # This can be replaced with an isspace() call once we drop 2.2 compatibility
84 85 _isspace_match = re.compile(r'^\s+$').match
85 86 def isspace(s):
86 87 return bool(_isspace_match(s))
87 88
88 89 def esc_quotes(strng):
89 90 """Return the input string with single and double quotes escaped out"""
90 91
91 92 return strng.replace('"','\\"').replace("'","\\'")
92 93
93 94 def import_fail_info(mod_name,fns=None):
94 95 """Inform load failure for a module."""
95 96
96 97 if fns == None:
97 98 warn("Loading of %s failed.\n" % (mod_name,))
98 99 else:
99 100 warn("Loading of %s from %s failed.\n" % (fns,mod_name))
100 101
101 102 def qw_lol(indata):
102 103 """qw_lol('a b') -> [['a','b']],
103 104 otherwise it's just a call to qw().
104 105
105 106 We need this to make sure the modules_some keys *always* end up as a
106 107 list of lists."""
107 108
108 109 if type(indata) in StringTypes:
109 110 return [qw(indata)]
110 111 else:
111 112 return qw(indata)
112 113
113 114 def ipmagic(arg_s):
114 115 """Call a magic function by name.
115 116
116 117 Input: a string containing the name of the magic function to call and any
117 118 additional arguments to be passed to the magic.
118 119
119 120 ipmagic('name -opt foo bar') is equivalent to typing at the ipython
120 121 prompt:
121 122
122 123 In[1]: %name -opt foo bar
123 124
124 125 To call a magic without arguments, simply use ipmagic('name').
125 126
126 127 This provides a proper Python function to call IPython's magics in any
127 128 valid Python code you can type at the interpreter, including loops and
128 129 compound statements. It is added by IPython to the Python builtin
129 130 namespace upon initialization."""
130 131
131 132 args = arg_s.split(' ',1)
132 133 magic_name = args[0]
133 134 if magic_name.startswith(__IPYTHON__.ESC_MAGIC):
134 135 magic_name = magic_name[1:]
135 136 try:
136 137 magic_args = args[1]
137 138 except IndexError:
138 139 magic_args = ''
139 140 fn = getattr(__IPYTHON__,'magic_'+magic_name,None)
140 141 if fn is None:
141 142 error("Magic function `%s` not found." % magic_name)
142 143 else:
143 144 magic_args = __IPYTHON__.var_expand(magic_args)
144 145 return fn(magic_args)
145 146
146 147 def ipalias(arg_s):
147 148 """Call an alias by name.
148 149
149 150 Input: a string containing the name of the alias to call and any
150 151 additional arguments to be passed to the magic.
151 152
152 153 ipalias('name -opt foo bar') is equivalent to typing at the ipython
153 154 prompt:
154 155
155 156 In[1]: name -opt foo bar
156 157
157 158 To call an alias without arguments, simply use ipalias('name').
158 159
159 160 This provides a proper Python function to call IPython's aliases in any
160 161 valid Python code you can type at the interpreter, including loops and
161 162 compound statements. It is added by IPython to the Python builtin
162 163 namespace upon initialization."""
163 164
164 165 args = arg_s.split(' ',1)
165 166 alias_name = args[0]
166 167 try:
167 168 alias_args = args[1]
168 169 except IndexError:
169 170 alias_args = ''
170 171 if alias_name in __IPYTHON__.alias_table:
171 172 __IPYTHON__.call_alias(alias_name,alias_args)
172 173 else:
173 174 error("Alias `%s` not found." % alias_name)
174 175
175 176 def softspace(file, newvalue):
176 177 """Copied from code.py, to remove the dependency"""
177 178 oldvalue = 0
178 179 try:
179 180 oldvalue = file.softspace
180 181 except AttributeError:
181 182 pass
182 183 try:
183 184 file.softspace = newvalue
184 185 except (AttributeError, TypeError):
185 186 # "attribute-less object" or "read-only attributes"
186 187 pass
187 188 return oldvalue
188 189
189 190
190 191 #****************************************************************************
191 192 # Local use exceptions
192 193 class SpaceInInput(exceptions.Exception): pass
193 194
194 195 #****************************************************************************
195 196 # Local use classes
196 197 class Bunch: pass
197 198
198 199 class InputList(list):
199 200 """Class to store user input.
200 201
201 202 It's basically a list, but slices return a string instead of a list, thus
202 203 allowing things like (assuming 'In' is an instance):
203 204
204 205 exec In[4:7]
205 206
206 207 or
207 208
208 209 exec In[5:9] + In[14] + In[21:25]"""
209 210
210 211 def __getslice__(self,i,j):
211 212 return ''.join(list.__getslice__(self,i,j))
212 213
213 214 class SyntaxTB(ultraTB.ListTB):
214 215 """Extension which holds some state: the last exception value"""
215 216
216 217 def __init__(self,color_scheme = 'NoColor'):
217 218 ultraTB.ListTB.__init__(self,color_scheme)
218 219 self.last_syntax_error = None
219 220
220 221 def __call__(self, etype, value, elist):
221 222 self.last_syntax_error = value
222 223 ultraTB.ListTB.__call__(self,etype,value,elist)
223 224
224 225 def clear_err_state(self):
225 226 """Return the current error state and clear it"""
226 227 e = self.last_syntax_error
227 228 self.last_syntax_error = None
228 229 return e
229 230
230 231 #****************************************************************************
231 232 # Main IPython class
232 class InteractiveShell(Logger, Magic):
233
234 # FIXME: the Magic class is a mixin for now, and will unfortunately remain so
235 # until a full rewrite is made. I've cleaned all cross-class uses of
236 # attributes and methods, but too much user code out there relies on the
237 # equlity %foo == __IP.magic_foo, so I can't actually remove the mixin usage.
238 #
239 # But at least now, all the pieces have been separated and we could, in
240 # principle, stop using the mixin. This will ease the transition to the
241 # chainsaw branch.
242
243 # For reference, the following is the list of 'self.foo' uses in the Magic
244 # class as of 2005-12-28. These are names we CAN'T use in the main ipython
245 # class, to prevent clashes.
246
247 # ['self.__class__', 'self.__dict__', 'self._inspect', 'self._ofind',
248 # 'self.arg_err', 'self.extract_input', 'self.format_', 'self.lsmagic',
249 # 'self.magic_', 'self.options_table', 'self.parse', 'self.shell',
250 # 'self.value']
251
252
253 class InteractiveShell(Magic):
233 254 """An enhanced console for Python."""
234 255
235 256 # class attribute to indicate whether the class supports threads or not.
236 257 # Subclasses with thread support should override this as needed.
237 258 isthreaded = False
238 259
239 260 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
240 261 user_ns = None,user_global_ns=None,banner2='',
241 262 custom_exceptions=((),None),embedded=False):
242 263
243 264 # some minimal strict typechecks. For some core data structures, I
244 265 # want actual basic python types, not just anything that looks like
245 266 # one. This is especially true for namespaces.
246 267 for ns in (user_ns,user_global_ns):
247 268 if ns is not None and type(ns) != types.DictType:
248 269 raise TypeError,'namespace must be a dictionary'
249 270
250 271 # Put a reference to self in builtins so that any form of embedded or
251 272 # imported code can test for being inside IPython.
252 273 __builtin__.__IPYTHON__ = self
253 274
254 275 # And load into builtins ipmagic/ipalias as well
255 276 __builtin__.ipmagic = ipmagic
256 277 __builtin__.ipalias = ipalias
257 278
258 279 # Add to __builtin__ other parts of IPython's public API
259 280 __builtin__.ip_set_hook = self.set_hook
260 281
261 282 # Keep in the builtins a flag for when IPython is active. We set it
262 283 # with setdefault so that multiple nested IPythons don't clobber one
263 284 # another. Each will increase its value by one upon being activated,
264 285 # which also gives us a way to determine the nesting level.
265 286 __builtin__.__dict__.setdefault('__IPYTHON__active',0)
266 287
267 288 # Do the intuitively correct thing for quit/exit: we remove the
268 289 # builtins if they exist, and our own prefilter routine will handle
269 290 # these special cases
270 291 try:
271 292 del __builtin__.exit, __builtin__.quit
272 293 except AttributeError:
273 294 pass
274 295
275 296 # Store the actual shell's name
276 297 self.name = name
277 298
278 299 # We need to know whether the instance is meant for embedding, since
279 300 # global/local namespaces need to be handled differently in that case
280 301 self.embedded = embedded
281 302
282 303 # command compiler
283 304 self.compile = codeop.CommandCompiler()
284 305
285 306 # User input buffer
286 307 self.buffer = []
287 308
288 309 # Default name given in compilation of code
289 310 self.filename = '<ipython console>'
290 311
291 312 # Create the namespace where the user will operate. user_ns is
292 313 # normally the only one used, and it is passed to the exec calls as
293 314 # the locals argument. But we do carry a user_global_ns namespace
294 315 # given as the exec 'globals' argument, This is useful in embedding
295 316 # situations where the ipython shell opens in a context where the
296 317 # distinction between locals and globals is meaningful.
297 318
298 319 # FIXME. For some strange reason, __builtins__ is showing up at user
299 320 # level as a dict instead of a module. This is a manual fix, but I
300 321 # should really track down where the problem is coming from. Alex
301 322 # Schmolck reported this problem first.
302 323
303 324 # A useful post by Alex Martelli on this topic:
304 325 # Re: inconsistent value from __builtins__
305 326 # Von: Alex Martelli <aleaxit@yahoo.com>
306 327 # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends
307 328 # Gruppen: comp.lang.python
308 # Referenzen: 1
309 329
310 330 # Michael Hohn <hohn@hooknose.lbl.gov> wrote:
311 331 # > >>> print type(builtin_check.get_global_binding('__builtins__'))
312 332 # > <type 'dict'>
313 333 # > >>> print type(__builtins__)
314 334 # > <type 'module'>
315 335 # > Is this difference in return value intentional?
316 336
317 337 # Well, it's documented that '__builtins__' can be either a dictionary
318 338 # or a module, and it's been that way for a long time. Whether it's
319 339 # intentional (or sensible), I don't know. In any case, the idea is
320 340 # that if you need to access the built-in namespace directly, you
321 341 # should start with "import __builtin__" (note, no 's') which will
322 342 # definitely give you a module. Yeah, it's somewhat confusing:-(.
323 343
324 344 if user_ns is None:
325 345 # Set __name__ to __main__ to better match the behavior of the
326 346 # normal interpreter.
327 347 user_ns = {'__name__' :'__main__',
328 348 '__builtins__' : __builtin__,
329 349 }
330 350
331 351 if user_global_ns is None:
332 352 user_global_ns = {}
333 353
334 354 # Assign namespaces
335 355 # This is the namespace where all normal user variables live
336 356 self.user_ns = user_ns
337 357 # Embedded instances require a separate namespace for globals.
338 358 # Normally this one is unused by non-embedded instances.
339 359 self.user_global_ns = user_global_ns
340 360 # A namespace to keep track of internal data structures to prevent
341 361 # them from cluttering user-visible stuff. Will be updated later
342 362 self.internal_ns = {}
343 363
344 364 # Namespace of system aliases. Each entry in the alias
345 365 # table must be a 2-tuple of the form (N,name), where N is the number
346 366 # of positional arguments of the alias.
347 367 self.alias_table = {}
348 368
349 369 # A table holding all the namespaces IPython deals with, so that
350 370 # introspection facilities can search easily.
351 371 self.ns_table = {'user':user_ns,
352 372 'user_global':user_global_ns,
353 373 'alias':self.alias_table,
354 374 'internal':self.internal_ns,
355 375 'builtin':__builtin__.__dict__
356 376 }
357 377
358 378 # The user namespace MUST have a pointer to the shell itself.
359 379 self.user_ns[name] = self
360 380
361 381 # We need to insert into sys.modules something that looks like a
362 382 # module but which accesses the IPython namespace, for shelve and
363 383 # pickle to work interactively. Normally they rely on getting
364 384 # everything out of __main__, but for embedding purposes each IPython
365 385 # instance has its own private namespace, so we can't go shoving
366 386 # everything into __main__.
367 387
368 388 # note, however, that we should only do this for non-embedded
369 389 # ipythons, which really mimic the __main__.__dict__ with their own
370 390 # namespace. Embedded instances, on the other hand, should not do
371 391 # this because they need to manage the user local/global namespaces
372 392 # only, but they live within a 'normal' __main__ (meaning, they
373 393 # shouldn't overtake the execution environment of the script they're
374 394 # embedded in).
375 395
376 396 if not embedded:
377 397 try:
378 398 main_name = self.user_ns['__name__']
379 399 except KeyError:
380 400 raise KeyError,'user_ns dictionary MUST have a "__name__" key'
381 401 else:
382 402 #print "pickle hack in place" # dbg
383 403 sys.modules[main_name] = FakeModule(self.user_ns)
384 404
385 405 # List of input with multi-line handling.
386 406 # Fill its zero entry, user counter starts at 1
387 407 self.input_hist = InputList(['\n'])
388 408
389 409 # list of visited directories
390 410 try:
391 411 self.dir_hist = [os.getcwd()]
392 412 except IOError, e:
393 413 self.dir_hist = []
394 414
395 415 # dict of output history
396 416 self.output_hist = {}
397 417
398 418 # dict of things NOT to alias (keywords, builtins and some magics)
399 419 no_alias = {}
400 420 no_alias_magics = ['cd','popd','pushd','dhist','alias','unalias']
401 421 for key in keyword.kwlist + no_alias_magics:
402 422 no_alias[key] = 1
403 423 no_alias.update(__builtin__.__dict__)
404 424 self.no_alias = no_alias
405 425
406 426 # make global variables for user access to these
407 427 self.user_ns['_ih'] = self.input_hist
408 428 self.user_ns['_oh'] = self.output_hist
409 429 self.user_ns['_dh'] = self.dir_hist
410 430
411 431 # user aliases to input and output histories
412 432 self.user_ns['In'] = self.input_hist
413 433 self.user_ns['Out'] = self.output_hist
414 434
415 435 # Object variable to store code object waiting execution. This is
416 436 # used mainly by the multithreaded shells, but it can come in handy in
417 437 # other situations. No need to use a Queue here, since it's a single
418 438 # item which gets cleared once run.
419 439 self.code_to_run = None
420 440
421 441 # Job manager (for jobs run as background threads)
422 442 self.jobs = BackgroundJobManager()
423 443 # Put the job manager into builtins so it's always there.
424 444 __builtin__.jobs = self.jobs
425 445
426 446 # escapes for automatic behavior on the command line
427 447 self.ESC_SHELL = '!'
428 448 self.ESC_HELP = '?'
429 449 self.ESC_MAGIC = '%'
430 450 self.ESC_QUOTE = ','
431 451 self.ESC_QUOTE2 = ';'
432 452 self.ESC_PAREN = '/'
433 453
434 454 # And their associated handlers
435 self.esc_handlers = {self.ESC_PAREN:self.handle_auto,
436 self.ESC_QUOTE:self.handle_auto,
437 self.ESC_QUOTE2:self.handle_auto,
438 self.ESC_MAGIC:self.handle_magic,
439 self.ESC_HELP:self.handle_help,
440 self.ESC_SHELL:self.handle_shell_escape,
455 self.esc_handlers = {self.ESC_PAREN : self.handle_auto,
456 self.ESC_QUOTE : self.handle_auto,
457 self.ESC_QUOTE2 : self.handle_auto,
458 self.ESC_MAGIC : self.handle_magic,
459 self.ESC_HELP : self.handle_help,
460 self.ESC_SHELL : self.handle_shell_escape,
441 461 }
442 462
443 463 # class initializations
444 Logger.__init__(self,log_ns = self.user_ns)
445 464 Magic.__init__(self,self)
446 465
447 # an ugly hack to get a pointer to the shell, so I can start writing
448 # magic code via this pointer instead of the current mixin salad.
449 Magic.set_shell(self,self)
450
451 466 # Python source parser/formatter for syntax highlighting
452 467 pyformat = PyColorize.Parser().format
453 468 self.pycolorize = lambda src: pyformat(src,'str',self.rc['colors'])
454 469
455 470 # hooks holds pointers used for user-side customizations
456 471 self.hooks = Struct()
457 472
458 473 # Set all default hooks, defined in the IPython.hooks module.
459 474 hooks = IPython.hooks
460 475 for hook_name in hooks.__all__:
461 476 self.set_hook(hook_name,getattr(hooks,hook_name))
462 477
463 478 # Flag to mark unconditional exit
464 479 self.exit_now = False
465 480
466 481 self.usage_min = """\
467 482 An enhanced console for Python.
468 483 Some of its features are:
469 484 - Readline support if the readline library is present.
470 485 - Tab completion in the local namespace.
471 486 - Logging of input, see command-line options.
472 487 - System shell escape via ! , eg !ls.
473 488 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
474 489 - Keeps track of locally defined variables via %who, %whos.
475 490 - Show object information with a ? eg ?x or x? (use ?? for more info).
476 491 """
477 492 if usage: self.usage = usage
478 493 else: self.usage = self.usage_min
479 494
480 495 # Storage
481 496 self.rc = rc # This will hold all configuration information
482 497 self.inputcache = []
483 498 self._boundcache = []
484 499 self.pager = 'less'
485 500 # temporary files used for various purposes. Deleted at exit.
486 501 self.tempfiles = []
487 502
488 503 # Keep track of readline usage (later set by init_readline)
489 504 self.has_readline = False
490 505
506 # template for logfile headers. It gets resolved at runtime by the
507 # logstart method.
508 self.loghead_tpl = \
509 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
510 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
511 #log# opts = %s
512 #log# args = %s
513 #log# It is safe to make manual edits below here.
514 #log#-----------------------------------------------------------------------
515 """
491 516 # for pushd/popd management
492 517 try:
493 518 self.home_dir = get_home_dir()
494 519 except HomeDirError,msg:
495 520 fatal(msg)
496 521
497 522 self.dir_stack = [os.getcwd().replace(self.home_dir,'~')]
498 523
499 524 # Functions to call the underlying shell.
500 525
501 526 # utility to expand user variables via Itpl
502 527 self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'),
503 528 self.user_ns))
504 529 # The first is similar to os.system, but it doesn't return a value,
505 530 # and it allows interpolation of variables in the user's namespace.
506 531 self.system = lambda cmd: shell(self.var_expand(cmd),
507 532 header='IPython system call: ',
508 533 verbose=self.rc.system_verbose)
509 534 # These are for getoutput and getoutputerror:
510 535 self.getoutput = lambda cmd: \
511 536 getoutput(self.var_expand(cmd),
512 537 header='IPython system call: ',
513 538 verbose=self.rc.system_verbose)
514 539 self.getoutputerror = lambda cmd: \
515 540 getoutputerror(str(ItplNS(cmd.replace('#','\#'),
516 541 self.user_ns)),
517 542 header='IPython system call: ',
518 543 verbose=self.rc.system_verbose)
519 544
520 545 # RegExp for splitting line contents into pre-char//first
521 546 # word-method//rest. For clarity, each group in on one line.
522 547
523 548 # WARNING: update the regexp if the above escapes are changed, as they
524 549 # are hardwired in.
525 550
526 551 # Don't get carried away with trying to make the autocalling catch too
527 552 # much: it's better to be conservative rather than to trigger hidden
528 553 # evals() somewhere and end up causing side effects.
529 554
530 555 self.line_split = re.compile(r'^([\s*,;/])'
531 556 r'([\?\w\.]+\w*\s*)'
532 557 r'(\(?.*$)')
533 558
534 559 # Original re, keep around for a while in case changes break something
535 560 #self.line_split = re.compile(r'(^[\s*!\?%,/]?)'
536 561 # r'(\s*[\?\w\.]+\w*\s*)'
537 562 # r'(\(?.*$)')
538 563
539 564 # RegExp to identify potential function names
540 565 self.re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$')
541 566 # RegExp to exclude strings with this start from autocalling
542 567 self.re_exclude_auto = re.compile('^[!=()<>,\*/\+-]|^is ')
543 568
544 569 # try to catch also methods for stuff in lists/tuples/dicts: off
545 570 # (experimental). For this to work, the line_split regexp would need
546 571 # to be modified so it wouldn't break things at '['. That line is
547 572 # nasty enough that I shouldn't change it until I can test it _well_.
548 573 #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$')
549 574
550 575 # keep track of where we started running (mainly for crash post-mortem)
551 576 self.starting_dir = os.getcwd()
552 577
553 # Attributes for Logger mixin class, make defaults here
554 self._dolog = False
555 self.LOG = ''
556 self.LOGDEF = '.InteractiveShell.log'
557 self.LOGMODE = 'over'
558 self.LOGHEAD = Itpl(
559 """#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
560 #log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
561 #log# opts = $self.rc.opts
562 #log# args = $self.rc.args
563 #log# It is safe to make manual edits below here.
564 #log#-----------------------------------------------------------------------
565 """)
566 578 # Various switches which can be set
567 579 self.CACHELENGTH = 5000 # this is cheap, it's just text
568 580 self.BANNER = "Python %(version)s on %(platform)s\n" % sys.__dict__
569 581 self.banner2 = banner2
570 582
571 583 # TraceBack handlers:
572 584
573 585 # Syntax error handler.
574 586 self.SyntaxTB = SyntaxTB(color_scheme='NoColor')
575 587
576 588 # The interactive one is initialized with an offset, meaning we always
577 589 # want to remove the topmost item in the traceback, which is our own
578 590 # internal code. Valid modes: ['Plain','Context','Verbose']
579 591 self.InteractiveTB = ultraTB.AutoFormattedTB(mode = 'Plain',
580 592 color_scheme='NoColor',
581 593 tb_offset = 1)
582 594
583 595 # IPython itself shouldn't crash. This will produce a detailed
584 596 # post-mortem if it does. But we only install the crash handler for
585 597 # non-threaded shells, the threaded ones use a normal verbose reporter
586 598 # and lose the crash handler. This is because exceptions in the main
587 599 # thread (such as in GUI code) propagate directly to sys.excepthook,
588 600 # and there's no point in printing crash dumps for every user exception.
589 601 if self.isthreaded:
590 602 sys.excepthook = ultraTB.FormattedTB()
591 603 else:
592 604 from IPython import CrashHandler
593 605 sys.excepthook = CrashHandler.CrashHandler(self)
594 606
595 607 # The instance will store a pointer to this, so that runtime code
596 608 # (such as magics) can access it. This is because during the
597 609 # read-eval loop, it gets temporarily overwritten (to deal with GUI
598 610 # frameworks).
599 611 self.sys_excepthook = sys.excepthook
600 612
601 613 # and add any custom exception handlers the user may have specified
602 614 self.set_custom_exc(*custom_exceptions)
603 615
604 616 # Object inspector
605 617 self.inspector = OInspect.Inspector(OInspect.InspectColors,
606 618 PyColorize.ANSICodeColors,
607 619 'NoColor')
608 620 # indentation management
609 621 self.autoindent = False
610 622 self.indent_current_nsp = 0
611 623 self.indent_current = '' # actual indent string
612 624
613 625 # Make some aliases automatically
614 626 # Prepare list of shell aliases to auto-define
615 627 if os.name == 'posix':
616 628 auto_alias = ('mkdir mkdir', 'rmdir rmdir',
617 629 'mv mv -i','rm rm -i','cp cp -i',
618 630 'cat cat','less less','clear clear',
619 631 # a better ls
620 632 'ls ls -F',
621 633 # long ls
622 634 'll ls -lF',
623 635 # color ls
624 636 'lc ls -F -o --color',
625 637 # ls normal files only
626 638 'lf ls -F -o --color %l | grep ^-',
627 639 # ls symbolic links
628 640 'lk ls -F -o --color %l | grep ^l',
629 641 # directories or links to directories,
630 642 'ldir ls -F -o --color %l | grep /$',
631 643 # things which are executable
632 644 'lx ls -F -o --color %l | grep ^-..x',
633 645 )
634 646 elif os.name in ['nt','dos']:
635 647 auto_alias = ('dir dir /on', 'ls dir /on',
636 648 'ddir dir /ad /on', 'ldir dir /ad /on',
637 649 'mkdir mkdir','rmdir rmdir','echo echo',
638 650 'ren ren','cls cls','copy copy')
639 651 else:
640 652 auto_alias = ()
641 653 self.auto_alias = map(lambda s:s.split(None,1),auto_alias)
642 654 # Call the actual (public) initializer
643 655 self.init_auto_alias()
644 656 # end __init__
645 657
646 658 def post_config_initialization(self):
647 659 """Post configuration init method
648 660
649 661 This is called after the configuration files have been processed to
650 662 'finalize' the initialization."""
651 663
652 664 rc = self.rc
653 665
654 666 # Load readline proper
655 667 if rc.readline:
656 668 self.init_readline()
657 669
670 # log system
671 self.logger = Logger(self,logfname='ipython_log.py',logmode='rotate')
672 # local shortcut, this is used a LOT
673 self.log = self.logger.log
674
675 # Initialize cache, set in/out prompts and printing system
676 self.outputcache = CachedOutput(self,
677 rc.cache_size,
678 rc.pprint,
679 input_sep = rc.separate_in,
680 output_sep = rc.separate_out,
681 output_sep2 = rc.separate_out2,
682 ps1 = rc.prompt_in1,
683 ps2 = rc.prompt_in2,
684 ps_out = rc.prompt_out,
685 pad_left = rc.prompts_pad_left)
686
687 # user may have over-ridden the default print hook:
688 try:
689 self.outputcache.__class__.display = self.hooks.display
690 except AttributeError:
691 pass
692
693 # I don't like assigning globally to sys, because it means when embedding
694 # instances, each embedded instance overrides the previous choice. But
695 # sys.displayhook seems to be called internally by exec, so I don't see a
696 # way around it.
697 sys.displayhook = self.outputcache
698
658 699 # Set user colors (don't do it in the constructor above so that it
659 700 # doesn't crash if colors option is invalid)
660 701 self.magic_colors(rc.colors)
661 702
703 # Set calling of pdb on exceptions
704 self.call_pdb = rc.pdb
705
662 706 # Load user aliases
663 707 for alias in rc.alias:
664 708 self.magic_alias(alias)
665 709
666 710 # dynamic data that survives through sessions
667 711 # XXX make the filename a config option?
668 712 persist_base = 'persist'
669 713 if rc.profile:
670 714 persist_base += '_%s' % rc.profile
671 715 self.persist_fname = os.path.join(rc.ipythondir,persist_base)
672 716
673 717 try:
674 718 self.persist = pickle.load(file(self.persist_fname))
675 719 except:
676 720 self.persist = {}
677 721
678 722 def set_hook(self,name,hook):
679 723 """set_hook(name,hook) -> sets an internal IPython hook.
680 724
681 725 IPython exposes some of its internal API as user-modifiable hooks. By
682 726 resetting one of these hooks, you can modify IPython's behavior to
683 727 call at runtime your own routines."""
684 728
685 729 # At some point in the future, this should validate the hook before it
686 730 # accepts it. Probably at least check that the hook takes the number
687 731 # of args it's supposed to.
688 732 setattr(self.hooks,name,new.instancemethod(hook,self,self.__class__))
689 733
690 734 def set_custom_exc(self,exc_tuple,handler):
691 735 """set_custom_exc(exc_tuple,handler)
692 736
693 737 Set a custom exception handler, which will be called if any of the
694 738 exceptions in exc_tuple occur in the mainloop (specifically, in the
695 739 runcode() method.
696 740
697 741 Inputs:
698 742
699 743 - exc_tuple: a *tuple* of valid exceptions to call the defined
700 744 handler for. It is very important that you use a tuple, and NOT A
701 745 LIST here, because of the way Python's except statement works. If
702 746 you only want to trap a single exception, use a singleton tuple:
703 747
704 748 exc_tuple == (MyCustomException,)
705 749
706 750 - handler: this must be defined as a function with the following
707 751 basic interface: def my_handler(self,etype,value,tb).
708 752
709 753 This will be made into an instance method (via new.instancemethod)
710 754 of IPython itself, and it will be called if any of the exceptions
711 755 listed in the exc_tuple are caught. If the handler is None, an
712 756 internal basic one is used, which just prints basic info.
713 757
714 758 WARNING: by putting in your own exception handler into IPython's main
715 759 execution loop, you run a very good chance of nasty crashes. This
716 760 facility should only be used if you really know what you are doing."""
717 761
718 762 assert type(exc_tuple)==type(()) , \
719 763 "The custom exceptions must be given AS A TUPLE."
720 764
721 765 def dummy_handler(self,etype,value,tb):
722 766 print '*** Simple custom exception handler ***'
723 767 print 'Exception type :',etype
724 768 print 'Exception value:',value
725 769 print 'Traceback :',tb
726 770 print 'Source code :','\n'.join(self.buffer)
727 771
728 772 if handler is None: handler = dummy_handler
729 773
730 774 self.CustomTB = new.instancemethod(handler,self,self.__class__)
731 775 self.custom_exceptions = exc_tuple
732 776
733 777 def set_custom_completer(self,completer,pos=0):
734 778 """set_custom_completer(completer,pos=0)
735 779
736 780 Adds a new custom completer function.
737 781
738 782 The position argument (defaults to 0) is the index in the completers
739 783 list where you want the completer to be inserted."""
740 784
741 785 newcomp = new.instancemethod(completer,self.Completer,
742 786 self.Completer.__class__)
743 787 self.Completer.matchers.insert(pos,newcomp)
744 788
789 def _get_call_pdb(self):
790 return self._call_pdb
791
792 def _set_call_pdb(self,val):
793
794 if val not in (0,1,False,True):
795 raise ValueError,'new call_pdb value must be boolean'
796
797 # store value in instance
798 self._call_pdb = val
799
800 # notify the actual exception handlers
801 self.InteractiveTB.call_pdb = val
802 if self.isthreaded:
803 try:
804 self.sys_excepthook.call_pdb = val
805 except:
806 warn('Failed to activate pdb for threaded exception handler')
807
808 call_pdb = property(_get_call_pdb,_set_call_pdb,None,
809 'Control auto-activation of pdb at exceptions')
810
745 811 def complete(self,text):
746 812 """Return a sorted list of all possible completions on text.
747 813
748 814 Inputs:
749 815
750 816 - text: a string of text to be completed on.
751 817
752 818 This is a wrapper around the completion mechanism, similar to what
753 819 readline does at the command line when the TAB key is hit. By
754 820 exposing it as a method, it can be used by other non-readline
755 821 environments (such as GUIs) for text completion.
756 822
757 823 Simple usage example:
758 824
759 825 In [1]: x = 'hello'
760 826
761 827 In [2]: __IP.complete('x.l')
762 828 Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']"""
763 829
764 830 complete = self.Completer.complete
765 831 state = 0
766 832 # use a dict so we get unique keys, since ipyhton's multiple
767 833 # completers can return duplicates.
768 834 comps = {}
769 835 while True:
770 836 newcomp = complete(text,state)
771 837 if newcomp is None:
772 838 break
773 839 comps[newcomp] = 1
774 840 state += 1
775 841 outcomps = comps.keys()
776 842 outcomps.sort()
777 843 return outcomps
778 844
779 845 def set_completer_frame(self, frame):
780 846 if frame:
781 847 self.Completer.namespace = frame.f_locals
782 848 self.Completer.global_namespace = frame.f_globals
783 849 else:
784 850 self.Completer.namespace = self.user_ns
785 851 self.Completer.global_namespace = self.user_global_ns
786 852
787 853 def init_auto_alias(self):
788 854 """Define some aliases automatically.
789 855
790 856 These are ALL parameter-less aliases"""
791 857 for alias,cmd in self.auto_alias:
792 858 self.alias_table[alias] = (0,cmd)
793 859
794 860 def alias_table_validate(self,verbose=0):
795 861 """Update information about the alias table.
796 862
797 863 In particular, make sure no Python keywords/builtins are in it."""
798 864
799 865 no_alias = self.no_alias
800 866 for k in self.alias_table.keys():
801 867 if k in no_alias:
802 868 del self.alias_table[k]
803 869 if verbose:
804 870 print ("Deleting alias <%s>, it's a Python "
805 871 "keyword or builtin." % k)
806 872
807 873 def set_autoindent(self,value=None):
808 874 """Set the autoindent flag, checking for readline support.
809 875
810 876 If called with no arguments, it acts as a toggle."""
811 877
812 878 if not self.has_readline:
813 879 if os.name == 'posix':
814 880 warn("The auto-indent feature requires the readline library")
815 881 self.autoindent = 0
816 882 return
817 883 if value is None:
818 884 self.autoindent = not self.autoindent
819 885 else:
820 886 self.autoindent = value
821 887
822 888 def rc_set_toggle(self,rc_field,value=None):
823 889 """Set or toggle a field in IPython's rc config. structure.
824 890
825 891 If called with no arguments, it acts as a toggle.
826 892
827 893 If called with a non-existent field, the resulting AttributeError
828 894 exception will propagate out."""
829 895
830 896 rc_val = getattr(self.rc,rc_field)
831 897 if value is None:
832 898 value = not rc_val
833 899 setattr(self.rc,rc_field,value)
834 900
835 901 def user_setup(self,ipythondir,rc_suffix,mode='install'):
836 902 """Install the user configuration directory.
837 903
838 904 Can be called when running for the first time or to upgrade the user's
839 905 .ipython/ directory with the mode parameter. Valid modes are 'install'
840 906 and 'upgrade'."""
841 907
842 908 def wait():
843 909 try:
844 910 raw_input("Please press <RETURN> to start IPython.")
845 911 except EOFError:
846 912 print >> Term.cout
847 913 print '*'*70
848 914
849 915 cwd = os.getcwd() # remember where we started
850 916 glb = glob.glob
851 917 print '*'*70
852 918 if mode == 'install':
853 919 print \
854 920 """Welcome to IPython. I will try to create a personal configuration directory
855 921 where you can customize many aspects of IPython's functionality in:\n"""
856 922 else:
857 923 print 'I am going to upgrade your configuration in:'
858 924
859 925 print ipythondir
860 926
861 927 rcdirend = os.path.join('IPython','UserConfig')
862 928 cfg = lambda d: os.path.join(d,rcdirend)
863 929 try:
864 930 rcdir = filter(os.path.isdir,map(cfg,sys.path))[0]
865 931 except IOError:
866 932 warning = """
867 933 Installation error. IPython's directory was not found.
868 934
869 935 Check the following:
870 936
871 937 The ipython/IPython directory should be in a directory belonging to your
872 938 PYTHONPATH environment variable (that is, it should be in a directory
873 939 belonging to sys.path). You can copy it explicitly there or just link to it.
874 940
875 941 IPython will proceed with builtin defaults.
876 942 """
877 943 warn(warning)
878 944 wait()
879 945 return
880 946
881 947 if mode == 'install':
882 948 try:
883 949 shutil.copytree(rcdir,ipythondir)
884 950 os.chdir(ipythondir)
885 951 rc_files = glb("ipythonrc*")
886 952 for rc_file in rc_files:
887 953 os.rename(rc_file,rc_file+rc_suffix)
888 954 except:
889 955 warning = """
890 956
891 957 There was a problem with the installation:
892 958 %s
893 959 Try to correct it or contact the developers if you think it's a bug.
894 960 IPython will proceed with builtin defaults.""" % sys.exc_info()[1]
895 961 warn(warning)
896 962 wait()
897 963 return
898 964
899 965 elif mode == 'upgrade':
900 966 try:
901 967 os.chdir(ipythondir)
902 968 except:
903 969 print """
904 970 Can not upgrade: changing to directory %s failed. Details:
905 971 %s
906 972 """ % (ipythondir,sys.exc_info()[1])
907 973 wait()
908 974 return
909 975 else:
910 976 sources = glb(os.path.join(rcdir,'[A-Za-z]*'))
911 977 for new_full_path in sources:
912 978 new_filename = os.path.basename(new_full_path)
913 979 if new_filename.startswith('ipythonrc'):
914 980 new_filename = new_filename + rc_suffix
915 981 # The config directory should only contain files, skip any
916 982 # directories which may be there (like CVS)
917 983 if os.path.isdir(new_full_path):
918 984 continue
919 985 if os.path.exists(new_filename):
920 986 old_file = new_filename+'.old'
921 987 if os.path.exists(old_file):
922 988 os.remove(old_file)
923 989 os.rename(new_filename,old_file)
924 990 shutil.copy(new_full_path,new_filename)
925 991 else:
926 992 raise ValueError,'unrecognized mode for install:',`mode`
927 993
928 994 # Fix line-endings to those native to each platform in the config
929 995 # directory.
930 996 try:
931 997 os.chdir(ipythondir)
932 998 except:
933 999 print """
934 1000 Problem: changing to directory %s failed.
935 1001 Details:
936 1002 %s
937 1003
938 1004 Some configuration files may have incorrect line endings. This should not
939 1005 cause any problems during execution. """ % (ipythondir,sys.exc_info()[1])
940 1006 wait()
941 1007 else:
942 1008 for fname in glb('ipythonrc*'):
943 1009 try:
944 1010 native_line_ends(fname,backup=0)
945 1011 except IOError:
946 1012 pass
947 1013
948 1014 if mode == 'install':
949 1015 print """
950 1016 Successful installation!
951 1017
952 1018 Please read the sections 'Initial Configuration' and 'Quick Tips' in the
953 1019 IPython manual (there are both HTML and PDF versions supplied with the
954 1020 distribution) to make sure that your system environment is properly configured
955 1021 to take advantage of IPython's features."""
956 1022 else:
957 1023 print """
958 1024 Successful upgrade!
959 1025
960 1026 All files in your directory:
961 1027 %(ipythondir)s
962 1028 which would have been overwritten by the upgrade were backed up with a .old
963 1029 extension. If you had made particular customizations in those files you may
964 1030 want to merge them back into the new files.""" % locals()
965 1031 wait()
966 1032 os.chdir(cwd)
967 1033 # end user_setup()
968 1034
969 1035 def atexit_operations(self):
970 1036 """This will be executed at the time of exit.
971 1037
972 1038 Saving of persistent data should be performed here. """
973 1039
974 1040 # input history
975 1041 self.savehist()
976 1042
977 1043 # Cleanup all tempfiles left around
978 1044 for tfile in self.tempfiles:
979 1045 try:
980 1046 os.unlink(tfile)
981 1047 except OSError:
982 1048 pass
983 1049
984 1050 # save the "persistent data" catch-all dictionary
985 1051 try:
986 1052 pickle.dump(self.persist, open(self.persist_fname,"w"))
987 1053 except:
988 1054 print "*** ERROR *** persistent data saving failed."
989 1055
990 1056 def savehist(self):
991 1057 """Save input history to a file (via readline library)."""
992 1058 try:
993 1059 self.readline.write_history_file(self.histfile)
994 1060 except:
995 1061 print 'Unable to save IPython command history to file: ' + \
996 1062 `self.histfile`
997 1063
998 1064 def pre_readline(self):
999 1065 """readline hook to be used at the start of each line.
1000 1066
1001 1067 Currently it handles auto-indent only."""
1002 1068
1003 1069 self.readline.insert_text(self.indent_current)
1004 1070
1005 1071 def init_readline(self):
1006 1072 """Command history completion/saving/reloading."""
1007 1073 try:
1008 1074 import readline
1009 1075 except ImportError:
1010 1076 self.has_readline = 0
1011 1077 self.readline = None
1012 1078 # no point in bugging windows users with this every time:
1013 1079 if os.name == 'posix':
1014 1080 warn('Readline services not available on this platform.')
1015 1081 else:
1016 1082 import atexit
1017 1083 from IPython.completer import IPCompleter
1018 1084 self.Completer = IPCompleter(self,
1019 1085 self.user_ns,
1020 1086 self.user_global_ns,
1021 1087 self.rc.readline_omit__names,
1022 1088 self.alias_table)
1023 1089
1024 1090 # Platform-specific configuration
1025 1091 if os.name == 'nt':
1026 1092 self.readline_startup_hook = readline.set_pre_input_hook
1027 1093 else:
1028 1094 self.readline_startup_hook = readline.set_startup_hook
1029 1095
1030 1096 # Load user's initrc file (readline config)
1031 1097 inputrc_name = os.environ.get('INPUTRC')
1032 1098 if inputrc_name is None:
1033 1099 home_dir = get_home_dir()
1034 1100 if home_dir is not None:
1035 1101 inputrc_name = os.path.join(home_dir,'.inputrc')
1036 1102 if os.path.isfile(inputrc_name):
1037 1103 try:
1038 1104 readline.read_init_file(inputrc_name)
1039 1105 except:
1040 1106 warn('Problems reading readline initialization file <%s>'
1041 1107 % inputrc_name)
1042 1108
1043 1109 self.has_readline = 1
1044 1110 self.readline = readline
1045 1111 # save this in sys so embedded copies can restore it properly
1046 1112 sys.ipcompleter = self.Completer.complete
1047 1113 readline.set_completer(self.Completer.complete)
1048 1114
1049 1115 # Configure readline according to user's prefs
1050 1116 for rlcommand in self.rc.readline_parse_and_bind:
1051 1117 readline.parse_and_bind(rlcommand)
1052 1118
1053 1119 # remove some chars from the delimiters list
1054 1120 delims = readline.get_completer_delims()
1055 1121 delims = delims.translate(string._idmap,
1056 1122 self.rc.readline_remove_delims)
1057 1123 readline.set_completer_delims(delims)
1058 1124 # otherwise we end up with a monster history after a while:
1059 1125 readline.set_history_length(1000)
1060 1126 try:
1061 1127 #print '*** Reading readline history' # dbg
1062 1128 readline.read_history_file(self.histfile)
1063 1129 except IOError:
1064 1130 pass # It doesn't exist yet.
1065 1131
1066 1132 atexit.register(self.atexit_operations)
1067 1133 del atexit
1068 1134
1069 1135 # Configure auto-indent for all platforms
1070 1136 self.set_autoindent(self.rc.autoindent)
1071 1137
1072 1138 def _should_recompile(self,e):
1073 1139 """Utility routine for edit_syntax_error"""
1074 1140
1075 1141 if e.filename in ('<ipython console>','<input>','<string>',
1076 1142 '<console>'):
1077 1143 return False
1078 1144 try:
1079 1145 if not ask_yes_no('Return to editor to correct syntax error? '
1080 1146 '[Y/n] ','y'):
1081 1147 return False
1082 1148 except EOFError:
1083 1149 return False
1084 1150 self.hooks.fix_error_editor(e.filename,e.lineno,e.offset,e.msg)
1085 1151 return True
1086 1152
1087 1153 def edit_syntax_error(self):
1088 1154 """The bottom half of the syntax error handler called in the main loop.
1089 1155
1090 1156 Loop until syntax error is fixed or user cancels.
1091 1157 """
1092 1158
1093 1159 while self.SyntaxTB.last_syntax_error:
1094 1160 # copy and clear last_syntax_error
1095 1161 err = self.SyntaxTB.clear_err_state()
1096 1162 if not self._should_recompile(err):
1097 1163 return
1098 1164 try:
1099 1165 # may set last_syntax_error again if a SyntaxError is raised
1100 1166 self.safe_execfile(err.filename,self.shell.user_ns)
1101 1167 except:
1102 1168 self.showtraceback()
1103 1169 else:
1104 1170 f = file(err.filename)
1105 1171 try:
1106 1172 sys.displayhook(f.read())
1107 1173 finally:
1108 1174 f.close()
1109 1175
1110 1176 def showsyntaxerror(self, filename=None):
1111 1177 """Display the syntax error that just occurred.
1112 1178
1113 1179 This doesn't display a stack trace because there isn't one.
1114 1180
1115 1181 If a filename is given, it is stuffed in the exception instead
1116 1182 of what was there before (because Python's parser always uses
1117 1183 "<string>" when reading from a string).
1118 1184 """
1119 1185 type, value, sys.last_traceback = sys.exc_info()
1120 1186 sys.last_type = type
1121 1187 sys.last_value = value
1122 1188 if filename and type is SyntaxError:
1123 1189 # Work hard to stuff the correct filename in the exception
1124 1190 try:
1125 1191 msg, (dummy_filename, lineno, offset, line) = value
1126 1192 except:
1127 1193 # Not the format we expect; leave it alone
1128 1194 pass
1129 1195 else:
1130 1196 # Stuff in the right filename
1131 1197 try:
1132 1198 # Assume SyntaxError is a class exception
1133 1199 value = SyntaxError(msg, (filename, lineno, offset, line))
1134 1200 except:
1135 1201 # If that failed, assume SyntaxError is a string
1136 1202 value = msg, (filename, lineno, offset, line)
1137 1203 self.SyntaxTB(type,value,[])
1138 1204
1139 1205 def debugger(self):
1140 1206 """Call the pdb debugger."""
1141 1207
1142 1208 if not self.rc.pdb:
1143 1209 return
1144 1210 pdb.pm()
1145 1211
1146 1212 def showtraceback(self,exc_tuple = None,filename=None):
1147 1213 """Display the exception that just occurred."""
1148 1214
1149 1215 # Though this won't be called by syntax errors in the input line,
1150 1216 # there may be SyntaxError cases whith imported code.
1151 1217 if exc_tuple is None:
1152 1218 type, value, tb = sys.exc_info()
1153 1219 else:
1154 1220 type, value, tb = exc_tuple
1155 1221 if type is SyntaxError:
1156 1222 self.showsyntaxerror(filename)
1157 1223 else:
1158 1224 sys.last_type = type
1159 1225 sys.last_value = value
1160 1226 sys.last_traceback = tb
1161 1227 self.InteractiveTB()
1162 1228 if self.InteractiveTB.call_pdb and self.has_readline:
1163 1229 # pdb mucks up readline, fix it back
1164 1230 self.readline.set_completer(self.Completer.complete)
1165 1231
1166 1232 def update_cache(self, line):
1167 1233 """puts line into cache"""
1168 1234 self.inputcache.insert(0, line) # This copies the cache every time ... :-(
1169 1235 if len(self.inputcache) >= self.CACHELENGTH:
1170 1236 self.inputcache.pop() # This doesn't :-)
1171 1237
1172 1238 def mainloop(self,banner=None):
1173 1239 """Creates the local namespace and starts the mainloop.
1174 1240
1175 1241 If an optional banner argument is given, it will override the
1176 1242 internally created default banner."""
1177 1243
1178 1244 if self.rc.c: # Emulate Python's -c option
1179 1245 self.exec_init_cmd()
1180 1246 if banner is None:
1181 1247 if self.rc.banner:
1182 1248 banner = self.BANNER+self.banner2
1183 1249 else:
1184 1250 banner = ''
1185 1251 self.interact(banner)
1186 1252
1187 1253 def exec_init_cmd(self):
1188 1254 """Execute a command given at the command line.
1189 1255
1190 1256 This emulates Python's -c option."""
1191 1257
1192 1258 sys.argv = ['-c']
1193 1259 self.push(self.rc.c)
1194 1260
1195 1261 def embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
1196 1262 """Embeds IPython into a running python program.
1197 1263
1198 1264 Input:
1199 1265
1200 1266 - header: An optional header message can be specified.
1201 1267
1202 1268 - local_ns, global_ns: working namespaces. If given as None, the
1203 1269 IPython-initialized one is updated with __main__.__dict__, so that
1204 1270 program variables become visible but user-specific configuration
1205 1271 remains possible.
1206 1272
1207 1273 - stack_depth: specifies how many levels in the stack to go to
1208 1274 looking for namespaces (when local_ns and global_ns are None). This
1209 1275 allows an intermediate caller to make sure that this function gets
1210 1276 the namespace from the intended level in the stack. By default (0)
1211 1277 it will get its locals and globals from the immediate caller.
1212 1278
1213 1279 Warning: it's possible to use this in a program which is being run by
1214 1280 IPython itself (via %run), but some funny things will happen (a few
1215 1281 globals get overwritten). In the future this will be cleaned up, as
1216 1282 there is no fundamental reason why it can't work perfectly."""
1217 1283
1218 1284 # Get locals and globals from caller
1219 1285 if local_ns is None or global_ns is None:
1220 1286 call_frame = sys._getframe(stack_depth).f_back
1221 1287
1222 1288 if local_ns is None:
1223 1289 local_ns = call_frame.f_locals
1224 1290 if global_ns is None:
1225 1291 global_ns = call_frame.f_globals
1226 1292
1227 1293 # Update namespaces and fire up interpreter
1228 1294 self.user_ns = local_ns
1229 1295 self.user_global_ns = global_ns
1230 1296
1231 1297 # Patch for global embedding to make sure that things don't overwrite
1232 1298 # user globals accidentally. Thanks to Richard <rxe@renre-europe.com>
1233 1299 # FIXME. Test this a bit more carefully (the if.. is new)
1234 1300 if local_ns is None and global_ns is None:
1235 1301 self.user_global_ns.update(__main__.__dict__)
1236 1302
1237 1303 # make sure the tab-completer has the correct frame information, so it
1238 1304 # actually completes using the frame's locals/globals
1239 1305 self.set_completer_frame(call_frame)
1240 1306
1241 1307 self.interact(header)
1242 1308
1243 1309 def interact(self, banner=None):
1244 1310 """Closely emulate the interactive Python console.
1245 1311
1246 1312 The optional banner argument specify the banner to print
1247 1313 before the first interaction; by default it prints a banner
1248 1314 similar to the one printed by the real Python interpreter,
1249 1315 followed by the current class name in parentheses (so as not
1250 1316 to confuse this with the real interpreter -- since it's so
1251 1317 close!).
1252 1318
1253 1319 """
1254 1320 cprt = 'Type "copyright", "credits" or "license" for more information.'
1255 1321 if banner is None:
1256 1322 self.write("Python %s on %s\n%s\n(%s)\n" %
1257 1323 (sys.version, sys.platform, cprt,
1258 1324 self.__class__.__name__))
1259 1325 else:
1260 1326 self.write(banner)
1261 1327
1262 1328 more = 0
1263 1329
1264 1330 # Mark activity in the builtins
1265 1331 __builtin__.__dict__['__IPYTHON__active'] += 1
1266 1332
1267 1333 # compiled regexps for autoindent management
1268 1334 ini_spaces_re = re.compile(r'^(\s+)')
1269 1335 dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass')
1270 1336
1271 1337 # exit_now is set by a call to %Exit or %Quit
1272 1338 while not self.exit_now:
1273 1339 try:
1274 1340 if more:
1275 1341 prompt = self.outputcache.prompt2
1276 1342 if self.autoindent:
1277 1343 self.readline_startup_hook(self.pre_readline)
1278 1344 else:
1279 1345 prompt = self.outputcache.prompt1
1280 1346 try:
1281 1347 line = self.raw_input(prompt,more)
1282 1348 if self.autoindent:
1283 1349 self.readline_startup_hook(None)
1284 1350 except EOFError:
1285 1351 if self.autoindent:
1286 1352 self.readline_startup_hook(None)
1287 1353 self.write("\n")
1288 1354 self.exit()
1289 1355 else:
1290 1356 more = self.push(line)
1291 1357 # Auto-indent management
1292 1358 if self.autoindent:
1293 1359 if line:
1294 1360 ini_spaces = ini_spaces_re.match(line)
1295 1361 if ini_spaces:
1296 1362 nspaces = ini_spaces.end()
1297 1363 else:
1298 1364 nspaces = 0
1299 1365 self.indent_current_nsp = nspaces
1300 1366
1301 1367 if line[-1] == ':':
1302 1368 self.indent_current_nsp += 4
1303 1369 elif dedent_re.match(line):
1304 1370 self.indent_current_nsp -= 4
1305 1371 else:
1306 1372 self.indent_current_nsp = 0
1307 1373
1308 1374 # indent_current is the actual string to be inserted
1309 1375 # by the readline hooks for indentation
1310 1376 self.indent_current = ' '* self.indent_current_nsp
1311 1377
1312 1378 if (self.SyntaxTB.last_syntax_error and
1313 1379 self.rc.autoedit_syntax):
1314 1380 self.edit_syntax_error()
1315 1381
1316 1382 except KeyboardInterrupt:
1317 1383 self.write("\nKeyboardInterrupt\n")
1318 1384 self.resetbuffer()
1319 1385 more = 0
1320 1386 # keep cache in sync with the prompt counter:
1321 1387 self.outputcache.prompt_count -= 1
1322 1388
1323 1389 if self.autoindent:
1324 1390 self.indent_current_nsp = 0
1325 1391 self.indent_current = ' '* self.indent_current_nsp
1326 1392
1327 1393 except bdb.BdbQuit:
1328 1394 warn("The Python debugger has exited with a BdbQuit exception.\n"
1329 1395 "Because of how pdb handles the stack, it is impossible\n"
1330 1396 "for IPython to properly format this particular exception.\n"
1331 1397 "IPython will resume normal operation.")
1332 1398
1333 1399 # We are off again...
1334 1400 __builtin__.__dict__['__IPYTHON__active'] -= 1
1335 1401
1336 1402 def excepthook(self, type, value, tb):
1337 1403 """One more defense for GUI apps that call sys.excepthook.
1338 1404
1339 1405 GUI frameworks like wxPython trap exceptions and call
1340 1406 sys.excepthook themselves. I guess this is a feature that
1341 1407 enables them to keep running after exceptions that would
1342 1408 otherwise kill their mainloop. This is a bother for IPython
1343 1409 which excepts to catch all of the program exceptions with a try:
1344 1410 except: statement.
1345 1411
1346 1412 Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
1347 1413 any app directly invokes sys.excepthook, it will look to the user like
1348 1414 IPython crashed. In order to work around this, we can disable the
1349 1415 CrashHandler and replace it with this excepthook instead, which prints a
1350 1416 regular traceback using our InteractiveTB. In this fashion, apps which
1351 1417 call sys.excepthook will generate a regular-looking exception from
1352 1418 IPython, and the CrashHandler will only be triggered by real IPython
1353 1419 crashes.
1354 1420
1355 1421 This hook should be used sparingly, only in places which are not likely
1356 1422 to be true IPython errors.
1357 1423 """
1358 1424
1359 1425 self.InteractiveTB(type, value, tb, tb_offset=0)
1360 1426 if self.InteractiveTB.call_pdb and self.has_readline:
1361 1427 self.readline.set_completer(self.Completer.complete)
1362 1428
1363 1429 def call_alias(self,alias,rest=''):
1364 1430 """Call an alias given its name and the rest of the line.
1365 1431
1366 1432 This function MUST be given a proper alias, because it doesn't make
1367 1433 any checks when looking up into the alias table. The caller is
1368 1434 responsible for invoking it only with a valid alias."""
1369 1435
1370 1436 #print 'ALIAS: <%s>+<%s>' % (alias,rest) # dbg
1371 1437 nargs,cmd = self.alias_table[alias]
1372 1438 # Expand the %l special to be the user's input line
1373 1439 if cmd.find('%l') >= 0:
1374 1440 cmd = cmd.replace('%l',rest)
1375 1441 rest = ''
1376 1442 if nargs==0:
1377 1443 # Simple, argument-less aliases
1378 1444 cmd = '%s %s' % (cmd,rest)
1379 1445 else:
1380 1446 # Handle aliases with positional arguments
1381 1447 args = rest.split(None,nargs)
1382 1448 if len(args)< nargs:
1383 1449 error('Alias <%s> requires %s arguments, %s given.' %
1384 1450 (alias,nargs,len(args)))
1385 1451 return
1386 1452 cmd = '%s %s' % (cmd % tuple(args[:nargs]),' '.join(args[nargs:]))
1387 1453 # Now call the macro, evaluating in the user's namespace
1388 1454 try:
1389 1455 self.system(cmd)
1390 1456 except:
1391 1457 self.showtraceback()
1392 1458
1393 1459 def runlines(self,lines):
1394 1460 """Run a string of one or more lines of source.
1395 1461
1396 1462 This method is capable of running a string containing multiple source
1397 1463 lines, as if they had been entered at the IPython prompt. Since it
1398 1464 exposes IPython's processing machinery, the given strings can contain
1399 1465 magic calls (%magic), special shell access (!cmd), etc."""
1400 1466
1401 1467 # We must start with a clean buffer, in case this is run from an
1402 1468 # interactive IPython session (via a magic, for example).
1403 1469 self.resetbuffer()
1404 1470 lines = lines.split('\n')
1405 1471 more = 0
1406 1472 for line in lines:
1407 1473 # skip blank lines so we don't mess up the prompt counter, but do
1408 1474 # NOT skip even a blank line if we are in a code block (more is
1409 1475 # true)
1410 1476 if line or more:
1411 1477 more = self.push((self.prefilter(line,more)))
1412 1478 # IPython's runsource returns None if there was an error
1413 1479 # compiling the code. This allows us to stop processing right
1414 1480 # away, so the user gets the error message at the right place.
1415 1481 if more is None:
1416 1482 break
1417 1483 # final newline in case the input didn't have it, so that the code
1418 1484 # actually does get executed
1419 1485 if more:
1420 1486 self.push('\n')
1421 1487
1422 1488 def runsource(self, source, filename='<input>', symbol='single'):
1423 1489 """Compile and run some source in the interpreter.
1424 1490
1425 1491 Arguments are as for compile_command().
1426 1492
1427 1493 One several things can happen:
1428 1494
1429 1495 1) The input is incorrect; compile_command() raised an
1430 1496 exception (SyntaxError or OverflowError). A syntax traceback
1431 1497 will be printed by calling the showsyntaxerror() method.
1432 1498
1433 1499 2) The input is incomplete, and more input is required;
1434 1500 compile_command() returned None. Nothing happens.
1435 1501
1436 1502 3) The input is complete; compile_command() returned a code
1437 1503 object. The code is executed by calling self.runcode() (which
1438 1504 also handles run-time exceptions, except for SystemExit).
1439 1505
1440 1506 The return value is:
1441 1507
1442 1508 - True in case 2
1443 1509
1444 1510 - False in the other cases, unless an exception is raised, where
1445 1511 None is returned instead. This can be used by external callers to
1446 1512 know whether to continue feeding input or not.
1447 1513
1448 1514 The return value can be used to decide whether to use sys.ps1 or
1449 1515 sys.ps2 to prompt the next line."""
1450 1516
1451 1517 try:
1452 1518 code = self.compile(source,filename,symbol)
1453 1519 except (OverflowError, SyntaxError, ValueError):
1454 1520 # Case 1
1455 1521 self.showsyntaxerror(filename)
1456 1522 return None
1457 1523
1458 1524 if code is None:
1459 1525 # Case 2
1460 1526 return True
1461 1527
1462 1528 # Case 3
1463 1529 # We store the code object so that threaded shells and
1464 1530 # custom exception handlers can access all this info if needed.
1465 1531 # The source corresponding to this can be obtained from the
1466 1532 # buffer attribute as '\n'.join(self.buffer).
1467 1533 self.code_to_run = code
1468 1534 # now actually execute the code object
1469 1535 if self.runcode(code) == 0:
1470 1536 return False
1471 1537 else:
1472 1538 return None
1473 1539
1474 1540 def runcode(self,code_obj):
1475 1541 """Execute a code object.
1476 1542
1477 1543 When an exception occurs, self.showtraceback() is called to display a
1478 1544 traceback.
1479 1545
1480 1546 Return value: a flag indicating whether the code to be run completed
1481 1547 successfully:
1482 1548
1483 1549 - 0: successful execution.
1484 1550 - 1: an error occurred.
1485 1551 """
1486 1552
1487 1553 # Set our own excepthook in case the user code tries to call it
1488 1554 # directly, so that the IPython crash handler doesn't get triggered
1489 1555 old_excepthook,sys.excepthook = sys.excepthook, self.excepthook
1490 1556
1491 1557 # we save the original sys.excepthook in the instance, in case config
1492 1558 # code (such as magics) needs access to it.
1493 1559 self.sys_excepthook = old_excepthook
1494 1560 outflag = 1 # happens in more places, so it's easier as default
1495 1561 try:
1496 1562 try:
1497 1563 # Embedded instances require separate global/local namespaces
1498 1564 # so they can see both the surrounding (local) namespace and
1499 1565 # the module-level globals when called inside another function.
1500 1566 if self.embedded:
1501 1567 exec code_obj in self.user_global_ns, self.user_ns
1502 1568 # Normal (non-embedded) instances should only have a single
1503 1569 # namespace for user code execution, otherwise functions won't
1504 1570 # see interactive top-level globals.
1505 1571 else:
1506 1572 exec code_obj in self.user_ns
1507 1573 finally:
1508 1574 # Reset our crash handler in place
1509 1575 sys.excepthook = old_excepthook
1510 1576 except SystemExit:
1511 1577 self.resetbuffer()
1512 1578 self.showtraceback()
1513 1579 warn("Type exit or quit to exit IPython "
1514 1580 "(%Exit or %Quit do so unconditionally).",level=1)
1515 1581 except self.custom_exceptions:
1516 1582 etype,value,tb = sys.exc_info()
1517 1583 self.CustomTB(etype,value,tb)
1518 1584 except:
1519 1585 self.showtraceback()
1520 1586 else:
1521 1587 outflag = 0
1522 1588 if softspace(sys.stdout, 0):
1523 1589 print
1524 1590 # Flush out code object which has been run (and source)
1525 1591 self.code_to_run = None
1526 1592 return outflag
1527 1593
1528 1594 def push(self, line):
1529 1595 """Push a line to the interpreter.
1530 1596
1531 1597 The line should not have a trailing newline; it may have
1532 1598 internal newlines. The line is appended to a buffer and the
1533 1599 interpreter's runsource() method is called with the
1534 1600 concatenated contents of the buffer as source. If this
1535 1601 indicates that the command was executed or invalid, the buffer
1536 1602 is reset; otherwise, the command is incomplete, and the buffer
1537 1603 is left as it was after the line was appended. The return
1538 1604 value is 1 if more input is required, 0 if the line was dealt
1539 1605 with in some way (this is the same as runsource()).
1540 1606
1541 1607 """
1542 1608 self.buffer.append(line)
1543 1609 more = self.runsource('\n'.join(self.buffer), self.filename)
1544 1610 if not more:
1545 1611 self.resetbuffer()
1546 1612 return more
1547 1613
1548 1614 def resetbuffer(self):
1549 1615 """Reset the input buffer."""
1550 1616 self.buffer[:] = []
1551 1617
1552 1618 def raw_input(self,prompt='',continue_prompt=False):
1553 1619 """Write a prompt and read a line.
1554 1620
1555 1621 The returned line does not include the trailing newline.
1556 1622 When the user enters the EOF key sequence, EOFError is raised.
1557 1623
1558 1624 Optional inputs:
1559 1625
1560 1626 - prompt(''): a string to be printed to prompt the user.
1561 1627
1562 1628 - continue_prompt(False): whether this line is the first one or a
1563 1629 continuation in a sequence of inputs.
1564 1630 """
1565 1631
1566 1632 line = raw_input_original(prompt)
1567 1633 # Try to be reasonably smart about not re-indenting pasted input more
1568 1634 # than necessary. We do this by trimming out the auto-indent initial
1569 1635 # spaces, if the user's actual input started itself with whitespace.
1570 1636 if self.autoindent:
1571 1637 line2 = line[self.indent_current_nsp:]
1572 1638 if line2[0:1] in (' ','\t'):
1573 1639 line = line2
1574 1640 return self.prefilter(line,continue_prompt)
1575 1641
1576 1642 def split_user_input(self,line):
1577 1643 """Split user input into pre-char, function part and rest."""
1578 1644
1579 1645 lsplit = self.line_split.match(line)
1580 1646 if lsplit is None: # no regexp match returns None
1581 1647 try:
1582 1648 iFun,theRest = line.split(None,1)
1583 1649 except ValueError:
1584 1650 iFun,theRest = line,''
1585 1651 pre = re.match('^(\s*)(.*)',line).groups()[0]
1586 1652 else:
1587 1653 pre,iFun,theRest = lsplit.groups()
1588 1654
1589 1655 #print 'line:<%s>' % line # dbg
1590 1656 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun.strip(),theRest) # dbg
1591 1657 return pre,iFun.strip(),theRest
1592 1658
1593 1659 def _prefilter(self, line, continue_prompt):
1594 1660 """Calls different preprocessors, depending on the form of line."""
1595 1661
1596 1662 # All handlers *must* return a value, even if it's blank ('').
1597 1663
1598 1664 # Lines are NOT logged here. Handlers should process the line as
1599 1665 # needed, update the cache AND log it (so that the input cache array
1600 1666 # stays synced).
1601 1667
1602 1668 # This function is _very_ delicate, and since it's also the one which
1603 1669 # determines IPython's response to user input, it must be as efficient
1604 1670 # as possible. For this reason it has _many_ returns in it, trying
1605 1671 # always to exit as quickly as it can figure out what it needs to do.
1606 1672
1607 1673 # This function is the main responsible for maintaining IPython's
1608 1674 # behavior respectful of Python's semantics. So be _very_ careful if
1609 1675 # making changes to anything here.
1610 1676
1611 1677 #.....................................................................
1612 1678 # Code begins
1613 1679
1614 1680 #if line.startswith('%crash'): raise RuntimeError,'Crash now!' # dbg
1615 1681
1616 1682 # save the line away in case we crash, so the post-mortem handler can
1617 1683 # record it
1618 1684 self._last_input_line = line
1619 1685
1620 1686 #print '***line: <%s>' % line # dbg
1621 1687
1622 1688 # the input history needs to track even empty lines
1623 1689 if not line.strip():
1624 1690 if not continue_prompt:
1625 1691 self.outputcache.prompt_count -= 1
1626 1692 return self.handle_normal(line,continue_prompt)
1627 1693 #return self.handle_normal('',continue_prompt)
1628 1694
1629 1695 # print '***cont',continue_prompt # dbg
1630 1696 # special handlers are only allowed for single line statements
1631 1697 if continue_prompt and not self.rc.multi_line_specials:
1632 1698 return self.handle_normal(line,continue_prompt)
1633 1699
1634 1700 # For the rest, we need the structure of the input
1635 1701 pre,iFun,theRest = self.split_user_input(line)
1636 1702 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1637 1703
1638 1704 # First check for explicit escapes in the last/first character
1639 1705 handler = None
1640 1706 if line[-1] == self.ESC_HELP:
1641 1707 handler = self.esc_handlers.get(line[-1]) # the ? can be at the end
1642 1708 if handler is None:
1643 1709 # look at the first character of iFun, NOT of line, so we skip
1644 1710 # leading whitespace in multiline input
1645 1711 handler = self.esc_handlers.get(iFun[0:1])
1646 1712 if handler is not None:
1647 1713 return handler(line,continue_prompt,pre,iFun,theRest)
1648 1714 # Emacs ipython-mode tags certain input lines
1649 1715 if line.endswith('# PYTHON-MODE'):
1650 1716 return self.handle_emacs(line,continue_prompt)
1651 1717
1652 1718 # Next, check if we can automatically execute this thing
1653 1719
1654 1720 # Allow ! in multi-line statements if multi_line_specials is on:
1655 1721 if continue_prompt and self.rc.multi_line_specials and \
1656 1722 iFun.startswith(self.ESC_SHELL):
1657 1723 return self.handle_shell_escape(line,continue_prompt,
1658 1724 pre=pre,iFun=iFun,
1659 1725 theRest=theRest)
1660 1726
1661 1727 # Let's try to find if the input line is a magic fn
1662 1728 oinfo = None
1663 1729 if hasattr(self,'magic_'+iFun):
1664 1730 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1665 1731 if oinfo['ismagic']:
1666 1732 # Be careful not to call magics when a variable assignment is
1667 1733 # being made (ls='hi', for example)
1668 1734 if self.rc.automagic and \
1669 1735 (len(theRest)==0 or theRest[0] not in '!=()<>,') and \
1670 1736 (self.rc.multi_line_specials or not continue_prompt):
1671 1737 return self.handle_magic(line,continue_prompt,
1672 1738 pre,iFun,theRest)
1673 1739 else:
1674 1740 return self.handle_normal(line,continue_prompt)
1675 1741
1676 1742 # If the rest of the line begins with an (in)equality, assginment or
1677 1743 # function call, we should not call _ofind but simply execute it.
1678 1744 # This avoids spurious geattr() accesses on objects upon assignment.
1679 1745 #
1680 1746 # It also allows users to assign to either alias or magic names true
1681 1747 # python variables (the magic/alias systems always take second seat to
1682 1748 # true python code).
1683 1749 if theRest and theRest[0] in '!=()':
1684 1750 return self.handle_normal(line,continue_prompt)
1685 1751
1686 1752 if oinfo is None:
1687 1753 oinfo = self._ofind(iFun) # FIXME - _ofind is part of Magic
1688 1754
1689 1755 if not oinfo['found']:
1690 1756 return self.handle_normal(line,continue_prompt)
1691 1757 else:
1692 1758 #print 'iFun <%s> rest <%s>' % (iFun,theRest) # dbg
1693 1759 if oinfo['isalias']:
1694 1760 return self.handle_alias(line,continue_prompt,
1695 1761 pre,iFun,theRest)
1696 1762
1697 1763 if self.rc.autocall and \
1698 1764 not self.re_exclude_auto.match(theRest) and \
1699 1765 self.re_fun_name.match(iFun) and \
1700 1766 callable(oinfo['obj']) :
1701 1767 #print 'going auto' # dbg
1702 1768 return self.handle_auto(line,continue_prompt,pre,iFun,theRest)
1703 1769 else:
1704 1770 #print 'was callable?', callable(oinfo['obj']) # dbg
1705 1771 return self.handle_normal(line,continue_prompt)
1706 1772
1707 1773 # If we get here, we have a normal Python line. Log and return.
1708 1774 return self.handle_normal(line,continue_prompt)
1709 1775
1710 1776 def _prefilter_dumb(self, line, continue_prompt):
1711 1777 """simple prefilter function, for debugging"""
1712 1778 return self.handle_normal(line,continue_prompt)
1713 1779
1714 1780 # Set the default prefilter() function (this can be user-overridden)
1715 1781 prefilter = _prefilter
1716 1782
1717 1783 def handle_normal(self,line,continue_prompt=None,
1718 1784 pre=None,iFun=None,theRest=None):
1719 1785 """Handle normal input lines. Use as a template for handlers."""
1720 1786
1721 1787 # With autoindent on, we need some way to exit the input loop, and I
1722 1788 # don't want to force the user to have to backspace all the way to
1723 1789 # clear the line. The rule will be in this case, that either two
1724 1790 # lines of pure whitespace in a row, or a line of pure whitespace but
1725 1791 # of a size different to the indent level, will exit the input loop.
1726 1792 if (continue_prompt and self.autoindent and isspace(line) and
1727 1793 (line != self.indent_current or isspace(self.buffer[-1]))):
1728 1794 line = ''
1729 1795
1730 1796 self.log(line,continue_prompt)
1731 1797 self.update_cache(line)
1732 1798 return line
1733 1799
1734 1800 def handle_alias(self,line,continue_prompt=None,
1735 1801 pre=None,iFun=None,theRest=None):
1736 1802 """Handle alias input lines. """
1737 1803
1738 1804 theRest = esc_quotes(theRest)
1739 1805 line_out = "%s%s.call_alias('%s','%s')" % (pre,self.name,iFun,theRest)
1740 1806 self.log(line_out,continue_prompt)
1741 1807 self.update_cache(line_out)
1742 1808 return line_out
1743 1809
1744 1810 def handle_shell_escape(self, line, continue_prompt=None,
1745 1811 pre=None,iFun=None,theRest=None):
1746 1812 """Execute the line in a shell, empty return value"""
1747 1813
1748 1814 #print 'line in :', `line` # dbg
1749 1815 # Example of a special handler. Others follow a similar pattern.
1750 1816 if continue_prompt: # multi-line statements
1751 1817 if iFun.startswith('!!'):
1752 1818 print 'SyntaxError: !! is not allowed in multiline statements'
1753 1819 return pre
1754 1820 else:
1755 1821 cmd = ("%s %s" % (iFun[1:],theRest)) #.replace('"','\\"')
1756 1822 #line_out = '%s%s.system("%s")' % (pre,self.name,cmd)
1757 1823 line_out = '%s%s.system(r"""%s"""[:-1])' % (pre,self.name,cmd + "_")
1758 1824 #line_out = ('%s%s.system(' % (pre,self.name)) + repr(cmd) + ')'
1759 1825 else: # single-line input
1760 1826 if line.startswith('!!'):
1761 1827 # rewrite iFun/theRest to properly hold the call to %sx and
1762 1828 # the actual command to be executed, so handle_magic can work
1763 1829 # correctly
1764 1830 theRest = '%s %s' % (iFun[2:],theRest)
1765 1831 iFun = 'sx'
1766 1832 return self.handle_magic('%ssx %s' % (self.ESC_MAGIC,line[2:]),
1767 1833 continue_prompt,pre,iFun,theRest)
1768 1834 else:
1769 1835 #cmd = esc_quotes(line[1:])
1770 1836 cmd=line[1:]
1771 1837 #line_out = '%s.system("%s")' % (self.name,cmd)
1772 1838 line_out = '%s.system(r"""%s"""[:-1])' % (self.name,cmd +"_")
1773 1839 #line_out = ('%s.system(' % self.name) + repr(cmd)+ ')'
1774 1840 # update cache/log and return
1775 1841 self.log(line_out,continue_prompt)
1776 1842 self.update_cache(line_out) # readline cache gets normal line
1777 1843 #print 'line out r:', `line_out` # dbg
1778 1844 #print 'line out s:', line_out # dbg
1779 1845 return line_out
1780 1846
1781 1847 def handle_magic(self, line, continue_prompt=None,
1782 1848 pre=None,iFun=None,theRest=None):
1783 1849 """Execute magic functions.
1784 1850
1785 1851 Also log them with a prepended # so the log is clean Python."""
1786 1852
1787 1853 cmd = '%sipmagic("%s")' % (pre,esc_quotes('%s %s' % (iFun,theRest)))
1788 1854 self.log(cmd,continue_prompt)
1789 1855 self.update_cache(line)
1790 1856 #print 'in handle_magic, cmd=<%s>' % cmd # dbg
1791 1857 return cmd
1792 1858
1793 1859 def handle_auto(self, line, continue_prompt=None,
1794 1860 pre=None,iFun=None,theRest=None):
1795 1861 """Hande lines which can be auto-executed, quoting if requested."""
1796 1862
1797 1863 #print 'pre <%s> iFun <%s> rest <%s>' % (pre,iFun,theRest) # dbg
1798 1864
1799 1865 # This should only be active for single-line input!
1800 1866 if continue_prompt:
1801 1867 return line
1802 1868
1803 1869 if pre == self.ESC_QUOTE:
1804 1870 # Auto-quote splitting on whitespace
1805 1871 newcmd = '%s("%s")' % (iFun,'", "'.join(theRest.split()) )
1806 1872 elif pre == self.ESC_QUOTE2:
1807 1873 # Auto-quote whole string
1808 1874 newcmd = '%s("%s")' % (iFun,theRest)
1809 1875 else:
1810 1876 # Auto-paren
1811 1877 if theRest[0:1] in ('=','['):
1812 1878 # Don't autocall in these cases. They can be either
1813 1879 # rebindings of an existing callable's name, or item access
1814 1880 # for an object which is BOTH callable and implements
1815 1881 # __getitem__.
1816 1882 return '%s %s' % (iFun,theRest)
1817 1883 if theRest.endswith(';'):
1818 1884 newcmd = '%s(%s);' % (iFun.rstrip(),theRest[:-1])
1819 1885 else:
1820 1886 newcmd = '%s(%s)' % (iFun.rstrip(),theRest)
1821 1887
1822 1888 print >>Term.cout, self.outputcache.prompt1.auto_rewrite() + newcmd
1823 1889 # log what is now valid Python, not the actual user input (without the
1824 1890 # final newline)
1825 1891 self.log(newcmd,continue_prompt)
1826 1892 return newcmd
1827 1893
1828 1894 def handle_help(self, line, continue_prompt=None,
1829 1895 pre=None,iFun=None,theRest=None):
1830 1896 """Try to get some help for the object.
1831 1897
1832 1898 obj? or ?obj -> basic information.
1833 1899 obj?? or ??obj -> more details.
1834 1900 """
1835 1901
1836 1902 # We need to make sure that we don't process lines which would be
1837 1903 # otherwise valid python, such as "x=1 # what?"
1838 1904 try:
1839 1905 codeop.compile_command(line)
1840 1906 except SyntaxError:
1841 1907 # We should only handle as help stuff which is NOT valid syntax
1842 1908 if line[0]==self.ESC_HELP:
1843 1909 line = line[1:]
1844 1910 elif line[-1]==self.ESC_HELP:
1845 1911 line = line[:-1]
1846 1912 self.log('#?'+line)
1847 1913 self.update_cache(line)
1848 1914 if line:
1849 1915 self.magic_pinfo(line)
1850 1916 else:
1851 1917 page(self.usage,screen_lines=self.rc.screen_length)
1852 1918 return '' # Empty string is needed here!
1853 1919 except:
1854 1920 # Pass any other exceptions through to the normal handler
1855 1921 return self.handle_normal(line,continue_prompt)
1856 1922 else:
1857 1923 # If the code compiles ok, we should handle it normally
1858 1924 return self.handle_normal(line,continue_prompt)
1859 1925
1860 1926 def handle_emacs(self,line,continue_prompt=None,
1861 1927 pre=None,iFun=None,theRest=None):
1862 1928 """Handle input lines marked by python-mode."""
1863 1929
1864 1930 # Currently, nothing is done. Later more functionality can be added
1865 1931 # here if needed.
1866 1932
1867 1933 # The input cache shouldn't be updated
1868 1934
1869 1935 return line
1870 1936
1871 1937 def write(self,data):
1872 1938 """Write a string to the default output"""
1873 1939 Term.cout.write(data)
1874 1940
1875 1941 def write_err(self,data):
1876 1942 """Write a string to the default error output"""
1877 1943 Term.cerr.write(data)
1878 1944
1879 1945 def exit(self):
1880 1946 """Handle interactive exit.
1881 1947
1882 1948 This method sets the exit_now attribute."""
1883 1949
1884 1950 if self.rc.confirm_exit:
1885 1951 if ask_yes_no('Do you really want to exit ([y]/n)?','y'):
1886 1952 self.exit_now = True
1887 1953 else:
1888 1954 self.exit_now = True
1889 1955 return self.exit_now
1890 1956
1891 1957 def safe_execfile(self,fname,*where,**kw):
1892 1958 fname = os.path.expanduser(fname)
1893 1959
1894 1960 # find things also in current directory
1895 1961 dname = os.path.dirname(fname)
1896 1962 if not sys.path.count(dname):
1897 1963 sys.path.append(dname)
1898 1964
1899 1965 try:
1900 1966 xfile = open(fname)
1901 1967 except:
1902 1968 print >> Term.cerr, \
1903 1969 'Could not open file <%s> for safe execution.' % fname
1904 1970 return None
1905 1971
1906 1972 kw.setdefault('islog',0)
1907 1973 kw.setdefault('quiet',1)
1908 1974 kw.setdefault('exit_ignore',0)
1909 1975 first = xfile.readline()
1910 _LOGHEAD = str(self.LOGHEAD).split('\n',1)[0].strip()
1976 loghead = str(self.loghead_tpl).split('\n',1)[0].strip()
1911 1977 xfile.close()
1912 1978 # line by line execution
1913 if first.startswith(_LOGHEAD) or kw['islog']:
1979 if first.startswith(loghead) or kw['islog']:
1914 1980 print 'Loading log file <%s> one line at a time...' % fname
1915 1981 if kw['quiet']:
1916 1982 stdout_save = sys.stdout
1917 1983 sys.stdout = StringIO.StringIO()
1918 1984 try:
1919 1985 globs,locs = where[0:2]
1920 1986 except:
1921 1987 try:
1922 1988 globs = locs = where[0]
1923 1989 except:
1924 1990 globs = locs = globals()
1925 1991 badblocks = []
1926 1992
1927 1993 # we also need to identify indented blocks of code when replaying
1928 1994 # logs and put them together before passing them to an exec
1929 1995 # statement. This takes a bit of regexp and look-ahead work in the
1930 1996 # file. It's easiest if we swallow the whole thing in memory
1931 1997 # first, and manually walk through the lines list moving the
1932 1998 # counter ourselves.
1933 1999 indent_re = re.compile('\s+\S')
1934 2000 xfile = open(fname)
1935 2001 filelines = xfile.readlines()
1936 2002 xfile.close()
1937 2003 nlines = len(filelines)
1938 2004 lnum = 0
1939 2005 while lnum < nlines:
1940 2006 line = filelines[lnum]
1941 2007 lnum += 1
1942 2008 # don't re-insert logger status info into cache
1943 2009 if line.startswith('#log#'):
1944 2010 continue
1945 elif line.startswith('#%s'% self.ESC_MAGIC):
1946 self.update_cache(line[1:])
1947 line = magic2python(line)
1948 2011 elif line.startswith('#!'):
1949 2012 self.update_cache(line[1:])
1950 2013 else:
1951 2014 # build a block of code (maybe a single line) for execution
1952 2015 block = line
1953 2016 try:
1954 2017 next = filelines[lnum] # lnum has already incremented
1955 2018 except:
1956 2019 next = None
1957 2020 while next and indent_re.match(next):
1958 2021 block += next
1959 2022 lnum += 1
1960 2023 try:
1961 2024 next = filelines[lnum]
1962 2025 except:
1963 2026 next = None
1964 2027 # now execute the block of one or more lines
1965 2028 try:
1966 2029 exec block in globs,locs
1967 2030 self.update_cache(block.rstrip())
1968 2031 except SystemExit:
1969 2032 pass
1970 2033 except:
1971 2034 badblocks.append(block.rstrip())
1972 2035 if kw['quiet']: # restore stdout
1973 2036 sys.stdout.close()
1974 2037 sys.stdout = stdout_save
1975 2038 print 'Finished replaying log file <%s>' % fname
1976 2039 if badblocks:
1977 2040 print >> sys.stderr, ('\nThe following lines/blocks in file '
1978 2041 '<%s> reported errors:' % fname)
1979 2042
1980 2043 for badline in badblocks:
1981 2044 print >> sys.stderr, badline
1982 2045 else: # regular file execution
1983 2046 try:
1984 2047 execfile(fname,*where)
1985 2048 except SyntaxError:
1986 2049 etype,evalue = sys.exc_info()[:2]
1987 2050 self.SyntaxTB(etype,evalue,[])
1988 2051 warn('Failure executing file: <%s>' % fname)
1989 2052 except SystemExit,status:
1990 2053 if not kw['exit_ignore']:
1991 2054 self.InteractiveTB()
1992 2055 warn('Failure executing file: <%s>' % fname)
1993 2056 except:
1994 2057 self.InteractiveTB()
1995 2058 warn('Failure executing file: <%s>' % fname)
1996 2059
1997 2060 #************************* end of file <iplib.py> *****************************
@@ -1,735 +1,701 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 IPython -- An enhanced Interactive Python
4 4
5 5 Requires Python 2.1 or better.
6 6
7 7 This file contains the main make_IPython() starter function.
8 8
9 $Id: ipmaker.py 965 2005-12-28 23:23:09Z fperez $"""
9 $Id: ipmaker.py 966 2005-12-29 08:34:07Z fperez $"""
10 10
11 11 #*****************************************************************************
12 12 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
13 13 #
14 14 # Distributed under the terms of the BSD License. The full license is in
15 15 # the file COPYING, distributed as part of this software.
16 16 #*****************************************************************************
17 17
18 18 from IPython import Release
19 19 __author__ = '%s <%s>' % Release.authors['Fernando']
20 20 __license__ = Release.license
21 21 __version__ = Release.version
22 22
23 23 credits._Printer__data = """
24 24 Python: %s
25 25
26 26 IPython: Fernando Perez, Janko Hauser, Nathan Gray, and many users.
27 27 See http://ipython.scipy.org for more information.""" \
28 28 % credits._Printer__data
29 29
30 30 copyright._Printer__data += """
31 31
32 32 Copyright (c) 2001-2004 Fernando Perez, Janko Hauser, Nathan Gray.
33 33 All Rights Reserved."""
34 34
35 35 #****************************************************************************
36 36 # Required modules
37 37
38 38 # From the standard library
39 39 import __main__
40 40 import __builtin__
41 41 import os
42 42 import re
43 43 import sys
44 44 import types
45 45 from pprint import pprint,pformat
46 46
47 47 # Our own
48 48 from IPython import DPyGetOpt
49 49 from IPython.Struct import Struct
50 50 from IPython.OutputTrap import OutputTrap
51 51 from IPython.ConfigLoader import ConfigLoader
52 52 from IPython.iplib import InteractiveShell,qw_lol,import_fail_info
53 53 from IPython.usage import cmd_line_usage,interactive_usage
54 from IPython.Prompts import CachedOutput
55 54 from IPython.genutils import *
56 55
57 56 #-----------------------------------------------------------------------------
58 57 def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1,
59 58 rc_override=None,shell_class=InteractiveShell,
60 59 embedded=False,**kw):
61 60 """This is a dump of IPython into a single function.
62 61
63 62 Later it will have to be broken up in a sensible manner.
64 63
65 64 Arguments:
66 65
67 66 - argv: a list similar to sys.argv[1:]. It should NOT contain the desired
68 67 script name, b/c DPyGetOpt strips the first argument only for the real
69 68 sys.argv.
70 69
71 70 - user_ns: a dict to be used as the user's namespace."""
72 71
73 72 #----------------------------------------------------------------------
74 73 # Defaults and initialization
75 74
76 75 # For developer debugging, deactivates crash handler and uses pdb.
77 76 DEVDEBUG = False
78 77
79 78 if argv is None:
80 79 argv = sys.argv
81 80
82 81 # __IP is the main global that lives throughout and represents the whole
83 82 # application. If the user redefines it, all bets are off as to what
84 83 # happens.
85 84
86 85 # __IP is the name of he global which the caller will have accessible as
87 86 # __IP.name. We set its name via the first parameter passed to
88 87 # InteractiveShell:
89 88
90 89 IP = shell_class('__IP',user_ns=user_ns,user_global_ns=user_global_ns,
91 90 embedded=embedded,**kw)
92 91
93 92 # Put 'help' in the user namespace
94 93 from site import _Helper
95 94 IP.user_ns['help'] = _Helper()
96 95
97 96
98 97 if DEVDEBUG:
99 98 # For developer debugging only (global flag)
100 99 from IPython import ultraTB
101 100 sys.excepthook = ultraTB.VerboseTB(call_pdb=1)
102 101
103 102 IP.BANNER_PARTS = ['Python %s\n'
104 103 'Type "copyright", "credits" or "license" '
105 104 'for more information.\n'
106 105 % (sys.version.split('\n')[0],),
107 106 "IPython %s -- An enhanced Interactive Python."
108 107 % (__version__,),
109 108 """? -> Introduction to IPython's features.
110 109 %magic -> Information about IPython's 'magic' % functions.
111 110 help -> Python's own help system.
112 111 object? -> Details about 'object'. ?object also works, ?? prints more.
113 112 """ ]
114 113
115 114 IP.usage = interactive_usage
116 115
117 116 # Platform-dependent suffix and directory names. We use _ipython instead
118 117 # of .ipython under win32 b/c there's software that breaks with .named
119 118 # directories on that platform.
120 119 if os.name == 'posix':
121 120 rc_suffix = ''
122 121 ipdir_def = '.ipython'
123 122 else:
124 123 rc_suffix = '.ini'
125 124 ipdir_def = '_ipython'
126 125
127 126 # default directory for configuration
128 127 ipythondir = os.path.abspath(os.environ.get('IPYTHONDIR',
129 128 os.path.join(IP.home_dir,ipdir_def)))
130 129
131 130 # we need the directory where IPython itself is installed
132 131 import IPython
133 132 IPython_dir = os.path.dirname(IPython.__file__)
134 133 del IPython
135 134
136 135 #-------------------------------------------------------------------------
137 136 # Command line handling
138 137
139 138 # Valid command line options (uses DPyGetOpt syntax, like Perl's
140 139 # GetOpt::Long)
141 140
142 141 # Any key not listed here gets deleted even if in the file (like session
143 142 # or profile). That's deliberate, to maintain the rc namespace clean.
144 143
145 144 # Each set of options appears twice: under _conv only the names are
146 145 # listed, indicating which type they must be converted to when reading the
147 146 # ipythonrc file. And under DPyGetOpt they are listed with the regular
148 147 # DPyGetOpt syntax (=s,=i,:f,etc).
149 148
150 149 # Make sure there's a space before each end of line (they get auto-joined!)
151 150 cmdline_opts = ('autocall! autoindent! automagic! banner! cache_size|cs=i '
152 151 'c=s classic|cl color_info! colors=s confirm_exit! '
153 152 'debug! deep_reload! editor=s log|l messages! nosep pdb! '
154 153 'pprint! prompt_in1|pi1=s prompt_in2|pi2=s prompt_out|po=s '
155 154 'quick screen_length|sl=i prompts_pad_left=i '
156 155 'logfile|lf=s logplay|lp=s profile|p=s '
157 156 'readline! readline_merge_completions! '
158 157 'readline_omit__names! '
159 158 'rcfile=s separate_in|si=s separate_out|so=s '
160 159 'separate_out2|so2=s xmode=s wildcards_case_sensitive! '
161 160 'magic_docstrings system_verbose! '
162 161 'multi_line_specials! '
163 162 'autoedit_syntax!')
164 163
165 164 # Options that can *only* appear at the cmd line (not in rcfiles).
166 165
167 166 # The "ignore" option is a kludge so that Emacs buffers don't crash, since
168 167 # the 'C-c !' command in emacs automatically appends a -i option at the end.
169 168 cmdline_only = ('help ignore|i ipythondir=s Version upgrade '
170 169 'gthread! qthread! wthread! pylab! tk!')
171 170
172 171 # Build the actual name list to be used by DPyGetOpt
173 172 opts_names = qw(cmdline_opts) + qw(cmdline_only)
174 173
175 174 # Set sensible command line defaults.
176 175 # This should have everything from cmdline_opts and cmdline_only
177 176 opts_def = Struct(autocall = 1,
178 177 autoedit_syntax = 1,
179 178 autoindent=0,
180 179 automagic = 1,
181 180 banner = 1,
182 181 cache_size = 1000,
183 182 c = '',
184 183 classic = 0,
185 184 colors = 'NoColor',
186 185 color_info = 0,
187 186 confirm_exit = 1,
188 187 debug = 0,
189 188 deep_reload = 0,
190 189 editor = '0',
191 190 help = 0,
192 191 ignore = 0,
193 192 ipythondir = ipythondir,
194 193 log = 0,
195 194 logfile = '',
196 195 logplay = '',
197 196 multi_line_specials = 1,
198 197 messages = 1,
199 198 nosep = 0,
200 199 pdb = 0,
201 200 pprint = 0,
202 201 profile = '',
203 202 prompt_in1 = 'In [\\#]: ',
204 203 prompt_in2 = ' .\\D.: ',
205 204 prompt_out = 'Out[\\#]: ',
206 205 prompts_pad_left = 1,
207 206 quick = 0,
208 207 readline = 1,
209 208 readline_merge_completions = 1,
210 209 readline_omit__names = 0,
211 210 rcfile = 'ipythonrc' + rc_suffix,
212 211 screen_length = 0,
213 212 separate_in = '\n',
214 213 separate_out = '\n',
215 214 separate_out2 = '',
216 215 system_verbose = 0,
217 216 gthread = 0,
218 217 qthread = 0,
219 218 wthread = 0,
220 219 pylab = 0,
221 220 tk = 0,
222 221 upgrade = 0,
223 222 Version = 0,
224 223 xmode = 'Verbose',
225 224 wildcards_case_sensitive = 1,
226 225 magic_docstrings = 0, # undocumented, for doc generation
227 226 )
228 227
229 228 # Things that will *only* appear in rcfiles (not at the command line).
230 229 # Make sure there's a space before each end of line (they get auto-joined!)
231 230 rcfile_opts = { qwflat: 'include import_mod import_all execfile ',
232 231 qw_lol: 'import_some ',
233 232 # for things with embedded whitespace:
234 233 list_strings:'execute alias readline_parse_and_bind ',
235 234 # Regular strings need no conversion:
236 235 None:'readline_remove_delims ',
237 236 }
238 237 # Default values for these
239 238 rc_def = Struct(include = [],
240 239 import_mod = [],
241 240 import_all = [],
242 241 import_some = [[]],
243 242 execute = [],
244 243 execfile = [],
245 244 alias = [],
246 245 readline_parse_and_bind = [],
247 246 readline_remove_delims = '',
248 247 )
249 248
250 249 # Build the type conversion dictionary from the above tables:
251 250 typeconv = rcfile_opts.copy()
252 251 typeconv.update(optstr2types(cmdline_opts))
253 252
254 253 # FIXME: the None key appears in both, put that back together by hand. Ugly!
255 254 typeconv[None] += ' ' + rcfile_opts[None]
256 255
257 256 # Remove quotes at ends of all strings (used to protect spaces)
258 257 typeconv[unquote_ends] = typeconv[None]
259 258 del typeconv[None]
260 259
261 260 # Build the list we'll use to make all config decisions with defaults:
262 261 opts_all = opts_def.copy()
263 262 opts_all.update(rc_def)
264 263
265 264 # Build conflict resolver for recursive loading of config files:
266 265 # - preserve means the outermost file maintains the value, it is not
267 266 # overwritten if an included file has the same key.
268 267 # - add_flip applies + to the two values, so it better make sense to add
269 268 # those types of keys. But it flips them first so that things loaded
270 269 # deeper in the inclusion chain have lower precedence.
271 270 conflict = {'preserve': ' '.join([ typeconv[int],
272 271 typeconv[unquote_ends] ]),
273 272 'add_flip': ' '.join([ typeconv[qwflat],
274 273 typeconv[qw_lol],
275 274 typeconv[list_strings] ])
276 275 }
277 276
278 277 # Now actually process the command line
279 278 getopt = DPyGetOpt.DPyGetOpt()
280 279 getopt.setIgnoreCase(0)
281 280
282 281 getopt.parseConfiguration(opts_names)
283 282
284 283 try:
285 284 getopt.processArguments(argv)
286 285 except:
287 286 print cmd_line_usage
288 287 warn('\nError in Arguments: ' + `sys.exc_value`)
289 288 sys.exit(1)
290 289
291 290 # convert the options dict to a struct for much lighter syntax later
292 291 opts = Struct(getopt.optionValues)
293 292 args = getopt.freeValues
294 293
295 294 # this is the struct (which has default values at this point) with which
296 295 # we make all decisions:
297 296 opts_all.update(opts)
298 297
299 298 # Options that force an immediate exit
300 299 if opts_all.help:
301 300 page(cmd_line_usage)
302 301 sys.exit()
303 302
304 303 if opts_all.Version:
305 304 print __version__
306 305 sys.exit()
307 306
308 307 if opts_all.magic_docstrings:
309 308 IP.magic_magic('-latex')
310 309 sys.exit()
311 310
312 311 # Create user config directory if it doesn't exist. This must be done
313 312 # *after* getting the cmd line options.
314 313 if not os.path.isdir(opts_all.ipythondir):
315 314 IP.user_setup(opts_all.ipythondir,rc_suffix,'install')
316 315
317 316 # upgrade user config files while preserving a copy of the originals
318 317 if opts_all.upgrade:
319 318 IP.user_setup(opts_all.ipythondir,rc_suffix,'upgrade')
320 319
321 320 # check mutually exclusive options in the *original* command line
322 321 mutex_opts(opts,[qw('log logfile'),qw('rcfile profile'),
323 322 qw('classic profile'),qw('classic rcfile')])
324 323
325 # default logfilename used when -log is called.
326 IP.LOGDEF = 'ipython.log'
327
328 324 #---------------------------------------------------------------------------
329 325 # Log replay
330 326
331 327 # if -logplay, we need to 'become' the other session. That basically means
332 328 # replacing the current command line environment with that of the old
333 329 # session and moving on.
334 330
335 331 # this is needed so that later we know we're in session reload mode, as
336 332 # opts_all will get overwritten:
337 333 load_logplay = 0
338 334
339 335 if opts_all.logplay:
340 336 load_logplay = opts_all.logplay
341 337 opts_debug_save = opts_all.debug
342 338 try:
343 339 logplay = open(opts_all.logplay)
344 340 except IOError:
345 341 if opts_all.debug: IP.InteractiveTB()
346 342 warn('Could not open logplay file '+`opts_all.logplay`)
347 343 # restore state as if nothing had happened and move on, but make
348 344 # sure that later we don't try to actually load the session file
349 345 logplay = None
350 346 load_logplay = 0
351 347 del opts_all.logplay
352 348 else:
353 349 try:
354 350 logplay.readline()
355 351 logplay.readline();
356 352 # this reloads that session's command line
357 353 cmd = logplay.readline()[6:]
358 354 exec cmd
359 355 # restore the true debug flag given so that the process of
360 356 # session loading itself can be monitored.
361 357 opts.debug = opts_debug_save
362 358 # save the logplay flag so later we don't overwrite the log
363 359 opts.logplay = load_logplay
364 360 # now we must update our own structure with defaults
365 361 opts_all.update(opts)
366 362 # now load args
367 363 cmd = logplay.readline()[6:]
368 364 exec cmd
369 365 logplay.close()
370 366 except:
371 367 logplay.close()
372 368 if opts_all.debug: IP.InteractiveTB()
373 369 warn("Logplay file lacking full configuration information.\n"
374 370 "I'll try to read it, but some things may not work.")
375 371
376 372 #-------------------------------------------------------------------------
377 373 # set up output traps: catch all output from files, being run, modules
378 374 # loaded, etc. Then give it to the user in a clean form at the end.
379 375
380 376 msg_out = 'Output messages. '
381 377 msg_err = 'Error messages. '
382 378 msg_sep = '\n'
383 379 msg = Struct(config = OutputTrap('Configuration Loader',msg_out,
384 380 msg_err,msg_sep,debug,
385 381 quiet_out=1),
386 382 user_exec = OutputTrap('User File Execution',msg_out,
387 383 msg_err,msg_sep,debug),
388 384 logplay = OutputTrap('Log Loader',msg_out,
389 385 msg_err,msg_sep,debug),
390 386 summary = ''
391 387 )
392 388
393 389 #-------------------------------------------------------------------------
394 390 # Process user ipythonrc-type configuration files
395 391
396 392 # turn on output trapping and log to msg.config
397 393 # remember that with debug on, trapping is actually disabled
398 394 msg.config.trap_all()
399 395
400 396 # look for rcfile in current or default directory
401 397 try:
402 398 opts_all.rcfile = filefind(opts_all.rcfile,opts_all.ipythondir)
403 399 except IOError:
404 400 if opts_all.debug: IP.InteractiveTB()
405 401 warn('Configuration file %s not found. Ignoring request.'
406 402 % (opts_all.rcfile) )
407 403
408 404 # 'profiles' are a shorthand notation for config filenames
409 405 if opts_all.profile:
410 406 try:
411 407 opts_all.rcfile = filefind('ipythonrc-' + opts_all.profile
412 408 + rc_suffix,
413 409 opts_all.ipythondir)
414 410 except IOError:
415 411 if opts_all.debug: IP.InteractiveTB()
416 412 opts.profile = '' # remove profile from options if invalid
417 413 warn('Profile configuration file %s not found. Ignoring request.'
418 414 % (opts_all.profile) )
419 415
420 416 # load the config file
421 417 rcfiledata = None
422 418 if opts_all.quick:
423 419 print 'Launching IPython in quick mode. No config file read.'
424 420 elif opts_all.classic:
425 421 print 'Launching IPython in classic mode. No config file read.'
426 422 elif opts_all.rcfile:
427 423 try:
428 424 cfg_loader = ConfigLoader(conflict)
429 425 rcfiledata = cfg_loader.load(opts_all.rcfile,typeconv,
430 426 'include',opts_all.ipythondir,
431 427 purge = 1,
432 428 unique = conflict['preserve'])
433 429 except:
434 430 IP.InteractiveTB()
435 431 warn('Problems loading configuration file '+
436 432 `opts_all.rcfile`+
437 433 '\nStarting with default -bare bones- configuration.')
438 434 else:
439 435 warn('No valid configuration file found in either currrent directory\n'+
440 436 'or in the IPython config. directory: '+`opts_all.ipythondir`+
441 437 '\nProceeding with internal defaults.')
442 438
443 439 #------------------------------------------------------------------------
444 440 # Set exception handlers in mode requested by user.
445 441 otrap = OutputTrap(trap_out=1) # trap messages from magic_xmode
446 442 IP.magic_xmode(opts_all.xmode)
447 443 otrap.release_out()
448 444
449 445 #------------------------------------------------------------------------
450 446 # Execute user config
451 447
452 448 # Create a valid config structure with the right precedence order:
453 449 # defaults < rcfile < command line. This needs to be in the instance, so
454 450 # that method calls below that rely on it find it.
455 451 IP.rc = rc_def.copy()
456 452
457 453 # Work with a local alias inside this routine to avoid unnecessary
458 454 # attribute lookups.
459 455 IP_rc = IP.rc
460 456
461 457 IP_rc.update(opts_def)
462 458 if rcfiledata:
463 459 # now we can update
464 460 IP_rc.update(rcfiledata)
465 461 IP_rc.update(opts)
466 462 IP_rc.update(rc_override)
467 463
468 464 # Store the original cmd line for reference:
469 465 IP_rc.opts = opts
470 466 IP_rc.args = args
471 467
472 468 # create a *runtime* Struct like rc for holding parameters which may be
473 469 # created and/or modified by runtime user extensions.
474 470 IP.runtime_rc = Struct()
475 471
476 472 # from this point on, all config should be handled through IP_rc,
477 473 # opts* shouldn't be used anymore.
478 474
479 475 # add personal .ipython dir to sys.path so that users can put things in
480 476 # there for customization
481 477 sys.path.append(IP_rc.ipythondir)
482 478 sys.path.insert(0, '') # add . to sys.path. Fix from Prabhu Ramachandran
483 479
484 480 # update IP_rc with some special things that need manual
485 481 # tweaks. Basically options which affect other options. I guess this
486 482 # should just be written so that options are fully orthogonal and we
487 483 # wouldn't worry about this stuff!
488 484
489 485 if IP_rc.classic:
490 486 IP_rc.quick = 1
491 487 IP_rc.cache_size = 0
492 488 IP_rc.pprint = 0
493 489 IP_rc.prompt_in1 = '>>> '
494 490 IP_rc.prompt_in2 = '... '
495 491 IP_rc.prompt_out = ''
496 492 IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
497 493 IP_rc.colors = 'NoColor'
498 494 IP_rc.xmode = 'Plain'
499 495
500 496 # configure readline
501 497 # Define the history file for saving commands in between sessions
502 498 if IP_rc.profile:
503 499 histfname = 'history-%s' % IP_rc.profile
504 500 else:
505 501 histfname = 'history'
506 502 IP.histfile = os.path.join(opts_all.ipythondir,histfname)
507 503
508 504 # update exception handlers with rc file status
509 505 otrap.trap_out() # I don't want these messages ever.
510 506 IP.magic_xmode(IP_rc.xmode)
511 507 otrap.release_out()
512 508
513 509 # activate logging if requested and not reloading a log
514 510 if IP_rc.logplay:
515 511 IP.magic_logstart(IP_rc.logplay + ' append')
516 512 elif IP_rc.logfile:
517 513 IP.magic_logstart(IP_rc.logfile)
518 514 elif IP_rc.log:
519 515 IP.magic_logstart()
520 516
521 517 # find user editor so that it we don't have to look it up constantly
522 518 if IP_rc.editor.strip()=='0':
523 519 try:
524 520 ed = os.environ['EDITOR']
525 521 except KeyError:
526 522 if os.name == 'posix':
527 523 ed = 'vi' # the only one guaranteed to be there!
528 524 else:
529 525 ed = 'notepad' # same in Windows!
530 526 IP_rc.editor = ed
531 527
532 528 # Keep track of whether this is an embedded instance or not (useful for
533 529 # post-mortems).
534 530 IP_rc.embedded = IP.embedded
535 531
536 532 # Recursive reload
537 533 try:
538 534 from IPython import deep_reload
539 535 if IP_rc.deep_reload:
540 536 __builtin__.reload = deep_reload.reload
541 537 else:
542 538 __builtin__.dreload = deep_reload.reload
543 539 del deep_reload
544 540 except ImportError:
545 541 pass
546 542
547 543 # Save the current state of our namespace so that the interactive shell
548 544 # can later know which variables have been created by us from config files
549 545 # and loading. This way, loading a file (in any way) is treated just like
550 546 # defining things on the command line, and %who works as expected.
551 547
552 548 # DON'T do anything that affects the namespace beyond this point!
553 549 IP.internal_ns.update(__main__.__dict__)
554 550
555 551 #IP.internal_ns.update(locals()) # so our stuff doesn't show up in %who
556 552
557 553 # Now run through the different sections of the users's config
558 554 if IP_rc.debug:
559 555 print 'Trying to execute the following configuration structure:'
560 556 print '(Things listed first are deeper in the inclusion tree and get'
561 557 print 'loaded first).\n'
562 558 pprint(IP_rc.__dict__)
563 559
564 560 for mod in IP_rc.import_mod:
565 561 try:
566 562 exec 'import '+mod in IP.user_ns
567 563 except :
568 564 IP.InteractiveTB()
569 565 import_fail_info(mod)
570 566
571 567 for mod_fn in IP_rc.import_some:
572 568 if mod_fn == []: break
573 569 mod,fn = mod_fn[0],','.join(mod_fn[1:])
574 570 try:
575 571 exec 'from '+mod+' import '+fn in IP.user_ns
576 572 except :
577 573 IP.InteractiveTB()
578 574 import_fail_info(mod,fn)
579 575
580 576 for mod in IP_rc.import_all:
581 577 try:
582 578 exec 'from '+mod+' import *' in IP.user_ns
583 579 except :
584 580 IP.InteractiveTB()
585 581 import_fail_info(mod)
586 582
587 583 for code in IP_rc.execute:
588 584 try:
589 585 exec code in IP.user_ns
590 586 except:
591 587 IP.InteractiveTB()
592 588 warn('Failure executing code: ' + `code`)
593 589
594 590 # Execute the files the user wants in ipythonrc
595 591 for file in IP_rc.execfile:
596 592 try:
597 593 file = filefind(file,sys.path+[IPython_dir])
598 594 except IOError:
599 595 warn(itpl('File $file not found. Skipping it.'))
600 596 else:
601 597 IP.safe_execfile(os.path.expanduser(file),IP.user_ns)
602 598
603 599 # release stdout and stderr and save config log into a global summary
604 600 msg.config.release_all()
605 601 if IP_rc.messages:
606 602 msg.summary += msg.config.summary_all()
607 603
608 604 #------------------------------------------------------------------------
609 605 # Setup interactive session
610 606
611 607 # Now we should be fully configured. We can then execute files or load
612 608 # things only needed for interactive use. Then we'll open the shell.
613 609
614 610 # Take a snapshot of the user namespace before opening the shell. That way
615 611 # we'll be able to identify which things were interactively defined and
616 612 # which were defined through config files.
617 613 IP.user_config_ns = IP.user_ns.copy()
618 614
619 615 # Force reading a file as if it were a session log. Slower but safer.
620 616 if load_logplay:
621 617 print 'Replaying log...'
622 618 try:
623 619 if IP_rc.debug:
624 620 logplay_quiet = 0
625 621 else:
626 622 logplay_quiet = 1
627 623
628 624 msg.logplay.trap_all()
629 625 IP.safe_execfile(load_logplay,IP.user_ns,
630 626 islog = 1, quiet = logplay_quiet)
631 627 msg.logplay.release_all()
632 628 if IP_rc.messages:
633 629 msg.summary += msg.logplay.summary_all()
634 630 except:
635 631 warn('Problems replaying logfile %s.' % load_logplay)
636 632 IP.InteractiveTB()
637 633
638 634 # Load remaining files in command line
639 635 msg.user_exec.trap_all()
640 636
641 637 # Do NOT execute files named in the command line as scripts to be loaded
642 638 # by embedded instances. Doing so has the potential for an infinite
643 639 # recursion if there are exceptions thrown in the process.
644 640
645 641 # XXX FIXME: the execution of user files should be moved out to after
646 642 # ipython is fully initialized, just as if they were run via %run at the
647 643 # ipython prompt. This would also give them the benefit of ipython's
648 644 # nice tracebacks.
649 645
650 646 if not embedded and IP_rc.args:
651 647 name_save = IP.user_ns['__name__']
652 648 IP.user_ns['__name__'] = '__main__'
653 649 try:
654 650 # Set our own excepthook in case the user code tries to call it
655 651 # directly. This prevents triggering the IPython crash handler.
656 652 old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook
657 653 for run in args:
658 654 IP.safe_execfile(run,IP.user_ns)
659 655 finally:
660 656 # Reset our crash handler in place
661 657 sys.excepthook = old_excepthook
662 658
663 659 IP.user_ns['__name__'] = name_save
664 660
665 661 msg.user_exec.release_all()
666 662 if IP_rc.messages:
667 663 msg.summary += msg.user_exec.summary_all()
668 664
669 665 # since we can't specify a null string on the cmd line, 0 is the equivalent:
670 666 if IP_rc.nosep:
671 667 IP_rc.separate_in = IP_rc.separate_out = IP_rc.separate_out2 = '0'
672 668 if IP_rc.separate_in == '0': IP_rc.separate_in = ''
673 669 if IP_rc.separate_out == '0': IP_rc.separate_out = ''
674 670 if IP_rc.separate_out2 == '0': IP_rc.separate_out2 = ''
675 671 IP_rc.separate_in = IP_rc.separate_in.replace('\\n','\n')
676 672 IP_rc.separate_out = IP_rc.separate_out.replace('\\n','\n')
677 673 IP_rc.separate_out2 = IP_rc.separate_out2.replace('\\n','\n')
678 674
679 675 # Determine how many lines at the bottom of the screen are needed for
680 676 # showing prompts, so we can know wheter long strings are to be printed or
681 677 # paged:
682 678 num_lines_bot = IP_rc.separate_in.count('\n')+1
683 679 IP_rc.screen_length = IP_rc.screen_length - num_lines_bot
684 # Initialize cache, set in/out prompts and printing system
685 IP.outputcache = CachedOutput(IP_rc.cache_size,
686 IP_rc.pprint,
687 input_sep = IP_rc.separate_in,
688 output_sep = IP_rc.separate_out,
689 output_sep2 = IP_rc.separate_out2,
690 ps1 = IP_rc.prompt_in1,
691 ps2 = IP_rc.prompt_in2,
692 ps_out = IP_rc.prompt_out,
693 user_ns = IP.user_ns,
694 input_hist = IP.input_hist,
695 pad_left = IP_rc.prompts_pad_left)
696
697 # user may have over-ridden the default print hook:
698 try:
699 IP.outputcache.__class__.display = IP.hooks.display
700 except AttributeError:
701 pass
702 680
703 # Set calling of pdb on exceptions
704 IP.InteractiveTB.call_pdb = IP_rc.pdb
705
706 # I don't like assigning globally to sys, because it means when embedding
707 # instances, each embedded instance overrides the previous choice. But
708 # sys.displayhook seems to be called internally by exec, so I don't see a
709 # way around it.
710 sys.displayhook = IP.outputcache
711
712 # we need to know globally if we're caching i/o or not
713 IP.do_full_cache = IP.outputcache.do_full_cache
714
715 681 # configure startup banner
716 682 if IP_rc.c: # regular python doesn't print the banner with -c
717 683 IP_rc.banner = 0
718 684 if IP_rc.banner:
719 685 BANN_P = IP.BANNER_PARTS
720 686 else:
721 687 BANN_P = []
722 688
723 689 if IP_rc.profile: BANN_P.append('IPython profile: %s\n' % IP_rc.profile)
724 690
725 691 # add message log (possibly empty)
726 692 if msg.summary: BANN_P.append(msg.summary)
727 693 # Final banner is a string
728 694 IP.BANNER = '\n'.join(BANN_P)
729 695
730 696 # Finalize the IPython instance. This assumes the rc structure is fully
731 697 # in place.
732 698 IP.post_config_initialization()
733 699
734 700 return IP
735 701 #************************ end of file <ipmaker.py> **************************
@@ -1,585 +1,585 b''
1 1 # -*- coding: utf-8 -*-
2 2 #*****************************************************************************
3 3 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
4 4 #
5 5 # Distributed under the terms of the BSD License. The full license is in
6 6 # the file COPYING, distributed as part of this software.
7 7 #*****************************************************************************
8 8
9 # $Id: usage.py 960 2005-12-28 06:51:01Z fperez $
9 # $Id: usage.py 966 2005-12-29 08:34:07Z fperez $
10 10
11 11 from IPython import Release
12 12 __author__ = '%s <%s>' % Release.authors['Fernando']
13 13 __license__ = Release.license
14 14 __version__ = Release.version
15 15
16 16 __doc__ = """
17 17 IPython -- An enhanced Interactive Python
18 18 =========================================
19 19
20 20 A Python shell with automatic history (input and output), dynamic object
21 21 introspection, easier configuration, command completion, access to the system
22 22 shell and more.
23 23
24 24 IPython can also be embedded in running programs. See EMBEDDING below.
25 25
26 26
27 27 USAGE
28 28 ipython [options] files
29 29
30 30 If invoked with no options, it executes all the files listed in
31 31 sequence and drops you into the interpreter while still acknowledging
32 32 any options you may have set in your ipythonrc file. This behavior is
33 33 different from standard Python, which when called as python -i will
34 34 only execute one file and will ignore your configuration setup.
35 35
36 36 Please note that some of the configuration options are not available at
37 37 the command line, simply because they are not practical here. Look into
38 38 your ipythonrc configuration file for details on those. This file
39 39 typically installed in the $HOME/.ipython directory.
40 40
41 41 For Windows users, $HOME resolves to C:\\Documents and
42 42 Settings\\YourUserName in most instances, and _ipython is used instead
43 43 of .ipython, since some Win32 programs have problems with dotted names
44 44 in directories.
45 45
46 46 In the rest of this text, we will refer to this directory as
47 47 IPYTHONDIR.
48 48
49 49
50 50 SPECIAL THREADING OPTIONS
51 51 The following special options are ONLY valid at the beginning of the
52 52 command line, and not later. This is because they control the initial-
53 53 ization of ipython itself, before the normal option-handling mechanism
54 54 is active.
55 55
56 56 -gthread, -qthread, -wthread, -pylab
57 57
58 58 Only ONE of these can be given, and it can only be given as the
59 59 first option passed to IPython (it will have no effect in any
60 60 other position). They provide threading support for the GTK, QT
61 61 and WXWidgets toolkits, and for the matplotlib library.
62 62
63 63 With any of the first three options, IPython starts running a
64 64 separate thread for the graphical toolkit's operation, so that
65 65 you can open and control graphical elements from within an
66 66 IPython command line, without blocking. All three provide
67 67 essentially the same functionality, respectively for GTK, QT and
68 68 WXWidgets (via their Python interfaces).
69 69
70 70 If -pylab is given, IPython loads special support for the mat-
71 71 plotlib library (http://matplotlib.sourceforge.net), allowing
72 72 interactive usage of any of its backends as defined in the
73 73 user's .matplotlibrc file. It automatically activates GTK, QT
74 74 or WX threading for IPyhton if the choice of matplotlib backend
75 75 requires it. It also modifies the %run command to correctly
76 76 execute (without blocking) any matplotlib-based script which
77 77 calls show() at the end.
78 78
79 79 -tk The -g/q/wthread options, and -pylab (if matplotlib is
80 80 configured to use GTK, QT or WX), will normally block Tk
81 81 graphical interfaces. This means that when GTK, QT or WX
82 82 threading is active, any attempt to open a Tk GUI will result in
83 83 a dead window, and possibly cause the Python interpreter to
84 84 crash. An extra option, -tk, is available to address this
85 85 issue. It can ONLY be given as a SECOND option after any of the
86 86 above (-gthread, -qthread, -wthread or -pylab).
87 87
88 88 If -tk is given, IPython will try to coordinate Tk threading
89 89 with GTK, QT or WX. This is however potentially unreliable, and
90 90 you will have to test on your platform and Python configuration
91 91 to determine whether it works for you. Debian users have
92 92 reported success, apparently due to the fact that Debian builds
93 93 all of Tcl, Tk, Tkinter and Python with pthreads support. Under
94 94 other Linux environments (such as Fedora Core 2/3), this option
95 95 has caused random crashes and lockups of the Python interpreter.
96 96 Under other operating systems (Mac OSX and Windows), you'll need
97 97 to try it to find out, since currently no user reports are
98 98 available.
99 99
100 100 There is unfortunately no way for IPython to determine at run-
101 101 time whether -tk will work reliably or not, so you will need to
102 102 do some experiments before relying on it for regular work.
103 103
104 104 A WARNING ABOUT SIGNALS AND THREADS
105 105
106 106 When any of the thread systems (GTK, QT or WX) are active, either
107 107 directly or via -pylab with a threaded backend, it is impossible to
108 108 interrupt long-running Python code via Ctrl-C. IPython can not pass
109 109 the KeyboardInterrupt exception (or the underlying SIGINT) across
110 110 threads, so any long-running process started from IPython will run to
111 111 completion, or will have to be killed via an external (OS-based)
112 112 mechanism.
113 113
114 114 To the best of my knowledge, this limitation is imposed by the Python
115 115 interpreter itself, and it comes from the difficulty of writing
116 116 portable signal/threaded code. If any user is an expert on this topic
117 117 and can suggest a better solution, I would love to hear about it. In
118 118 the IPython sources, look at the Shell.py module, and in particular at
119 119 the runcode() method.
120 120
121 121 REGULAR OPTIONS
122 122 After the above threading options have been given, regular options can
123 123 follow in any order. All options can be abbreviated to their shortest
124 124 non-ambiguous form and are case-sensitive. One or two dashes can be
125 125 used. Some options have an alternate short form, indicated after a |.
126 126
127 127 Most options can also be set from your ipythonrc configuration file.
128 128 See the provided examples for assistance. Options given on the comman-
129 129 dline override the values set in the ipythonrc file.
130 130
131 131 All options with a [no] prepended can be specified in negated form
132 132 (using -nooption instead of -option) to turn the feature off.
133 133
134 134 -h, --help
135 135 Show summary of options.
136 136
137 137 -pylab This can only be given as the first option passed to IPython (it
138 138 will have no effect in any other position). It adds special sup-
139 139 port for the matplotlib library (http://matplotlib.source-
140 140 forge.net), allowing interactive usage of any of its backends as
141 141 defined in the user’s .matplotlibrc file. It automatically
142 142 activates GTK or WX threading for IPyhton if the choice of mat-
143 143 plotlib backend requires it. It also modifies the @run command
144 144 to correctly execute (without blocking) any matplotlib-based
145 145 script which calls show() at the end.
146 146
147 147 -[no]autocall
148 148 Make IPython automatically call any callable object even if you
149 149 didn’t type explicit parentheses. For example, ’str 43’ becomes
150 150 ’str(43)’ automatically.
151 151
152 152 -[no]autoindent
153 153 Turn automatic indentation on/off.
154 154
155 155 -[no]automagic
156 156 Make magic commands automatic (without needing their first char-
157 157 acter to be %). Type %magic at the IPython prompt for more
158 158 information.
159 159
160 160 -[no]autoedit_syntax
161 161 When a syntax error occurs after editing a file, automatically
162 162 open the file to the trouble causing line for convenient fixing.
163 163
164 164 -[no]banner
165 165 Print the intial information banner (default on).
166 166
167 167 -c <command>
168 168 Execute the given command string, and set sys.argv to [’c’].
169 169 This is similar to the -c option in the normal Python inter-
170 170 preter.
171 171
172 172 -cache_size|cs <n>
173 173 Size of the output cache (maximum number of entries to hold in
174 174 memory). The default is 1000, you can change it permanently in
175 175 your config file. Setting it to 0 completely disables the
176 176 caching system, and the minimum value accepted is 20 (if you
177 177 provide a value less than 20, it is reset to 0 and a warning is
178 178 issued). This limit is defined because otherwise you’ll spend
179 179 more time re-flushing a too small cache than working.
180 180
181 181 -classic|cl
182 182 Gives IPython a similar feel to the classic Python prompt.
183 183
184 184 -colors <scheme>
185 185 Color scheme for prompts and exception reporting. Currently
186 186 implemented: NoColor, Linux, and LightBG.
187 187
188 188 -[no]color_info
189 189 IPython can display information about objects via a set of func-
190 190 tions, and optionally can use colors for this, syntax highlight-
191 191 ing source code and various other elements. However, because
192 192 this information is passed through a pager (like ’less’) and
193 193 many pagers get confused with color codes, this option is off by
194 194 default. You can test it and turn it on permanently in your
195 195 ipythonrc file if it works for you. As a reference, the ’less’
196 196 pager supplied with Mandrake 8.2 works ok, but that in RedHat
197 197 7.2 doesn’t.
198 198
199 199 Test it and turn it on permanently if it works with your system.
200 200 The magic function @color_info allows you to toggle this inter-
201 201 actively for testing.
202 202
203 203 -[no]confirm_exit
204 204 Set to confirm when you try to exit IPython with an EOF (Con-
205 205 trol-D in Unix, Control-Z/Enter in Windows). Note that using the
206 206 magic functions @Exit or @Quit you can force a direct exit,
207 207 bypassing any confirmation.
208 208
209 209 -[no]debug
210 210 Show information about the loading process. Very useful to pin
211 211 down problems with your configuration files or to get details
212 212 about session restores.
213 213
214 214 -[no]deep_reload
215 215 IPython can use the deep_reload module which reloads changes in
216 216 modules recursively (it replaces the reload() function, so you
217 217 don’t need to change anything to use it). deep_reload() forces a
218 218 full reload of modules whose code may have changed, which the
219 219 default reload() function does not.
220 220
221 221 When deep_reload is off, IPython will use the normal reload(),
222 222 but deep_reload will still be available as dreload(). This fea-
223 223 ture is off by default [which means that you have both normal
224 224 reload() and dreload()].
225 225
226 226 -editor <name>
227 227 Which editor to use with the @edit command. By default, IPython
228 228 will honor your EDITOR environment variable (if not set, vi is
229 229 the Unix default and notepad the Windows one). Since this editor
230 230 is invoked on the fly by IPython and is meant for editing small
231 231 code snippets, you may want to use a small, lightweight editor
232 232 here (in case your default EDITOR is something like Emacs).
233 233
234 234 -ipythondir <name>
235 235 The name of your IPython configuration directory IPYTHONDIR.
236 236 This can also be specified through the environment variable
237 237 IPYTHONDIR.
238 238
239 -log|l Generate a log file of all input. The file is named ipython.log
240 in your current directory (which prevents logs from multiple
241 IPython sessions from trampling each other). You can use this to
242 later restore a session by loading your logfile as a file to be
243 executed with option -logplay (see below).
239 -log|l Generate a log file of all input. The file is named
240 ipython_log.py in your current directory (which prevents logs
241 from multiple IPython sessions from trampling each other). You
242 can use this to later restore a session by loading your logfile
243 as a file to be executed with option -logplay (see below).
244 244
245 245 -logfile|lf
246 Specifu the name of your logfile.
246 Specify the name of your logfile.
247 247
248 248 -logplay|lp
249 249 Replay a previous log. For restoring a session as close as pos-
250 250 sible to the state you left it in, use this option (don’t just
251 251 run the logfile). With -logplay, IPython will try to reconstruct
252 252 the previous working environment in full, not just execute the
253 253 commands in the logfile.
254 254 When a session is restored, logging is automatically turned on
255 255 again with the name of the logfile it was invoked with (it is
256 256 read from the log header). So once you’ve turned logging on for
257 257 a session, you can quit IPython and reload it as many times as
258 258 you want and it will continue to log its history and restore
259 259 from the beginning every time.
260 260
261 261 Caveats: there are limitations in this option. The history vari-
262 262 ables _i*,_* and _dh don’t get restored properly. In the future
263 263 we will try to implement full session saving by writing and
264 264 retrieving a failed because of inherent limitations of Python’s
265 265 Pickle module, so this may have to wait.
266 266
267 267 -[no]messages
268 268 Print messages which IPython collects about its startup process
269 269 (default on).
270 270
271 271 -[no]pdb
272 272 Automatically call the pdb debugger after every uncaught excep-
273 273 tion. If you are used to debugging using pdb, this puts you
274 274 automatically inside of it after any call (either in IPython or
275 275 in code called by it) which triggers an exception which goes
276 276 uncaught.
277 277
278 278 -[no]pprint
279 279 IPython can optionally use the pprint (pretty printer) module
280 280 for displaying results. pprint tends to give a nicer display of
281 281 nested data structures. If you like it, you can turn it on per-
282 282 manently in your config file (default off).
283 283
284 284 -profile|p <name>
285 285 Assume that your config file is ipythonrc-<name> (looks in cur-
286 286 rent dir first, then in IPYTHONDIR). This is a quick way to keep
287 287 and load multiple config files for different tasks, especially
288 288 if you use the include option of config files. You can keep a
289 289 basic IPYTHONDIR/ipythonrc file and then have other ’profiles’
290 290 which include this one and load extra things for particular
291 291 tasks. For example:
292 292
293 293 1) $HOME/.ipython/ipythonrc : load basic things you always want.
294 294 2) $HOME/.ipython/ipythonrc-math : load (1) and basic math-
295 295 related modules.
296 296 3) $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and
297 297 plotting modules.
298 298
299 299 Since it is possible to create an endless loop by having circu-
300 300 lar file inclusions, IPython will stop if it reaches 15 recur-
301 301 sive inclusions.
302 302
303 303 -prompt_in1|pi1 <string>
304 304 Specify the string used for input prompts. Note that if you are
305 305 using numbered prompts, the number is represented with a ’\#’ in
306 306 the string. Don’t forget to quote strings with spaces embedded
307 307 in them. Default: ’In [\#]:’.
308 308
309 309 Most bash-like escapes can be used to customize IPython’s
310 310 prompts, as well as a few additional ones which are IPython-spe-
311 311 cific. All valid prompt escapes are described in detail in the
312 312 Customization section of the IPython HTML/PDF manual.
313 313
314 314 -prompt_in2|pi2 <string>
315 315 Similar to the previous option, but used for the continuation
316 316 prompts. The special sequence ’\D’ is similar to ’\#’, but with
317 317 all digits replaced dots (so you can have your continuation
318 318 prompt aligned with your input prompt). Default: ’ .\D.:’
319 319 (note three spaces at the start for alignment with ’In [\#]’).
320 320
321 321 -prompt_out|po <string>
322 322 String used for output prompts, also uses numbers like
323 323 prompt_in1. Default: ’Out[\#]:’.
324 324
325 325 -quick Start in bare bones mode (no config file loaded).
326 326
327 327 -rcfile <name>
328 328 Name of your IPython resource configuration file. normally
329 329 IPython loads ipythonrc (from current directory) or
330 330 IPYTHONDIR/ipythonrc. If the loading of your config file fails,
331 331 IPython starts with a bare bones configuration (no modules
332 332 loaded at all).
333 333
334 334 -[no]readline
335 335 Use the readline library, which is needed to support name com-
336 336 pletion and command history, among other things. It is enabled
337 337 by default, but may cause problems for users of X/Emacs in
338 338 Python comint or shell buffers.
339 339
340 340 Note that emacs ’eterm’ buffers (opened with M-x term) support
341 341 IPython’s readline and syntax coloring fine, only ’emacs’ (M-x
342 342 shell and C-c !) buffers do not.
343 343
344 344 -screen_length|sl <n>
345 345 Number of lines of your screen. This is used to control print-
346 346 ing of very long strings. Strings longer than this number of
347 347 lines will be sent through a pager instead of directly printed.
348 348
349 349 The default value for this is 0, which means IPython will auto-
350 350 detect your screen size every time it needs to print certain
351 351 potentially long strings (this doesn’t change the behavior of
352 352 the ’print’ keyword, it’s only triggered internally). If for
353 353 some reason this isn’t working well (it needs curses support),
354 354 specify it yourself. Otherwise don’t change the default.
355 355
356 356 -separate_in|si <string>
357 357 Separator before input prompts. Default ’0.
358 358
359 359 -separate_out|so <string>
360 360 Separator before output prompts. Default: 0 (nothing).
361 361
362 362 -separate_out2|so2 <string>
363 363 Separator after output prompts. Default: 0 (nothing).
364 364
365 365 -nosep Shorthand for ’-separate_in 0 -separate_out 0 -separate_out2 0’.
366 366 Simply removes all input/output separators.
367 367
368 368 -upgrade
369 369 Allows you to upgrade your IPYTHONDIR configuration when you
370 370 install a new version of IPython. Since new versions may
371 371 include new command lines options or example files, this copies
372 372 updated ipythonrc-type files. However, it backs up (with a .old
373 373 extension) all files which it overwrites so that you can merge
374 374 back any custimizations you might have in your personal files.
375 375
376 376 -Version
377 377 Print version information and exit.
378 378
379 379 -xmode <modename>
380 380 Mode for exception reporting. The valid modes are Plain, Con-
381 381 text, and Verbose.
382 382
383 383 - Plain: similar to python’s normal traceback printing.
384 384
385 385 - Context: prints 5 lines of context source code around each
386 386 line in the traceback.
387 387
388 388 - Verbose: similar to Context, but additionally prints the vari-
389 389 ables currently visible where the exception happened (shortening
390 390 their strings if too long). This can potentially be very slow,
391 391 if you happen to have a huge data structure whose string repre-
392 392 sentation is complex to compute. Your computer may appear to
393 393 freeze for a while with cpu usage at 100%. If this occurs, you
394 394 can cancel the traceback with Ctrl-C (maybe hitting it more than
395 395 once).
396 396
397 397
398 398 EMBEDDING
399 399 It is possible to start an IPython instance inside your own Python pro-
400 400 grams. In the documentation example files there are some illustrations
401 401 on how to do this.
402 402
403 403 This feature allows you to evalutate dynamically the state of your
404 404 code, operate with your variables, analyze them, etc. Note however
405 405 that any changes you make to values while in the shell do NOT propagate
406 406 back to the running code, so it is safe to modify your values because
407 407 you won’t break your code in bizarre ways by doing so.
408 408 """
409 409
410 410 cmd_line_usage = __doc__
411 411
412 412 #---------------------------------------------------------------------------
413 413 interactive_usage = """
414 414 IPython -- An enhanced Interactive Python
415 415 =========================================
416 416
417 417 IPython offers a combination of convenient shell features, special commands
418 418 and a history mechanism for both input (command history) and output (results
419 419 caching, similar to Mathematica). It is intended to be a fully compatible
420 420 replacement for the standard Python interpreter, while offering vastly
421 421 improved functionality and flexibility.
422 422
423 423 At your system command line, type 'ipython -help' to see the command line
424 424 options available. This document only describes interactive features.
425 425
426 426 Warning: IPython relies on the existence of a global variable called __IP which
427 427 controls the shell itself. If you redefine __IP to anything, bizarre behavior
428 428 will quickly occur.
429 429
430 430 MAIN FEATURES
431 431
432 432 * Access to the standard Python help. As of Python 2.1, a help system is
433 433 available with access to object docstrings and the Python manuals. Simply
434 434 type 'help' (no quotes) to access it.
435 435
436 436 * Magic commands: type %magic for information on the magic subsystem.
437 437
438 438 * System command aliases, via the %alias command or the ipythonrc config file.
439 439
440 440 * Dynamic object information:
441 441
442 442 Typing ?word or word? prints detailed information about an object. If
443 443 certain strings in the object are too long (docstrings, code, etc.) they get
444 444 snipped in the center for brevity.
445 445
446 446 Typing ??word or word?? gives access to the full information without
447 447 snipping long strings. Long strings are sent to the screen through the less
448 448 pager if longer than the screen, printed otherwise.
449 449
450 450 The ?/?? system gives access to the full source code for any object (if
451 451 available), shows function prototypes and other useful information.
452 452
453 453 If you just want to see an object's docstring, type '%pdoc object' (without
454 454 quotes, and without % if you have automagic on).
455 455
456 456 Both %pdoc and ?/?? give you access to documentation even on things which are
457 457 not explicitely defined. Try for example typing {}.get? or after import os,
458 458 type os.path.abspath??. The magic functions %pdef, %source and %file operate
459 459 similarly.
460 460
461 461 * Completion in the local namespace, by typing TAB at the prompt.
462 462
463 463 At any time, hitting tab will complete any available python commands or
464 464 variable names, and show you a list of the possible completions if there's
465 465 no unambiguous one. It will also complete filenames in the current directory.
466 466
467 467 This feature requires the readline and rlcomplete modules, so it won't work
468 468 if your Python lacks readline support (such as under Windows).
469 469
470 470 * Search previous command history in two ways (also requires readline):
471 471
472 472 - Start typing, and then use Ctrl-p (previous,up) and Ctrl-n (next,down) to
473 473 search through only the history items that match what you've typed so
474 474 far. If you use Ctrl-p/Ctrl-n at a blank prompt, they just behave like
475 475 normal arrow keys.
476 476
477 477 - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches
478 478 your history for lines that match what you've typed so far, completing as
479 479 much as it can.
480 480
481 481 * Persistent command history across sessions (readline required).
482 482
483 483 * Logging of input with the ability to save and restore a working session.
484 484
485 485 * System escape with !. Typing !ls will run 'ls' in the current directory.
486 486
487 487 * The reload command does a 'deep' reload of a module: changes made to the
488 488 module since you imported will actually be available without having to exit.
489 489
490 490 * Verbose and colored exception traceback printouts. See the magic xmode and
491 491 xcolor functions for details (just type %magic).
492 492
493 493 * Input caching system:
494 494
495 495 IPython offers numbered prompts (In/Out) with input and output caching. All
496 496 input is saved and can be retrieved as variables (besides the usual arrow
497 497 key recall).
498 498
499 499 The following GLOBAL variables always exist (so don't overwrite them!):
500 500 _i: stores previous input.
501 501 _ii: next previous.
502 502 _iii: next-next previous.
503 503 _ih : a list of all input _ih[n] is the input from line n.
504 504
505 505 Additionally, global variables named _i<n> are dynamically created (<n>
506 506 being the prompt counter), such that _i<n> == _ih[<n>]
507 507
508 508 For example, what you typed at prompt 14 is available as _i14 and _ih[14].
509 509
510 510 You can create macros which contain multiple input lines from this history,
511 511 for later re-execution, with the %macro function.
512 512
513 513 The history function %hist allows you to see any part of your input history
514 514 by printing a range of the _i variables. Note that inputs which contain
515 515 magic functions (%) appear in the history with a prepended comment. This is
516 516 because they aren't really valid Python code, so you can't exec them.
517 517
518 518 * Output caching system:
519 519
520 520 For output that is returned from actions, a system similar to the input
521 521 cache exists but using _ instead of _i. Only actions that produce a result
522 522 (NOT assignments, for example) are cached. If you are familiar with
523 523 Mathematica, IPython's _ variables behave exactly like Mathematica's %
524 524 variables.
525 525
526 526 The following GLOBAL variables always exist (so don't overwrite them!):
527 527 _ (one underscore): previous output.
528 528 __ (two underscores): next previous.
529 529 ___ (three underscores): next-next previous.
530 530
531 531 Global variables named _<n> are dynamically created (<n> being the prompt
532 532 counter), such that the result of output <n> is always available as _<n>.
533 533
534 534 Finally, a global dictionary named _oh exists with entries for all lines
535 535 which generated output.
536 536
537 537 * Directory history:
538 538
539 539 Your history of visited directories is kept in the global list _dh, and the
540 540 magic %cd command can be used to go to any entry in that list.
541 541
542 542 * Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
543 543
544 544 1. Auto-parentheses
545 545 Callable objects (i.e. functions, methods, etc) can be invoked like
546 546 this (notice the commas between the arguments):
547 547 >>> callable_ob arg1, arg2, arg3
548 548 and the input will be translated to this:
549 549 --> callable_ob(arg1, arg2, arg3)
550 550 You can force auto-parentheses by using '/' as the first character
551 551 of a line. For example:
552 552 >>> /globals # becomes 'globals()'
553 553 Note that the '/' MUST be the first character on the line! This
554 554 won't work:
555 555 >>> print /globals # syntax error
556 556
557 557 In most cases the automatic algorithm should work, so you should
558 558 rarely need to explicitly invoke /. One notable exception is if you
559 559 are trying to call a function with a list of tuples as arguments (the
560 560 parenthesis will confuse IPython):
561 561 In [1]: zip (1,2,3),(4,5,6) # won't work
562 562 but this will work:
563 563 In [2]: /zip (1,2,3),(4,5,6)
564 564 ------> zip ((1,2,3),(4,5,6))
565 565 Out[2]= [(1, 4), (2, 5), (3, 6)]
566 566
567 567 IPython tells you that it has altered your command line by
568 568 displaying the new command line preceded by -->. e.g.:
569 569 In [18]: callable list
570 570 -------> callable (list)
571 571
572 572 2. Auto-Quoting
573 573 You can force auto-quoting of a function's arguments by using ',' as
574 574 the first character of a line. For example:
575 575 >>> ,my_function /home/me # becomes my_function("/home/me")
576 576
577 577 If you use ';' instead, the whole argument is quoted as a single
578 578 string (while ',' splits on whitespace):
579 579 >>> ,my_function a b c # becomes my_function("a","b","c")
580 580 >>> ;my_function a b c # becomes my_function("a b c")
581 581
582 582 Note that the ',' MUST be the first character on the line! This
583 583 won't work:
584 584 >>> x = ,my_function /home/me # syntax error
585 585 """
@@ -1,4599 +1,4627 b''
1 2005-12-29 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/Magic.py (Macro): simplified Macro class to just
4 subclass list. We've had only 2.2 compatibility for a very long
5 time, yet I was still avoiding subclassing the builtin types. No
6 more (I'm also starting to use properties, though I won't shift to
7 2.3-specific features quite yet).
8
9 * IPython/iplib.py (InteractiveShell.post_config_initialization):
10 changed the default logfile name from 'ipython.log' to
11 'ipython_log.py'. These logs are real python files, and now that
12 we have much better multiline support, people are more likely to
13 want to use them as such. Might as well name them correctly.
14
15 * IPython/Magic.py: substantial cleanup. While we can't stop
16 using magics as mixins, due to the existing customizations 'out
17 there' which rely on the mixin naming conventions, at least I
18 cleaned out all cross-class name usage. So once we are OK with
19 breaking compatibility, the two systems can be separated.
20
21 * IPython/Logger.py: major cleanup. This one is NOT a mixin
22 anymore, and the class is a fair bit less hideous as well. New
23 features were also introduced: timestamping of input, and logging
24 of output results. These are user-visible with the -t and -o
25 options to %logstart. Closes
26 http://www.scipy.net/roundup/ipython/issue11 and a request by
27 William Stein (SAGE developer - http://modular.ucsd.edu/sage).
28
1 29 2005-12-28 Fernando Perez <Fernando.Perez@colorado.edu>
2 30
3 31 * IPython/iplib.py (handle_shell_escape): add Ville's patch to
4 32 better hadnle backslashes in paths. See the thread 'More Windows
5 33 questions part 2 - \/ characters revisited' on the iypthon user
6 34 list:
7 35 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
8 36
9 37 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
10 38
11 39 (InteractiveShell.__init__): change threaded shells to not use the
12 40 ipython crash handler. This was causing more problems than not,
13 41 as exceptions in the main thread (GUI code, typically) would
14 42 always show up as a 'crash', when they really weren't.
15 43
16 44 The colors and exception mode commands (%colors/%xmode) have been
17 45 synchronized to also take this into account, so users can get
18 46 verbose exceptions for their threaded code as well. I also added
19 47 support for activating pdb inside this exception handler as well,
20 48 so now GUI authors can use IPython's enhanced pdb at runtime.
21 49
22 50 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
23 51 true by default, and add it to the shipped ipythonrc file. Since
24 52 this asks the user before proceeding, I think it's OK to make it
25 53 true by default.
26 54
27 55 * IPython/Magic.py (magic_exit): make new exit/quit magics instead
28 56 of the previous special-casing of input in the eval loop. I think
29 57 this is cleaner, as they really are commands and shouldn't have
30 58 a special role in the middle of the core code.
31 59
32 60 2005-12-27 Fernando Perez <Fernando.Perez@colorado.edu>
33 61
34 62 * IPython/iplib.py (edit_syntax_error): added support for
35 63 automatically reopening the editor if the file had a syntax error
36 64 in it. Thanks to scottt who provided the patch at:
37 65 http://www.scipy.net/roundup/ipython/issue36 (slightly modified
38 66 version committed).
39 67
40 68 * IPython/iplib.py (handle_normal): add suport for multi-line
41 69 input with emtpy lines. This fixes
42 70 http://www.scipy.net/roundup/ipython/issue43 and a similar
43 71 discussion on the user list.
44 72
45 73 WARNING: a behavior change is necessarily introduced to support
46 74 blank lines: now a single blank line with whitespace does NOT
47 75 break the input loop, which means that when autoindent is on, by
48 76 default hitting return on the next (indented) line does NOT exit.
49 77
50 78 Instead, to exit a multiline input you can either have:
51 79
52 80 - TWO whitespace lines (just hit return again), or
53 81 - a single whitespace line of a different length than provided
54 82 by the autoindent (add or remove a space).
55 83
56 84 * IPython/completer.py (MagicCompleter.__init__): new 'completer'
57 85 module to better organize all readline-related functionality.
58 86 I've deleted FlexCompleter and put all completion clases here.
59 87
60 88 * IPython/iplib.py (raw_input): improve indentation management.
61 89 It is now possible to paste indented code with autoindent on, and
62 90 the code is interpreted correctly (though it still looks bad on
63 91 screen, due to the line-oriented nature of ipython).
64 92 (MagicCompleter.complete): change behavior so that a TAB key on an
65 93 otherwise empty line actually inserts a tab, instead of completing
66 94 on the entire global namespace. This makes it easier to use the
67 95 TAB key for indentation. After a request by Hans Meine
68 96 <hans_meine-AT-gmx.net>
69 97 (_prefilter): add support so that typing plain 'exit' or 'quit'
70 98 does a sensible thing. Originally I tried to deviate as little as
71 99 possible from the default python behavior, but even that one may
72 100 change in this direction (thread on python-dev to that effect).
73 101 Regardless, ipython should do the right thing even if CPython's
74 102 '>>>' prompt doesn't.
75 103 (InteractiveShell): removed subclassing code.InteractiveConsole
76 104 class. By now we'd overridden just about all of its methods: I've
77 105 copied the remaining two over, and now ipython is a standalone
78 106 class. This will provide a clearer picture for the chainsaw
79 107 branch refactoring.
80 108
81 109 2005-12-26 Fernando Perez <Fernando.Perez@colorado.edu>
82 110
83 111 * IPython/ultraTB.py (VerboseTB.text): harden reporting against
84 112 failures for objects which break when dir() is called on them.
85 113
86 114 * IPython/FlexCompleter.py (Completer.__init__): Added support for
87 115 distinct local and global namespaces in the completer API. This
88 116 change allows us top properly handle completion with distinct
89 117 scopes, including in embedded instances (this had never really
90 118 worked correctly).
91 119
92 120 Note: this introduces a change in the constructor for
93 121 MagicCompleter, as a new global_namespace parameter is now the
94 122 second argument (the others were bumped one position).
95 123
96 124 2005-12-25 Fernando Perez <Fernando.Perez@colorado.edu>
97 125
98 126 * IPython/iplib.py (embed_mainloop): fix tab-completion in
99 127 embedded instances (which can be done now thanks to Vivian's
100 128 frame-handling fixes for pdb).
101 129 (InteractiveShell.__init__): Fix namespace handling problem in
102 130 embedded instances. We were overwriting __main__ unconditionally,
103 131 and this should only be done for 'full' (non-embedded) IPython;
104 132 embedded instances must respect the caller's __main__. Thanks to
105 133 a bug report by Yaroslav Bulatov <yaroslavvb-AT-gmail.com>
106 134
107 135 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
108 136
109 137 * setup.py: added download_url to setup(). This registers the
110 138 download address at PyPI, which is not only useful to humans
111 139 browsing the site, but is also picked up by setuptools (the Eggs
112 140 machinery). Thanks to Ville and R. Kern for the info/discussion
113 141 on this.
114 142
115 143 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
116 144
117 145 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
118 146 This brings a lot of nice functionality to the pdb mode, which now
119 147 has tab-completion, syntax highlighting, and better stack handling
120 148 than before. Many thanks to Vivian De Smedt
121 149 <vivian-AT-vdesmedt.com> for the original patches.
122 150
123 151 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
124 152
125 153 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
126 154 sequence to consistently accept the banner argument. The
127 155 inconsistency was tripping SAGE, thanks to Gary Zablackis
128 156 <gzabl-AT-yahoo.com> for the report.
129 157
130 158 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
131 159
132 160 * IPython/iplib.py (InteractiveShell.post_config_initialization):
133 161 Fix bug where a naked 'alias' call in the ipythonrc file would
134 162 cause a crash. Bug reported by Jorgen Stenarson.
135 163
136 164 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
137 165
138 166 * IPython/ipmaker.py (make_IPython): cleanups which should improve
139 167 startup time.
140 168
141 169 * IPython/iplib.py (runcode): my globals 'fix' for embedded
142 170 instances had introduced a bug with globals in normal code. Now
143 171 it's working in all cases.
144 172
145 173 * IPython/Magic.py (magic_psearch): Finish wildcard cleanup and
146 174 API changes. A new ipytonrc option, 'wildcards_case_sensitive'
147 175 has been introduced to set the default case sensitivity of the
148 176 searches. Users can still select either mode at runtime on a
149 177 per-search basis.
150 178
151 179 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
152 180
153 181 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
154 182 attributes in wildcard searches for subclasses. Modified version
155 183 of a patch by Jorgen.
156 184
157 185 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
158 186
159 187 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
160 188 embedded instances. I added a user_global_ns attribute to the
161 189 InteractiveShell class to handle this.
162 190
163 191 2005-10-31 Fernando Perez <Fernando.Perez@colorado.edu>
164 192
165 193 * IPython/Shell.py (IPShellGTK.mainloop): Change timeout_add to
166 194 idle_add, which fixes horrible keyboard lag problems under gtk 2.6
167 195 (reported under win32, but may happen also in other platforms).
168 196 Bug report and fix courtesy of Sean Moore <smm-AT-logic.bm>
169 197
170 198 2005-10-15 Fernando Perez <Fernando.Perez@colorado.edu>
171 199
172 200 * IPython/Magic.py (magic_psearch): new support for wildcard
173 201 patterns. Now, typing ?a*b will list all names which begin with a
174 202 and end in b, for example. The %psearch magic has full
175 203 docstrings. Many thanks to Jörgen Stenarson
176 204 <jorgen.stenarson-AT-bostream.nu>, author of the patches
177 205 implementing this functionality.
178 206
179 207 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
180 208
181 209 * Manual: fixed long-standing annoyance of double-dashes (as in
182 210 --prefix=~, for example) being stripped in the HTML version. This
183 211 is a latex2html bug, but a workaround was provided. Many thanks
184 212 to George K. Thiruvathukal <gthiruv-AT-luc.edu> for the detailed
185 213 help, and Michael Tobis <mtobis-AT-gmail.com> for getting the ball
186 214 rolling. This seemingly small issue had tripped a number of users
187 215 when first installing, so I'm glad to see it gone.
188 216
189 217 2005-09-27 Fernando Perez <Fernando.Perez@colorado.edu>
190 218
191 219 * IPython/Extensions/numeric_formats.py: fix missing import,
192 220 reported by Stephen Walton.
193 221
194 222 2005-09-24 Fernando Perez <Fernando.Perez@colorado.edu>
195 223
196 224 * IPython/demo.py: finish demo module, fully documented now.
197 225
198 226 * IPython/genutils.py (file_read): simple little utility to read a
199 227 file and ensure it's closed afterwards.
200 228
201 229 2005-09-23 Fernando Perez <Fernando.Perez@colorado.edu>
202 230
203 231 * IPython/demo.py (Demo.__init__): added support for individually
204 232 tagging blocks for automatic execution.
205 233
206 234 * IPython/Magic.py (magic_pycat): new %pycat magic for showing
207 235 syntax-highlighted python sources, requested by John.
208 236
209 237 2005-09-22 Fernando Perez <Fernando.Perez@colorado.edu>
210 238
211 239 * IPython/demo.py (Demo.again): fix bug where again() blocks after
212 240 finishing.
213 241
214 242 * IPython/genutils.py (shlex_split): moved from Magic to here,
215 243 where all 2.2 compatibility stuff lives. I needed it for demo.py.
216 244
217 245 * IPython/demo.py (Demo.__init__): added support for silent
218 246 blocks, improved marks as regexps, docstrings written.
219 247 (Demo.__init__): better docstring, added support for sys.argv.
220 248
221 249 * IPython/genutils.py (marquee): little utility used by the demo
222 250 code, handy in general.
223 251
224 252 * IPython/demo.py (Demo.__init__): new class for interactive
225 253 demos. Not documented yet, I just wrote it in a hurry for
226 254 scipy'05. Will docstring later.
227 255
228 256 2005-09-20 Fernando Perez <Fernando.Perez@colorado.edu>
229 257
230 258 * IPython/Shell.py (sigint_handler): Drastic simplification which
231 259 also seems to make Ctrl-C work correctly across threads! This is
232 260 so simple, that I can't beleive I'd missed it before. Needs more
233 261 testing, though.
234 262 (KBINT): Never mind, revert changes. I'm sure I'd tried something
235 263 like this before...
236 264
237 265 * IPython/genutils.py (get_home_dir): add protection against
238 266 non-dirs in win32 registry.
239 267
240 268 * IPython/iplib.py (InteractiveShell.alias_table_validate): fix
241 269 bug where dict was mutated while iterating (pysh crash).
242 270
243 271 2005-09-06 Fernando Perez <Fernando.Perez@colorado.edu>
244 272
245 273 * IPython/iplib.py (handle_auto): Fix inconsistency arising from
246 274 spurious newlines added by this routine. After a report by
247 275 F. Mantegazza.
248 276
249 277 2005-09-05 Fernando Perez <Fernando.Perez@colorado.edu>
250 278
251 279 * IPython/Shell.py (hijack_gtk): remove pygtk.require("2.0")
252 280 calls. These were a leftover from the GTK 1.x days, and can cause
253 281 problems in certain cases (after a report by John Hunter).
254 282
255 283 * IPython/iplib.py (InteractiveShell.__init__): Trap exception if
256 284 os.getcwd() fails at init time. Thanks to patch from David Remahl
257 285 <chmod007-AT-mac.com>.
258 286 (InteractiveShell.__init__): prevent certain special magics from
259 287 being shadowed by aliases. Closes
260 288 http://www.scipy.net/roundup/ipython/issue41.
261 289
262 290 2005-08-31 Fernando Perez <Fernando.Perez@colorado.edu>
263 291
264 292 * IPython/iplib.py (InteractiveShell.complete): Added new
265 293 top-level completion method to expose the completion mechanism
266 294 beyond readline-based environments.
267 295
268 296 2005-08-19 Fernando Perez <Fernando.Perez@colorado.edu>
269 297
270 298 * tools/ipsvnc (svnversion): fix svnversion capture.
271 299
272 300 * IPython/iplib.py (InteractiveShell.__init__): Add has_readline
273 301 attribute to self, which was missing. Before, it was set by a
274 302 routine which in certain cases wasn't being called, so the
275 303 instance could end up missing the attribute. This caused a crash.
276 304 Closes http://www.scipy.net/roundup/ipython/issue40.
277 305
278 306 2005-08-16 Fernando Perez <fperez@colorado.edu>
279 307
280 308 * IPython/ultraTB.py (VerboseTB.text): don't crash if object
281 309 contains non-string attribute. Closes
282 310 http://www.scipy.net/roundup/ipython/issue38.
283 311
284 312 2005-08-14 Fernando Perez <fperez@colorado.edu>
285 313
286 314 * tools/ipsvnc: Minor improvements, to add changeset info.
287 315
288 316 2005-08-12 Fernando Perez <fperez@colorado.edu>
289 317
290 318 * IPython/iplib.py (runsource): remove self.code_to_run_src
291 319 attribute. I realized this is nothing more than
292 320 '\n'.join(self.buffer), and having the same data in two different
293 321 places is just asking for synchronization bugs. This may impact
294 322 people who have custom exception handlers, so I need to warn
295 323 ipython-dev about it (F. Mantegazza may use them).
296 324
297 325 2005-07-29 Fernando Perez <Fernando.Perez@colorado.edu>
298 326
299 327 * IPython/genutils.py: fix 2.2 compatibility (generators)
300 328
301 329 2005-07-18 Fernando Perez <fperez@colorado.edu>
302 330
303 331 * IPython/genutils.py (get_home_dir): fix to help users with
304 332 invalid $HOME under win32.
305 333
306 334 2005-07-17 Fernando Perez <fperez@colorado.edu>
307 335
308 336 * IPython/Prompts.py (str_safe): Make unicode-safe. Also remove
309 337 some old hacks and clean up a bit other routines; code should be
310 338 simpler and a bit faster.
311 339
312 340 * IPython/iplib.py (interact): removed some last-resort attempts
313 341 to survive broken stdout/stderr. That code was only making it
314 342 harder to abstract out the i/o (necessary for gui integration),
315 343 and the crashes it could prevent were extremely rare in practice
316 344 (besides being fully user-induced in a pretty violent manner).
317 345
318 346 * IPython/genutils.py (IOStream.__init__): Simplify the i/o stuff.
319 347 Nothing major yet, but the code is simpler to read; this should
320 348 make it easier to do more serious modifications in the future.
321 349
322 350 * IPython/Extensions/InterpreterExec.py: Fix auto-quoting in pysh,
323 351 which broke in .15 (thanks to a report by Ville).
324 352
325 353 * IPython/Itpl.py (Itpl.__init__): add unicode support (it may not
326 354 be quite correct, I know next to nothing about unicode). This
327 355 will allow unicode strings to be used in prompts, amongst other
328 356 cases. It also will prevent ipython from crashing when unicode
329 357 shows up unexpectedly in many places. If ascii encoding fails, we
330 358 assume utf_8. Currently the encoding is not a user-visible
331 359 setting, though it could be made so if there is demand for it.
332 360
333 361 * IPython/ipmaker.py (make_IPython): remove old 2.1-specific hack.
334 362
335 363 * IPython/Struct.py (Struct.merge): switch keys() to iterator.
336 364
337 365 * IPython/background_jobs.py: moved 2.2 compatibility to genutils.
338 366
339 367 * IPython/genutils.py: Add 2.2 compatibility here, so all other
340 368 code can work transparently for 2.2/2.3.
341 369
342 370 2005-07-16 Fernando Perez <fperez@colorado.edu>
343 371
344 372 * IPython/ultraTB.py (ExceptionColors): Make a global variable
345 373 out of the color scheme table used for coloring exception
346 374 tracebacks. This allows user code to add new schemes at runtime.
347 375 This is a minimally modified version of the patch at
348 376 http://www.scipy.net/roundup/ipython/issue35, many thanks to pabw
349 377 for the contribution.
350 378
351 379 * IPython/FlexCompleter.py (Completer.attr_matches): Add a
352 380 slightly modified version of the patch in
353 381 http://www.scipy.net/roundup/ipython/issue34, which also allows me
354 382 to remove the previous try/except solution (which was costlier).
355 383 Thanks to Gaetan Lehmann <gaetan.lehmann-AT-jouy.inra.fr> for the fix.
356 384
357 385 2005-06-08 Fernando Perez <fperez@colorado.edu>
358 386
359 387 * IPython/iplib.py (write/write_err): Add methods to abstract all
360 388 I/O a bit more.
361 389
362 390 * IPython/Shell.py (IPShellGTK.mainloop): Fix GTK deprecation
363 391 warning, reported by Aric Hagberg, fix by JD Hunter.
364 392
365 393 2005-06-02 *** Released version 0.6.15
366 394
367 395 2005-06-01 Fernando Perez <fperez@colorado.edu>
368 396
369 397 * IPython/iplib.py (MagicCompleter.file_matches): Fix
370 398 tab-completion of filenames within open-quoted strings. Note that
371 399 this requires that in ~/.ipython/ipythonrc, users change the
372 400 readline delimiters configuration to read:
373 401
374 402 readline_remove_delims -/~
375 403
376 404
377 405 2005-05-31 *** Released version 0.6.14
378 406
379 407 2005-05-29 Fernando Perez <fperez@colorado.edu>
380 408
381 409 * IPython/ultraTB.py (VerboseTB.text): Fix crash for tracebacks
382 410 with files not on the filesystem. Reported by Eliyahu Sandler
383 411 <eli@gondolin.net>
384 412
385 413 2005-05-22 Fernando Perez <fperez@colorado.edu>
386 414
387 415 * IPython/iplib.py: Fix a few crashes in the --upgrade option.
388 416 After an initial report by LUK ShunTim <shuntim.luk@polyu.edu.hk>.
389 417
390 418 2005-05-19 Fernando Perez <fperez@colorado.edu>
391 419
392 420 * IPython/iplib.py (safe_execfile): close a file which could be
393 421 left open (causing problems in win32, which locks open files).
394 422 Thanks to a bug report by D Brown <dbrown2@yahoo.com>.
395 423
396 424 2005-05-18 Fernando Perez <fperez@colorado.edu>
397 425
398 426 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): pass all
399 427 keyword arguments correctly to safe_execfile().
400 428
401 429 2005-05-13 Fernando Perez <fperez@colorado.edu>
402 430
403 431 * ipython.1: Added info about Qt to manpage, and threads warning
404 432 to usage page (invoked with --help).
405 433
406 434 * IPython/iplib.py (MagicCompleter.python_func_kw_matches): Added
407 435 new matcher (it goes at the end of the priority list) to do
408 436 tab-completion on named function arguments. Submitted by George
409 437 Sakkis <gsakkis-AT-eden.rutgers.edu>. See the thread at
410 438 http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html
411 439 for more details.
412 440
413 441 * IPython/Magic.py (magic_run): Added new -e flag to ignore
414 442 SystemExit exceptions in the script being run. Thanks to a report
415 443 by danny shevitz <danny_shevitz-AT-yahoo.com>, about this
416 444 producing very annoying behavior when running unit tests.
417 445
418 446 2005-05-12 Fernando Perez <fperez@colorado.edu>
419 447
420 448 * IPython/iplib.py (handle_auto): fixed auto-quoting and parens,
421 449 which I'd broken (again) due to a changed regexp. In the process,
422 450 added ';' as an escape to auto-quote the whole line without
423 451 splitting its arguments. Thanks to a report by Jerry McRae
424 452 <qrs0xyc02-AT-sneakemail.com>.
425 453
426 454 * IPython/ultraTB.py (VerboseTB.text): protect against rare but
427 455 possible crashes caused by a TokenError. Reported by Ed Schofield
428 456 <schofield-AT-ftw.at>.
429 457
430 458 2005-05-06 Fernando Perez <fperez@colorado.edu>
431 459
432 460 * IPython/Shell.py (hijack_wx): Fix to work with WX v.2.6.
433 461
434 462 2005-04-29 Fernando Perez <fperez@colorado.edu>
435 463
436 464 * IPython/Shell.py (IPShellQt): Thanks to Denis Rivière
437 465 <nudz-AT-free.fr>, Yann Cointepas <yann-AT-sapetnioc.org> and Benjamin
438 466 Thyreau <Benji2-AT-decideur.info>, we now have a -qthread option
439 467 which provides support for Qt interactive usage (similar to the
440 468 existing one for WX and GTK). This had been often requested.
441 469
442 470 2005-04-14 *** Released version 0.6.13
443 471
444 472 2005-04-08 Fernando Perez <fperez@colorado.edu>
445 473
446 474 * IPython/Magic.py (Magic._ofind): remove docstring evaluation
447 475 from _ofind, which gets called on almost every input line. Now,
448 476 we only try to get docstrings if they are actually going to be
449 477 used (the overhead of fetching unnecessary docstrings can be
450 478 noticeable for certain objects, such as Pyro proxies).
451 479
452 480 * IPython/iplib.py (MagicCompleter.python_matches): Change the API
453 481 for completers. For some reason I had been passing them the state
454 482 variable, which completers never actually need, and was in
455 483 conflict with the rlcompleter API. Custom completers ONLY need to
456 484 take the text parameter.
457 485
458 486 * IPython/Extensions/InterpreterExec.py: Fix regexp so that magics
459 487 work correctly in pysh. I've also moved all the logic which used
460 488 to be in pysh.py here, which will prevent problems with future
461 489 upgrades. However, this time I must warn users to update their
462 490 pysh profile to include the line
463 491
464 492 import_all IPython.Extensions.InterpreterExec
465 493
466 494 because otherwise things won't work for them. They MUST also
467 495 delete pysh.py and the line
468 496
469 497 execfile pysh.py
470 498
471 499 from their ipythonrc-pysh.
472 500
473 501 * IPython/FlexCompleter.py (Completer.attr_matches): Make more
474 502 robust in the face of objects whose dir() returns non-strings
475 503 (which it shouldn't, but some broken libs like ITK do). Thanks to
476 504 a patch by John Hunter (implemented differently, though). Also
477 505 minor improvements by using .extend instead of + on lists.
478 506
479 507 * pysh.py:
480 508
481 509 2005-04-06 Fernando Perez <fperez@colorado.edu>
482 510
483 511 * IPython/ipmaker.py (make_IPython): Make multi_line_specials on
484 512 by default, so that all users benefit from it. Those who don't
485 513 want it can still turn it off.
486 514
487 515 * IPython/UserConfig/ipythonrc: Add multi_line_specials to the
488 516 config file, I'd forgotten about this, so users were getting it
489 517 off by default.
490 518
491 519 * IPython/iplib.py (ipmagic): big overhaul of the magic system for
492 520 consistency. Now magics can be called in multiline statements,
493 521 and python variables can be expanded in magic calls via $var.
494 522 This makes the magic system behave just like aliases or !system
495 523 calls.
496 524
497 525 2005-03-28 Fernando Perez <fperez@colorado.edu>
498 526
499 527 * IPython/iplib.py (handle_auto): cleanup to use %s instead of
500 528 expensive string additions for building command. Add support for
501 529 trailing ';' when autocall is used.
502 530
503 531 2005-03-26 Fernando Perez <fperez@colorado.edu>
504 532
505 533 * ipython.el: Fix http://www.scipy.net/roundup/ipython/issue31.
506 534 Bugfix by A. Schmolck, the ipython.el maintainer. Also make
507 535 ipython.el robust against prompts with any number of spaces
508 536 (including 0) after the ':' character.
509 537
510 538 * IPython/Prompts.py (Prompt2.set_p_str): Fix spurious space in
511 539 continuation prompt, which misled users to think the line was
512 540 already indented. Closes debian Bug#300847, reported to me by
513 541 Norbert Tretkowski <tretkowski-AT-inittab.de>.
514 542
515 543 2005-03-23 Fernando Perez <fperez@colorado.edu>
516 544
517 545 * IPython/Prompts.py (Prompt1.__str__): Make sure that prompts are
518 546 properly aligned if they have embedded newlines.
519 547
520 548 * IPython/iplib.py (runlines): Add a public method to expose
521 549 IPython's code execution machinery, so that users can run strings
522 550 as if they had been typed at the prompt interactively.
523 551 (InteractiveShell.__init__): Added getoutput() to the __IPYTHON__
524 552 methods which can call the system shell, but with python variable
525 553 expansion. The three such methods are: __IPYTHON__.system,
526 554 .getoutput and .getoutputerror. These need to be documented in a
527 555 'public API' section (to be written) of the manual.
528 556
529 557 2005-03-20 Fernando Perez <fperez@colorado.edu>
530 558
531 559 * IPython/iplib.py (InteractiveShell.set_custom_exc): new system
532 560 for custom exception handling. This is quite powerful, and it
533 561 allows for user-installable exception handlers which can trap
534 562 custom exceptions at runtime and treat them separately from
535 563 IPython's default mechanisms. At the request of Frédéric
536 564 Mantegazza <mantegazza-AT-ill.fr>.
537 565 (InteractiveShell.set_custom_completer): public API function to
538 566 add new completers at runtime.
539 567
540 568 2005-03-19 Fernando Perez <fperez@colorado.edu>
541 569
542 570 * IPython/OInspect.py (getdoc): Add a call to obj.getdoc(), to
543 571 allow objects which provide their docstrings via non-standard
544 572 mechanisms (like Pyro proxies) to still be inspected by ipython's
545 573 ? system.
546 574
547 575 * IPython/iplib.py (InteractiveShell.__init__): back off the _o/_e
548 576 automatic capture system. I tried quite hard to make it work
549 577 reliably, and simply failed. I tried many combinations with the
550 578 subprocess module, but eventually nothing worked in all needed
551 579 cases (not blocking stdin for the child, duplicating stdout
552 580 without blocking, etc). The new %sc/%sx still do capture to these
553 581 magical list/string objects which make shell use much more
554 582 conveninent, so not all is lost.
555 583
556 584 XXX - FIX MANUAL for the change above!
557 585
558 586 (runsource): I copied code.py's runsource() into ipython to modify
559 587 it a bit. Now the code object and source to be executed are
560 588 stored in ipython. This makes this info accessible to third-party
561 589 tools, like custom exception handlers. After a request by Frédéric
562 590 Mantegazza <mantegazza-AT-ill.fr>.
563 591
564 592 * IPython/UserConfig/ipythonrc: Add up/down arrow keys to
565 593 history-search via readline (like C-p/C-n). I'd wanted this for a
566 594 long time, but only recently found out how to do it. For users
567 595 who already have their ipythonrc files made and want this, just
568 596 add:
569 597
570 598 readline_parse_and_bind "\e[A": history-search-backward
571 599 readline_parse_and_bind "\e[B": history-search-forward
572 600
573 601 2005-03-18 Fernando Perez <fperez@colorado.edu>
574 602
575 603 * IPython/Magic.py (magic_sc): %sc and %sx now use the fancy
576 604 LSString and SList classes which allow transparent conversions
577 605 between list mode and whitespace-separated string.
578 606 (magic_r): Fix recursion problem in %r.
579 607
580 608 * IPython/genutils.py (LSString): New class to be used for
581 609 automatic storage of the results of all alias/system calls in _o
582 610 and _e (stdout/err). These provide a .l/.list attribute which
583 611 does automatic splitting on newlines. This means that for most
584 612 uses, you'll never need to do capturing of output with %sc/%sx
585 613 anymore, since ipython keeps this always done for you. Note that
586 614 only the LAST results are stored, the _o/e variables are
587 615 overwritten on each call. If you need to save their contents
588 616 further, simply bind them to any other name.
589 617
590 618 2005-03-17 Fernando Perez <fperez@colorado.edu>
591 619
592 620 * IPython/Prompts.py (BasePrompt.cwd_filt): a few more fixes for
593 621 prompt namespace handling.
594 622
595 623 2005-03-16 Fernando Perez <fperez@colorado.edu>
596 624
597 625 * IPython/Prompts.py (CachedOutput.__init__): Fix default and
598 626 classic prompts to be '>>> ' (final space was missing, and it
599 627 trips the emacs python mode).
600 628 (BasePrompt.__str__): Added safe support for dynamic prompt
601 629 strings. Now you can set your prompt string to be '$x', and the
602 630 value of x will be printed from your interactive namespace. The
603 631 interpolation syntax includes the full Itpl support, so
604 632 ${foo()+x+bar()} is a valid prompt string now, and the function
605 633 calls will be made at runtime.
606 634
607 635 2005-03-15 Fernando Perez <fperez@colorado.edu>
608 636
609 637 * IPython/Magic.py (magic_history): renamed %hist to %history, to
610 638 avoid name clashes in pylab. %hist still works, it just forwards
611 639 the call to %history.
612 640
613 641 2005-03-02 *** Released version 0.6.12
614 642
615 643 2005-03-02 Fernando Perez <fperez@colorado.edu>
616 644
617 645 * IPython/iplib.py (handle_magic): log magic calls properly as
618 646 ipmagic() function calls.
619 647
620 648 * IPython/Magic.py (magic_time): Improved %time to support
621 649 statements and provide wall-clock as well as CPU time.
622 650
623 651 2005-02-27 Fernando Perez <fperez@colorado.edu>
624 652
625 653 * IPython/hooks.py: New hooks module, to expose user-modifiable
626 654 IPython functionality in a clean manner. For now only the editor
627 655 hook is actually written, and other thigns which I intend to turn
628 656 into proper hooks aren't yet there. The display and prefilter
629 657 stuff, for example, should be hooks. But at least now the
630 658 framework is in place, and the rest can be moved here with more
631 659 time later. IPython had had a .hooks variable for a long time for
632 660 this purpose, but I'd never actually used it for anything.
633 661
634 662 2005-02-26 Fernando Perez <fperez@colorado.edu>
635 663
636 664 * IPython/ipmaker.py (make_IPython): make the default ipython
637 665 directory be called _ipython under win32, to follow more the
638 666 naming peculiarities of that platform (where buggy software like
639 667 Visual Sourcesafe breaks with .named directories). Reported by
640 668 Ville Vainio.
641 669
642 670 2005-02-23 Fernando Perez <fperez@colorado.edu>
643 671
644 672 * IPython/iplib.py (InteractiveShell.__init__): removed a few
645 673 auto_aliases for win32 which were causing problems. Users can
646 674 define the ones they personally like.
647 675
648 676 2005-02-21 Fernando Perez <fperez@colorado.edu>
649 677
650 678 * IPython/Magic.py (magic_time): new magic to time execution of
651 679 expressions. After a request by Charles Moad <cmoad-AT-indiana.edu>.
652 680
653 681 2005-02-19 Fernando Perez <fperez@colorado.edu>
654 682
655 683 * IPython/ConfigLoader.py (ConfigLoader.load): Allow empty strings
656 684 into keys (for prompts, for example).
657 685
658 686 * IPython/Prompts.py (BasePrompt.set_p_str): Fix to allow empty
659 687 prompts in case users want them. This introduces a small behavior
660 688 change: ipython does not automatically add a space to all prompts
661 689 anymore. To get the old prompts with a space, users should add it
662 690 manually to their ipythonrc file, so for example prompt_in1 should
663 691 now read 'In [\#]: ' instead of 'In [\#]:'.
664 692 (BasePrompt.__init__): New option prompts_pad_left (only in rc
665 693 file) to control left-padding of secondary prompts.
666 694
667 695 * IPython/Magic.py (Magic.profile_missing_notice): Don't crash if
668 696 the profiler can't be imported. Fix for Debian, which removed
669 697 profile.py because of License issues. I applied a slightly
670 698 modified version of the original Debian patch at
671 699 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=294500.
672 700
673 701 2005-02-17 Fernando Perez <fperez@colorado.edu>
674 702
675 703 * IPython/genutils.py (native_line_ends): Fix bug which would
676 704 cause improper line-ends under win32 b/c I was not opening files
677 705 in binary mode. Bug report and fix thanks to Ville.
678 706
679 707 * IPython/iplib.py (handle_auto): Fix bug which I introduced when
680 708 trying to catch spurious foo[1] autocalls. My fix actually broke
681 709 ',/' autoquote/call with explicit escape (bad regexp).
682 710
683 711 2005-02-15 *** Released version 0.6.11
684 712
685 713 2005-02-14 Fernando Perez <fperez@colorado.edu>
686 714
687 715 * IPython/background_jobs.py: New background job management
688 716 subsystem. This is implemented via a new set of classes, and
689 717 IPython now provides a builtin 'jobs' object for background job
690 718 execution. A convenience %bg magic serves as a lightweight
691 719 frontend for starting the more common type of calls. This was
692 720 inspired by discussions with B. Granger and the BackgroundCommand
693 721 class described in the book Python Scripting for Computational
694 722 Science, by H. P. Langtangen: http://folk.uio.no/hpl/scripting
695 723 (although ultimately no code from this text was used, as IPython's
696 724 system is a separate implementation).
697 725
698 726 * IPython/iplib.py (MagicCompleter.python_matches): add new option
699 727 to control the completion of single/double underscore names
700 728 separately. As documented in the example ipytonrc file, the
701 729 readline_omit__names variable can now be set to 2, to omit even
702 730 single underscore names. Thanks to a patch by Brian Wong
703 731 <BrianWong-AT-AirgoNetworks.Com>.
704 732 (InteractiveShell.__init__): Fix bug which would cause foo[1] to
705 733 be autocalled as foo([1]) if foo were callable. A problem for
706 734 things which are both callable and implement __getitem__.
707 735 (init_readline): Fix autoindentation for win32. Thanks to a patch
708 736 by Vivian De Smedt <vivian-AT-vdesmedt.com>.
709 737
710 738 2005-02-12 Fernando Perez <fperez@colorado.edu>
711 739
712 740 * IPython/ipmaker.py (make_IPython): Disabled the stout traps
713 741 which I had written long ago to sort out user error messages which
714 742 may occur during startup. This seemed like a good idea initially,
715 743 but it has proven a disaster in retrospect. I don't want to
716 744 change much code for now, so my fix is to set the internal 'debug'
717 745 flag to true everywhere, whose only job was precisely to control
718 746 this subsystem. This closes issue 28 (as well as avoiding all
719 747 sorts of strange hangups which occur from time to time).
720 748
721 749 2005-02-07 Fernando Perez <fperez@colorado.edu>
722 750
723 751 * IPython/Magic.py (magic_edit): Fix 'ed -p' not working when the
724 752 previous call produced a syntax error.
725 753
726 754 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
727 755 classes without constructor.
728 756
729 757 2005-02-06 Fernando Perez <fperez@colorado.edu>
730 758
731 759 * IPython/iplib.py (MagicCompleter.complete): Extend the list of
732 760 completions with the results of each matcher, so we return results
733 761 to the user from all namespaces. This breaks with ipython
734 762 tradition, but I think it's a nicer behavior. Now you get all
735 763 possible completions listed, from all possible namespaces (python,
736 764 filesystem, magics...) After a request by John Hunter
737 765 <jdhunter-AT-nitace.bsd.uchicago.edu>.
738 766
739 767 2005-02-05 Fernando Perez <fperez@colorado.edu>
740 768
741 769 * IPython/Magic.py (magic_prun): Fix bug where prun would fail if
742 770 the call had quote characters in it (the quotes were stripped).
743 771
744 772 2005-01-31 Fernando Perez <fperez@colorado.edu>
745 773
746 774 * IPython/iplib.py (InteractiveShell.__init__): reduce reliance on
747 775 Itpl.itpl() to make the code more robust against psyco
748 776 optimizations.
749 777
750 778 * IPython/Itpl.py (Itpl.__str__): Use a _getframe() call instead
751 779 of causing an exception. Quicker, cleaner.
752 780
753 781 2005-01-28 Fernando Perez <fperez@colorado.edu>
754 782
755 783 * scripts/ipython_win_post_install.py (install): hardcode
756 784 sys.prefix+'python.exe' as the executable path. It turns out that
757 785 during the post-installation run, sys.executable resolves to the
758 786 name of the binary installer! I should report this as a distutils
759 787 bug, I think. I updated the .10 release with this tiny fix, to
760 788 avoid annoying the lists further.
761 789
762 790 2005-01-27 *** Released version 0.6.10
763 791
764 792 2005-01-27 Fernando Perez <fperez@colorado.edu>
765 793
766 794 * IPython/numutils.py (norm): Added 'inf' as optional name for
767 795 L-infinity norm, included references to mathworld.com for vector
768 796 norm definitions.
769 797 (amin/amax): added amin/amax for array min/max. Similar to what
770 798 pylab ships with after the recent reorganization of names.
771 799 (spike/spike_odd): removed deprecated spike/spike_odd functions.
772 800
773 801 * ipython.el: committed Alex's recent fixes and improvements.
774 802 Tested with python-mode from CVS, and it looks excellent. Since
775 803 python-mode hasn't released anything in a while, I'm temporarily
776 804 putting a copy of today's CVS (v 4.70) of python-mode in:
777 805 http://ipython.scipy.org/tmp/python-mode.el
778 806
779 807 * scripts/ipython_win_post_install.py (install): Win32 fix to use
780 808 sys.executable for the executable name, instead of assuming it's
781 809 called 'python.exe' (the post-installer would have produced broken
782 810 setups on systems with a differently named python binary).
783 811
784 812 * IPython/PyColorize.py (Parser.__call__): change explicit '\n'
785 813 references to os.linesep, to make the code more
786 814 platform-independent. This is also part of the win32 coloring
787 815 fixes.
788 816
789 817 * IPython/genutils.py (page_dumb): Remove attempts to chop long
790 818 lines, which actually cause coloring bugs because the length of
791 819 the line is very difficult to correctly compute with embedded
792 820 escapes. This was the source of all the coloring problems under
793 821 Win32. I think that _finally_, Win32 users have a properly
794 822 working ipython in all respects. This would never have happened
795 823 if not for Gary Bishop and Viktor Ransmayr's great help and work.
796 824
797 825 2005-01-26 *** Released version 0.6.9
798 826
799 827 2005-01-25 Fernando Perez <fperez@colorado.edu>
800 828
801 829 * setup.py: finally, we have a true Windows installer, thanks to
802 830 the excellent work of Viktor Ransmayr
803 831 <viktor.ransmayr-AT-t-online.de>. The docs have been updated for
804 832 Windows users. The setup routine is quite a bit cleaner thanks to
805 833 this, and the post-install script uses the proper functions to
806 834 allow a clean de-installation using the standard Windows Control
807 835 Panel.
808 836
809 837 * IPython/genutils.py (get_home_dir): changed to use the $HOME
810 838 environment variable under all OSes (including win32) if
811 839 available. This will give consistency to win32 users who have set
812 840 this variable for any reason. If os.environ['HOME'] fails, the
813 841 previous policy of using HOMEDRIVE\HOMEPATH kicks in.
814 842
815 843 2005-01-24 Fernando Perez <fperez@colorado.edu>
816 844
817 845 * IPython/numutils.py (empty_like): add empty_like(), similar to
818 846 zeros_like() but taking advantage of the new empty() Numeric routine.
819 847
820 848 2005-01-23 *** Released version 0.6.8
821 849
822 850 2005-01-22 Fernando Perez <fperez@colorado.edu>
823 851
824 852 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): I removed the
825 853 automatic show() calls. After discussing things with JDH, it
826 854 turns out there are too many corner cases where this can go wrong.
827 855 It's best not to try to be 'too smart', and simply have ipython
828 856 reproduce as much as possible the default behavior of a normal
829 857 python shell.
830 858
831 859 * IPython/iplib.py (InteractiveShell.__init__): Modified the
832 860 line-splitting regexp and _prefilter() to avoid calling getattr()
833 861 on assignments. This closes
834 862 http://www.scipy.net/roundup/ipython/issue24. Note that Python's
835 863 readline uses getattr(), so a simple <TAB> keypress is still
836 864 enough to trigger getattr() calls on an object.
837 865
838 866 2005-01-21 Fernando Perez <fperez@colorado.edu>
839 867
840 868 * IPython/Shell.py (MatplotlibShellBase.magic_run): Fix the %run
841 869 docstring under pylab so it doesn't mask the original.
842 870
843 871 2005-01-21 *** Released version 0.6.7
844 872
845 873 2005-01-21 Fernando Perez <fperez@colorado.edu>
846 874
847 875 * IPython/Shell.py (MTInteractiveShell.runcode): Trap a crash with
848 876 signal handling for win32 users in multithreaded mode.
849 877
850 878 2005-01-17 Fernando Perez <fperez@colorado.edu>
851 879
852 880 * IPython/OInspect.py (Inspector.pinfo): Fix crash when inspecting
853 881 instances with no __init__. After a crash report by Norbert Nemec
854 882 <Norbert-AT-nemec-online.de>.
855 883
856 884 2005-01-14 Fernando Perez <fperez@colorado.edu>
857 885
858 886 * IPython/ultraTB.py (VerboseTB.text): Fix bug in reporting of
859 887 names for verbose exceptions, when multiple dotted names and the
860 888 'parent' object were present on the same line.
861 889
862 890 2005-01-11 Fernando Perez <fperez@colorado.edu>
863 891
864 892 * IPython/genutils.py (flag_calls): new utility to trap and flag
865 893 calls in functions. I need it to clean up matplotlib support.
866 894 Also removed some deprecated code in genutils.
867 895
868 896 * IPython/Shell.py (MatplotlibShellBase.mplot_exec): small fix so
869 897 that matplotlib scripts called with %run, which don't call show()
870 898 themselves, still have their plotting windows open.
871 899
872 900 2005-01-05 Fernando Perez <fperez@colorado.edu>
873 901
874 902 * IPython/Shell.py (IPShellGTK.__init__): Patch by Andrew Straw
875 903 <astraw-AT-caltech.edu>, to fix gtk deprecation warnings.
876 904
877 905 2004-12-19 Fernando Perez <fperez@colorado.edu>
878 906
879 907 * IPython/Shell.py (MTInteractiveShell.runcode): Get rid of
880 908 parent_runcode, which was an eyesore. The same result can be
881 909 obtained with Python's regular superclass mechanisms.
882 910
883 911 2004-12-17 Fernando Perez <fperez@colorado.edu>
884 912
885 913 * IPython/Magic.py (Magic.magic_sc): Fix quote stripping problem
886 914 reported by Prabhu.
887 915 (Magic.magic_sx): direct all errors to Term.cerr (defaults to
888 916 sys.stderr) instead of explicitly calling sys.stderr. This helps
889 917 maintain our I/O abstractions clean, for future GUI embeddings.
890 918
891 919 * IPython/genutils.py (info): added new utility for sys.stderr
892 920 unified info message handling (thin wrapper around warn()).
893 921
894 922 * IPython/ultraTB.py (VerboseTB.text): Fix misreported global
895 923 composite (dotted) names on verbose exceptions.
896 924 (VerboseTB.nullrepr): harden against another kind of errors which
897 925 Python's inspect module can trigger, and which were crashing
898 926 IPython. Thanks to a report by Marco Lombardi
899 927 <mlombard-AT-ma010192.hq.eso.org>.
900 928
901 929 2004-12-13 *** Released version 0.6.6
902 930
903 931 2004-12-12 Fernando Perez <fperez@colorado.edu>
904 932
905 933 * IPython/Shell.py (IPShellGTK.mainloop): catch RuntimeErrors
906 934 generated by pygtk upon initialization if it was built without
907 935 threads (for matplotlib users). After a crash reported by
908 936 Leguijt, Jaap J SIEP-EPT-RES <Jaap.Leguijt-AT-shell.com>.
909 937
910 938 * IPython/ipmaker.py (make_IPython): fix small bug in the
911 939 import_some parameter for multiple imports.
912 940
913 941 * IPython/iplib.py (ipmagic): simplified the interface of
914 942 ipmagic() to take a single string argument, just as it would be
915 943 typed at the IPython cmd line.
916 944 (ipalias): Added new ipalias() with an interface identical to
917 945 ipmagic(). This completes exposing a pure python interface to the
918 946 alias and magic system, which can be used in loops or more complex
919 947 code where IPython's automatic line mangling is not active.
920 948
921 949 * IPython/genutils.py (timing): changed interface of timing to
922 950 simply run code once, which is the most common case. timings()
923 951 remains unchanged, for the cases where you want multiple runs.
924 952
925 953 * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix a
926 954 bug where Python2.2 crashes with exec'ing code which does not end
927 955 in a single newline. Python 2.3 is OK, so I hadn't noticed this
928 956 before.
929 957
930 958 2004-12-10 Fernando Perez <fperez@colorado.edu>
931 959
932 960 * IPython/Magic.py (Magic.magic_prun): changed name of option from
933 961 -t to -T, to accomodate the new -t flag in %run (the %run and
934 962 %prun options are kind of intermixed, and it's not easy to change
935 963 this with the limitations of python's getopt).
936 964
937 965 * IPython/Magic.py (Magic.magic_run): Added new -t option to time
938 966 the execution of scripts. It's not as fine-tuned as timeit.py,
939 967 but it works from inside ipython (and under 2.2, which lacks
940 968 timeit.py). Optionally a number of runs > 1 can be given for
941 969 timing very short-running code.
942 970
943 971 * IPython/genutils.py (uniq_stable): new routine which returns a
944 972 list of unique elements in any iterable, but in stable order of
945 973 appearance. I needed this for the ultraTB fixes, and it's a handy
946 974 utility.
947 975
948 976 * IPython/ultraTB.py (VerboseTB.text): Fix proper reporting of
949 977 dotted names in Verbose exceptions. This had been broken since
950 978 the very start, now x.y will properly be printed in a Verbose
951 979 traceback, instead of x being shown and y appearing always as an
952 980 'undefined global'. Getting this to work was a bit tricky,
953 981 because by default python tokenizers are stateless. Saved by
954 982 python's ability to easily add a bit of state to an arbitrary
955 983 function (without needing to build a full-blown callable object).
956 984
957 985 Also big cleanup of this code, which had horrendous runtime
958 986 lookups of zillions of attributes for colorization. Moved all
959 987 this code into a few templates, which make it cleaner and quicker.
960 988
961 989 Printout quality was also improved for Verbose exceptions: one
962 990 variable per line, and memory addresses are printed (this can be
963 991 quite handy in nasty debugging situations, which is what Verbose
964 992 is for).
965 993
966 994 * IPython/ipmaker.py (make_IPython): Do NOT execute files named in
967 995 the command line as scripts to be loaded by embedded instances.
968 996 Doing so has the potential for an infinite recursion if there are
969 997 exceptions thrown in the process. This fixes a strange crash
970 998 reported by Philippe MULLER <muller-AT-irit.fr>.
971 999
972 1000 2004-12-09 Fernando Perez <fperez@colorado.edu>
973 1001
974 1002 * IPython/Shell.py (MatplotlibShellBase.use): Change pylab support
975 1003 to reflect new names in matplotlib, which now expose the
976 1004 matlab-compatible interface via a pylab module instead of the
977 1005 'matlab' name. The new code is backwards compatible, so users of
978 1006 all matplotlib versions are OK. Patch by J. Hunter.
979 1007
980 1008 * IPython/OInspect.py (Inspector.pinfo): Add to object? printing
981 1009 of __init__ docstrings for instances (class docstrings are already
982 1010 automatically printed). Instances with customized docstrings
983 1011 (indep. of the class) are also recognized and all 3 separate
984 1012 docstrings are printed (instance, class, constructor). After some
985 1013 comments/suggestions by J. Hunter.
986 1014
987 1015 2004-12-05 Fernando Perez <fperez@colorado.edu>
988 1016
989 1017 * IPython/iplib.py (MagicCompleter.complete): Remove annoying
990 1018 warnings when tab-completion fails and triggers an exception.
991 1019
992 1020 2004-12-03 Fernando Perez <fperez@colorado.edu>
993 1021
994 1022 * IPython/Magic.py (magic_prun): Fix bug where an exception would
995 1023 be triggered when using 'run -p'. An incorrect option flag was
996 1024 being set ('d' instead of 'D').
997 1025 (manpage): fix missing escaped \- sign.
998 1026
999 1027 2004-11-30 *** Released version 0.6.5
1000 1028
1001 1029 2004-11-30 Fernando Perez <fperez@colorado.edu>
1002 1030
1003 1031 * IPython/Magic.py (Magic.magic_run): Fix bug in breakpoint
1004 1032 setting with -d option.
1005 1033
1006 1034 * setup.py (docfiles): Fix problem where the doc glob I was using
1007 1035 was COMPLETELY BROKEN. It was giving the right files by pure
1008 1036 accident, but failed once I tried to include ipython.el. Note:
1009 1037 glob() does NOT allow you to do exclusion on multiple endings!
1010 1038
1011 1039 2004-11-29 Fernando Perez <fperez@colorado.edu>
1012 1040
1013 1041 * IPython/usage.py (__doc__): cleaned up usage docstring, by using
1014 1042 the manpage as the source. Better formatting & consistency.
1015 1043
1016 1044 * IPython/Magic.py (magic_run): Added new -d option, to run
1017 1045 scripts under the control of the python pdb debugger. Note that
1018 1046 this required changing the %prun option -d to -D, to avoid a clash
1019 1047 (since %run must pass options to %prun, and getopt is too dumb to
1020 1048 handle options with string values with embedded spaces). Thanks
1021 1049 to a suggestion by Matthew Arnison <maffew-AT-cat.org.au>.
1022 1050 (magic_who_ls): added type matching to %who and %whos, so that one
1023 1051 can filter their output to only include variables of certain
1024 1052 types. Another suggestion by Matthew.
1025 1053 (magic_whos): Added memory summaries in kb and Mb for arrays.
1026 1054 (magic_who): Improve formatting (break lines every 9 vars).
1027 1055
1028 1056 2004-11-28 Fernando Perez <fperez@colorado.edu>
1029 1057
1030 1058 * IPython/Logger.py (Logger.log): Fix bug in syncing the input
1031 1059 cache when empty lines were present.
1032 1060
1033 1061 2004-11-24 Fernando Perez <fperez@colorado.edu>
1034 1062
1035 1063 * IPython/usage.py (__doc__): document the re-activated threading
1036 1064 options for WX and GTK.
1037 1065
1038 1066 2004-11-23 Fernando Perez <fperez@colorado.edu>
1039 1067
1040 1068 * IPython/Shell.py (start): Added Prabhu's big patch to reactivate
1041 1069 the -wthread and -gthread options, along with a new -tk one to try
1042 1070 and coordinate Tk threading with wx/gtk. The tk support is very
1043 1071 platform dependent, since it seems to require Tcl and Tk to be
1044 1072 built with threads (Fedora1/2 appears NOT to have it, but in
1045 1073 Prabhu's Debian boxes it works OK). But even with some Tk
1046 1074 limitations, this is a great improvement.
1047 1075
1048 1076 * IPython/Prompts.py (prompt_specials_color): Added \t for time
1049 1077 info in user prompts. Patch by Prabhu.
1050 1078
1051 1079 2004-11-18 Fernando Perez <fperez@colorado.edu>
1052 1080
1053 1081 * IPython/genutils.py (ask_yes_no): Add check for a max of 20
1054 1082 EOFErrors and bail, to avoid infinite loops if a non-terminating
1055 1083 file is fed into ipython. Patch submitted in issue 19 by user,
1056 1084 many thanks.
1057 1085
1058 1086 * IPython/iplib.py (InteractiveShell.handle_auto): do NOT trigger
1059 1087 autoquote/parens in continuation prompts, which can cause lots of
1060 1088 problems. Closes roundup issue 20.
1061 1089
1062 1090 2004-11-17 Fernando Perez <fperez@colorado.edu>
1063 1091
1064 1092 * debian/control (Build-Depends-Indep): Fix dpatch dependency,
1065 1093 reported as debian bug #280505. I'm not sure my local changelog
1066 1094 entry has the proper debian format (Jack?).
1067 1095
1068 1096 2004-11-08 *** Released version 0.6.4
1069 1097
1070 1098 2004-11-08 Fernando Perez <fperez@colorado.edu>
1071 1099
1072 1100 * IPython/iplib.py (init_readline): Fix exit message for Windows
1073 1101 when readline is active. Thanks to a report by Eric Jones
1074 1102 <eric-AT-enthought.com>.
1075 1103
1076 1104 2004-11-07 Fernando Perez <fperez@colorado.edu>
1077 1105
1078 1106 * IPython/genutils.py (page): Add a trap for OSError exceptions,
1079 1107 sometimes seen by win2k/cygwin users.
1080 1108
1081 1109 2004-11-06 Fernando Perez <fperez@colorado.edu>
1082 1110
1083 1111 * IPython/iplib.py (interact): Change the handling of %Exit from
1084 1112 trying to propagate a SystemExit to an internal ipython flag.
1085 1113 This is less elegant than using Python's exception mechanism, but
1086 1114 I can't get that to work reliably with threads, so under -pylab
1087 1115 %Exit was hanging IPython. Cross-thread exception handling is
1088 1116 really a bitch. Thaks to a bug report by Stephen Walton
1089 1117 <stephen.walton-AT-csun.edu>.
1090 1118
1091 1119 2004-11-04 Fernando Perez <fperez@colorado.edu>
1092 1120
1093 1121 * IPython/iplib.py (raw_input_original): store a pointer to the
1094 1122 true raw_input to harden against code which can modify it
1095 1123 (wx.py.PyShell does this and would otherwise crash ipython).
1096 1124 Thanks to a bug report by Jim Flowers <james.flowers-AT-lgx.com>.
1097 1125
1098 1126 * IPython/Shell.py (MTInteractiveShell.runsource): Cleaner fix for
1099 1127 Ctrl-C problem, which does not mess up the input line.
1100 1128
1101 1129 2004-11-03 Fernando Perez <fperez@colorado.edu>
1102 1130
1103 1131 * IPython/Release.py: Changed licensing to BSD, in all files.
1104 1132 (name): lowercase name for tarball/RPM release.
1105 1133
1106 1134 * IPython/OInspect.py (getdoc): wrap inspect.getdoc() safely for
1107 1135 use throughout ipython.
1108 1136
1109 1137 * IPython/Magic.py (Magic._ofind): Switch to using the new
1110 1138 OInspect.getdoc() function.
1111 1139
1112 1140 * IPython/Shell.py (sigint_handler): Hack to ignore the execution
1113 1141 of the line currently being canceled via Ctrl-C. It's extremely
1114 1142 ugly, but I don't know how to do it better (the problem is one of
1115 1143 handling cross-thread exceptions).
1116 1144
1117 1145 2004-10-28 Fernando Perez <fperez@colorado.edu>
1118 1146
1119 1147 * IPython/Shell.py (signal_handler): add signal handlers to trap
1120 1148 SIGINT and SIGSEGV in threaded code properly. Thanks to a bug
1121 1149 report by Francesc Alted.
1122 1150
1123 1151 2004-10-21 Fernando Perez <fperez@colorado.edu>
1124 1152
1125 1153 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Fix @
1126 1154 to % for pysh syntax extensions.
1127 1155
1128 1156 2004-10-09 Fernando Perez <fperez@colorado.edu>
1129 1157
1130 1158 * IPython/Magic.py (Magic.magic_whos): modify output of Numeric
1131 1159 arrays to print a more useful summary, without calling str(arr).
1132 1160 This avoids the problem of extremely lengthy computations which
1133 1161 occur if arr is large, and appear to the user as a system lockup
1134 1162 with 100% cpu activity. After a suggestion by Kristian Sandberg
1135 1163 <Kristian.Sandberg@colorado.edu>.
1136 1164 (Magic.__init__): fix bug in global magic escapes not being
1137 1165 correctly set.
1138 1166
1139 1167 2004-10-08 Fernando Perez <fperez@colorado.edu>
1140 1168
1141 1169 * IPython/Magic.py (__license__): change to absolute imports of
1142 1170 ipython's own internal packages, to start adapting to the absolute
1143 1171 import requirement of PEP-328.
1144 1172
1145 1173 * IPython/genutils.py (__author__): Fix coding to utf-8 on all
1146 1174 files, and standardize author/license marks through the Release
1147 1175 module instead of having per/file stuff (except for files with
1148 1176 particular licenses, like the MIT/PSF-licensed codes).
1149 1177
1150 1178 * IPython/Debugger.py: remove dead code for python 2.1
1151 1179
1152 1180 2004-10-04 Fernando Perez <fperez@colorado.edu>
1153 1181
1154 1182 * IPython/iplib.py (ipmagic): New function for accessing magics
1155 1183 via a normal python function call.
1156 1184
1157 1185 * IPython/Magic.py (Magic.magic_magic): Change the magic escape
1158 1186 from '@' to '%', to accomodate the new @decorator syntax of python
1159 1187 2.4.
1160 1188
1161 1189 2004-09-29 Fernando Perez <fperez@colorado.edu>
1162 1190
1163 1191 * IPython/Shell.py (MatplotlibShellBase.use): Added a wrapper to
1164 1192 matplotlib.use to prevent running scripts which try to switch
1165 1193 interactive backends from within ipython. This will just crash
1166 1194 the python interpreter, so we can't allow it (but a detailed error
1167 1195 is given to the user).
1168 1196
1169 1197 2004-09-28 Fernando Perez <fperez@colorado.edu>
1170 1198
1171 1199 * IPython/Shell.py (MatplotlibShellBase.mplot_exec):
1172 1200 matplotlib-related fixes so that using @run with non-matplotlib
1173 1201 scripts doesn't pop up spurious plot windows. This requires
1174 1202 matplotlib >= 0.63, where I had to make some changes as well.
1175 1203
1176 1204 * IPython/ipmaker.py (make_IPython): update version requirement to
1177 1205 python 2.2.
1178 1206
1179 1207 * IPython/iplib.py (InteractiveShell.mainloop): Add an optional
1180 1208 banner arg for embedded customization.
1181 1209
1182 1210 * IPython/Magic.py (Magic.__init__): big cleanup to remove all
1183 1211 explicit uses of __IP as the IPython's instance name. Now things
1184 1212 are properly handled via the shell.name value. The actual code
1185 1213 is a bit ugly b/c I'm doing it via a global in Magic.py, but this
1186 1214 is much better than before. I'll clean things completely when the
1187 1215 magic stuff gets a real overhaul.
1188 1216
1189 1217 * ipython.1: small fixes, sent in by Jack Moffit. He also sent in
1190 1218 minor changes to debian dir.
1191 1219
1192 1220 * IPython/iplib.py (InteractiveShell.__init__): Fix adding a
1193 1221 pointer to the shell itself in the interactive namespace even when
1194 1222 a user-supplied dict is provided. This is needed for embedding
1195 1223 purposes (found by tests with Michel Sanner).
1196 1224
1197 1225 2004-09-27 Fernando Perez <fperez@colorado.edu>
1198 1226
1199 1227 * IPython/UserConfig/ipythonrc: remove []{} from
1200 1228 readline_remove_delims, so that things like [modname.<TAB> do
1201 1229 proper completion. This disables [].TAB, but that's a less common
1202 1230 case than module names in list comprehensions, for example.
1203 1231 Thanks to a report by Andrea Riciputi.
1204 1232
1205 1233 2004-09-09 Fernando Perez <fperez@colorado.edu>
1206 1234
1207 1235 * IPython/Shell.py (IPShellGTK.mainloop): reorder to avoid
1208 1236 blocking problems in win32 and osx. Fix by John.
1209 1237
1210 1238 2004-09-08 Fernando Perez <fperez@colorado.edu>
1211 1239
1212 1240 * IPython/Shell.py (IPShellWX.OnInit): Fix output redirection bug
1213 1241 for Win32 and OSX. Fix by John Hunter.
1214 1242
1215 1243 2004-08-30 *** Released version 0.6.3
1216 1244
1217 1245 2004-08-30 Fernando Perez <fperez@colorado.edu>
1218 1246
1219 1247 * setup.py (isfile): Add manpages to list of dependent files to be
1220 1248 updated.
1221 1249
1222 1250 2004-08-27 Fernando Perez <fperez@colorado.edu>
1223 1251
1224 1252 * IPython/Shell.py (start): I've disabled -wthread and -gthread
1225 1253 for now. They don't really work with standalone WX/GTK code
1226 1254 (though matplotlib IS working fine with both of those backends).
1227 1255 This will neeed much more testing. I disabled most things with
1228 1256 comments, so turning it back on later should be pretty easy.
1229 1257
1230 1258 * IPython/iplib.py (InteractiveShell.__init__): Fix accidental
1231 1259 autocalling of expressions like r'foo', by modifying the line
1232 1260 split regexp. Closes
1233 1261 http://www.scipy.net/roundup/ipython/issue18, reported by Nicholas
1234 1262 Riley <ipythonbugs-AT-sabi.net>.
1235 1263 (InteractiveShell.mainloop): honor --nobanner with banner
1236 1264 extensions.
1237 1265
1238 1266 * IPython/Shell.py: Significant refactoring of all classes, so
1239 1267 that we can really support ALL matplotlib backends and threading
1240 1268 models (John spotted a bug with Tk which required this). Now we
1241 1269 should support single-threaded, WX-threads and GTK-threads, both
1242 1270 for generic code and for matplotlib.
1243 1271
1244 1272 * IPython/ipmaker.py (__call__): Changed -mpthread option to
1245 1273 -pylab, to simplify things for users. Will also remove the pylab
1246 1274 profile, since now all of matplotlib configuration is directly
1247 1275 handled here. This also reduces startup time.
1248 1276
1249 1277 * IPython/Shell.py (IPShellGTK.run): Fixed bug where mainloop() of
1250 1278 shell wasn't being correctly called. Also in IPShellWX.
1251 1279
1252 1280 * IPython/iplib.py (InteractiveShell.__init__): Added option to
1253 1281 fine-tune banner.
1254 1282
1255 1283 * IPython/numutils.py (spike): Deprecate these spike functions,
1256 1284 delete (long deprecated) gnuplot_exec handler.
1257 1285
1258 1286 2004-08-26 Fernando Perez <fperez@colorado.edu>
1259 1287
1260 1288 * ipython.1: Update for threading options, plus some others which
1261 1289 were missing.
1262 1290
1263 1291 * IPython/ipmaker.py (__call__): Added -wthread option for
1264 1292 wxpython thread handling. Make sure threading options are only
1265 1293 valid at the command line.
1266 1294
1267 1295 * scripts/ipython: moved shell selection into a factory function
1268 1296 in Shell.py, to keep the starter script to a minimum.
1269 1297
1270 1298 2004-08-25 Fernando Perez <fperez@colorado.edu>
1271 1299
1272 1300 * IPython/Shell.py (IPShellWX.wxexit): fixes to WX threading, by
1273 1301 John. Along with some recent changes he made to matplotlib, the
1274 1302 next versions of both systems should work very well together.
1275 1303
1276 1304 2004-08-24 Fernando Perez <fperez@colorado.edu>
1277 1305
1278 1306 * IPython/Magic.py (Magic.magic_prun): cleanup some dead code. I
1279 1307 tried to switch the profiling to using hotshot, but I'm getting
1280 1308 strange errors from prof.runctx() there. I may be misreading the
1281 1309 docs, but it looks weird. For now the profiling code will
1282 1310 continue to use the standard profiler.
1283 1311
1284 1312 2004-08-23 Fernando Perez <fperez@colorado.edu>
1285 1313
1286 1314 * IPython/Shell.py (IPShellWX.__init__): Improvements to the WX
1287 1315 threaded shell, by John Hunter. It's not quite ready yet, but
1288 1316 close.
1289 1317
1290 1318 2004-08-22 Fernando Perez <fperez@colorado.edu>
1291 1319
1292 1320 * IPython/iplib.py (InteractiveShell.interact): tab cleanups, also
1293 1321 in Magic and ultraTB.
1294 1322
1295 1323 * ipython.1: document threading options in manpage.
1296 1324
1297 1325 * scripts/ipython: Changed name of -thread option to -gthread,
1298 1326 since this is GTK specific. I want to leave the door open for a
1299 1327 -wthread option for WX, which will most likely be necessary. This
1300 1328 change affects usage and ipmaker as well.
1301 1329
1302 1330 * IPython/Shell.py (matplotlib_shell): Add a factory function to
1303 1331 handle the matplotlib shell issues. Code by John Hunter
1304 1332 <jdhunter-AT-nitace.bsd.uchicago.edu>.
1305 1333 (IPShellMatplotlibWX.__init__): Rudimentary WX support. It's
1306 1334 broken (and disabled for end users) for now, but it puts the
1307 1335 infrastructure in place.
1308 1336
1309 1337 2004-08-21 Fernando Perez <fperez@colorado.edu>
1310 1338
1311 1339 * ipythonrc-pylab: Add matplotlib support.
1312 1340
1313 1341 * matplotlib_config.py: new files for matplotlib support, part of
1314 1342 the pylab profile.
1315 1343
1316 1344 * IPython/usage.py (__doc__): documented the threading options.
1317 1345
1318 1346 2004-08-20 Fernando Perez <fperez@colorado.edu>
1319 1347
1320 1348 * ipython: Modified the main calling routine to handle the -thread
1321 1349 and -mpthread options. This needs to be done as a top-level hack,
1322 1350 because it determines which class to instantiate for IPython
1323 1351 itself.
1324 1352
1325 1353 * IPython/Shell.py (MTInteractiveShell.__init__): New set of
1326 1354 classes to support multithreaded GTK operation without blocking,
1327 1355 and matplotlib with all backends. This is a lot of still very
1328 1356 experimental code, and threads are tricky. So it may still have a
1329 1357 few rough edges... This code owes a lot to
1330 1358 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65109, by
1331 1359 Brian # McErlean and John Finlay, to Antoon Pardon for fixes, and
1332 1360 to John Hunter for all the matplotlib work.
1333 1361
1334 1362 * IPython/ipmaker.py (__call__): Added -thread and -mpthread
1335 1363 options for gtk thread and matplotlib support.
1336 1364
1337 1365 2004-08-16 Fernando Perez <fperez@colorado.edu>
1338 1366
1339 1367 * IPython/iplib.py (InteractiveShell.__init__): don't trigger
1340 1368 autocall for things like p*q,p/q,p+q,p-q, when p is callable. Bug
1341 1369 reported by Stephen Walton <stephen.walton-AT-csun.edu>.
1342 1370
1343 1371 2004-08-11 Fernando Perez <fperez@colorado.edu>
1344 1372
1345 1373 * setup.py (isfile): Fix build so documentation gets updated for
1346 1374 rpms (it was only done for .tgz builds).
1347 1375
1348 1376 2004-08-10 Fernando Perez <fperez@colorado.edu>
1349 1377
1350 1378 * genutils.py (Term): Fix misspell of stdin stream (sin->cin).
1351 1379
1352 1380 * iplib.py : Silence syntax error exceptions in tab-completion.
1353 1381
1354 1382 2004-08-05 Fernando Perez <fperez@colorado.edu>
1355 1383
1356 1384 * IPython/Prompts.py (Prompt2.set_colors): Fix incorrectly set
1357 1385 'color off' mark for continuation prompts. This was causing long
1358 1386 continuation lines to mis-wrap.
1359 1387
1360 1388 2004-08-01 Fernando Perez <fperez@colorado.edu>
1361 1389
1362 1390 * IPython/ipmaker.py (make_IPython): Allow the shell class used
1363 1391 for building ipython to be a parameter. All this is necessary
1364 1392 right now to have a multithreaded version, but this insane
1365 1393 non-design will be cleaned up soon. For now, it's a hack that
1366 1394 works.
1367 1395
1368 1396 * IPython/Shell.py (IPShell.__init__): Stop using mutable default
1369 1397 args in various places. No bugs so far, but it's a dangerous
1370 1398 practice.
1371 1399
1372 1400 2004-07-31 Fernando Perez <fperez@colorado.edu>
1373 1401
1374 1402 * IPython/iplib.py (complete): ignore SyntaxError exceptions to
1375 1403 fix completion of files with dots in their names under most
1376 1404 profiles (pysh was OK because the completion order is different).
1377 1405
1378 1406 2004-07-27 Fernando Perez <fperez@colorado.edu>
1379 1407
1380 1408 * IPython/iplib.py (InteractiveShell.__init__): build dict of
1381 1409 keywords manually, b/c the one in keyword.py was removed in python
1382 1410 2.4. Patch by Anakim Border <aborder-AT-users.sourceforge.net>.
1383 1411 This is NOT a bug under python 2.3 and earlier.
1384 1412
1385 1413 2004-07-26 Fernando Perez <fperez@colorado.edu>
1386 1414
1387 1415 * IPython/ultraTB.py (VerboseTB.text): Add another
1388 1416 linecache.checkcache() call to try to prevent inspect.py from
1389 1417 crashing under python 2.3. I think this fixes
1390 1418 http://www.scipy.net/roundup/ipython/issue17.
1391 1419
1392 1420 2004-07-26 *** Released version 0.6.2
1393 1421
1394 1422 2004-07-26 Fernando Perez <fperez@colorado.edu>
1395 1423
1396 1424 * IPython/Magic.py (Magic.magic_cd): Fix bug where 'cd -N' would
1397 1425 fail for any number.
1398 1426 (Magic.magic_bookmark): Fix bug where 'bookmark -l' would fail for
1399 1427 empty bookmarks.
1400 1428
1401 1429 2004-07-26 *** Released version 0.6.1
1402 1430
1403 1431 2004-07-26 Fernando Perez <fperez@colorado.edu>
1404 1432
1405 1433 * ipython_win_post_install.py (run): Added pysh shortcut for Windows.
1406 1434
1407 1435 * IPython/iplib.py (protect_filename): Applied Ville's patch for
1408 1436 escaping '()[]{}' in filenames.
1409 1437
1410 1438 * IPython/Magic.py (shlex_split): Fix handling of '*' and '?' for
1411 1439 Python 2.2 users who lack a proper shlex.split.
1412 1440
1413 1441 2004-07-19 Fernando Perez <fperez@colorado.edu>
1414 1442
1415 1443 * IPython/iplib.py (InteractiveShell.init_readline): Add support
1416 1444 for reading readline's init file. I follow the normal chain:
1417 1445 $INPUTRC is honored, otherwise ~/.inputrc is used. Thanks to a
1418 1446 report by Mike Heeter. This closes
1419 1447 http://www.scipy.net/roundup/ipython/issue16.
1420 1448
1421 1449 2004-07-18 Fernando Perez <fperez@colorado.edu>
1422 1450
1423 1451 * IPython/iplib.py (__init__): Add better handling of '\' under
1424 1452 Win32 for filenames. After a patch by Ville.
1425 1453
1426 1454 2004-07-17 Fernando Perez <fperez@colorado.edu>
1427 1455
1428 1456 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
1429 1457 autocalling would be triggered for 'foo is bar' if foo is
1430 1458 callable. I also cleaned up the autocall detection code to use a
1431 1459 regexp, which is faster. Bug reported by Alexander Schmolck.
1432 1460
1433 1461 * IPython/Magic.py (Magic.magic_pinfo): Fix bug where strings with
1434 1462 '?' in them would confuse the help system. Reported by Alex
1435 1463 Schmolck.
1436 1464
1437 1465 2004-07-16 Fernando Perez <fperez@colorado.edu>
1438 1466
1439 1467 * IPython/GnuplotInteractive.py (__all__): added plot2.
1440 1468
1441 1469 * IPython/Gnuplot2.py (Gnuplot.plot2): added new function for
1442 1470 plotting dictionaries, lists or tuples of 1d arrays.
1443 1471
1444 1472 * IPython/Magic.py (Magic.magic_hist): small clenaups and
1445 1473 optimizations.
1446 1474
1447 1475 * IPython/iplib.py:Remove old Changelog info for cleanup. This is
1448 1476 the information which was there from Janko's original IPP code:
1449 1477
1450 1478 03.05.99 20:53 porto.ifm.uni-kiel.de
1451 1479 --Started changelog.
1452 1480 --make clear do what it say it does
1453 1481 --added pretty output of lines from inputcache
1454 1482 --Made Logger a mixin class, simplifies handling of switches
1455 1483 --Added own completer class. .string<TAB> expands to last history
1456 1484 line which starts with string. The new expansion is also present
1457 1485 with Ctrl-r from the readline library. But this shows, who this
1458 1486 can be done for other cases.
1459 1487 --Added convention that all shell functions should accept a
1460 1488 parameter_string This opens the door for different behaviour for
1461 1489 each function. @cd is a good example of this.
1462 1490
1463 1491 04.05.99 12:12 porto.ifm.uni-kiel.de
1464 1492 --added logfile rotation
1465 1493 --added new mainloop method which freezes first the namespace
1466 1494
1467 1495 07.05.99 21:24 porto.ifm.uni-kiel.de
1468 1496 --added the docreader classes. Now there is a help system.
1469 1497 -This is only a first try. Currently it's not easy to put new
1470 1498 stuff in the indices. But this is the way to go. Info would be
1471 1499 better, but HTML is every where and not everybody has an info
1472 1500 system installed and it's not so easy to change html-docs to info.
1473 1501 --added global logfile option
1474 1502 --there is now a hook for object inspection method pinfo needs to
1475 1503 be provided for this. Can be reached by two '??'.
1476 1504
1477 1505 08.05.99 20:51 porto.ifm.uni-kiel.de
1478 1506 --added a README
1479 1507 --bug in rc file. Something has changed so functions in the rc
1480 1508 file need to reference the shell and not self. Not clear if it's a
1481 1509 bug or feature.
1482 1510 --changed rc file for new behavior
1483 1511
1484 1512 2004-07-15 Fernando Perez <fperez@colorado.edu>
1485 1513
1486 1514 * IPython/Logger.py (Logger.log): fixed recent bug where the input
1487 1515 cache was falling out of sync in bizarre manners when multi-line
1488 1516 input was present. Minor optimizations and cleanup.
1489 1517
1490 1518 (Logger): Remove old Changelog info for cleanup. This is the
1491 1519 information which was there from Janko's original code:
1492 1520
1493 1521 Changes to Logger: - made the default log filename a parameter
1494 1522
1495 1523 - put a check for lines beginning with !@? in log(). Needed
1496 1524 (even if the handlers properly log their lines) for mid-session
1497 1525 logging activation to work properly. Without this, lines logged
1498 1526 in mid session, which get read from the cache, would end up
1499 1527 'bare' (with !@? in the open) in the log. Now they are caught
1500 1528 and prepended with a #.
1501 1529
1502 1530 * IPython/iplib.py (InteractiveShell.init_readline): added check
1503 1531 in case MagicCompleter fails to be defined, so we don't crash.
1504 1532
1505 1533 2004-07-13 Fernando Perez <fperez@colorado.edu>
1506 1534
1507 1535 * IPython/Gnuplot2.py (Gnuplot.hardcopy): add automatic generation
1508 1536 of EPS if the requested filename ends in '.eps'.
1509 1537
1510 1538 2004-07-04 Fernando Perez <fperez@colorado.edu>
1511 1539
1512 1540 * IPython/iplib.py (InteractiveShell.handle_shell_escape): Fix
1513 1541 escaping of quotes when calling the shell.
1514 1542
1515 1543 2004-07-02 Fernando Perez <fperez@colorado.edu>
1516 1544
1517 1545 * IPython/Prompts.py (CachedOutput.update): Fix problem with
1518 1546 gettext not working because we were clobbering '_'. Fixes
1519 1547 http://www.scipy.net/roundup/ipython/issue6.
1520 1548
1521 1549 2004-07-01 Fernando Perez <fperez@colorado.edu>
1522 1550
1523 1551 * IPython/Magic.py (Magic.magic_cd): integrated bookmark handling
1524 1552 into @cd. Patch by Ville.
1525 1553
1526 1554 * IPython/iplib.py (InteractiveShell.post_config_initialization):
1527 1555 new function to store things after ipmaker runs. Patch by Ville.
1528 1556 Eventually this will go away once ipmaker is removed and the class
1529 1557 gets cleaned up, but for now it's ok. Key functionality here is
1530 1558 the addition of the persistent storage mechanism, a dict for
1531 1559 keeping data across sessions (for now just bookmarks, but more can
1532 1560 be implemented later).
1533 1561
1534 1562 * IPython/Magic.py (Magic.magic_bookmark): New bookmark system,
1535 1563 persistent across sections. Patch by Ville, I modified it
1536 1564 soemwhat to allow bookmarking arbitrary dirs other than CWD. Also
1537 1565 added a '-l' option to list all bookmarks.
1538 1566
1539 1567 * IPython/iplib.py (InteractiveShell.atexit_operations): new
1540 1568 center for cleanup. Registered with atexit.register(). I moved
1541 1569 here the old exit_cleanup(). After a patch by Ville.
1542 1570
1543 1571 * IPython/Magic.py (get_py_filename): added '~' to the accepted
1544 1572 characters in the hacked shlex_split for python 2.2.
1545 1573
1546 1574 * IPython/iplib.py (file_matches): more fixes to filenames with
1547 1575 whitespace in them. It's not perfect, but limitations in python's
1548 1576 readline make it impossible to go further.
1549 1577
1550 1578 2004-06-29 Fernando Perez <fperez@colorado.edu>
1551 1579
1552 1580 * IPython/iplib.py (file_matches): escape whitespace correctly in
1553 1581 filename completions. Bug reported by Ville.
1554 1582
1555 1583 2004-06-28 Fernando Perez <fperez@colorado.edu>
1556 1584
1557 1585 * IPython/ipmaker.py (__call__): Added per-profile histories. Now
1558 1586 the history file will be called 'history-PROFNAME' (or just
1559 1587 'history' if no profile is loaded). I was getting annoyed at
1560 1588 getting my Numerical work history clobbered by pysh sessions.
1561 1589
1562 1590 * IPython/iplib.py (InteractiveShell.__init__): Internal
1563 1591 getoutputerror() function so that we can honor the system_verbose
1564 1592 flag for _all_ system calls. I also added escaping of #
1565 1593 characters here to avoid confusing Itpl.
1566 1594
1567 1595 * IPython/Magic.py (shlex_split): removed call to shell in
1568 1596 parse_options and replaced it with shlex.split(). The annoying
1569 1597 part was that in Python 2.2, shlex.split() doesn't exist, so I had
1570 1598 to backport it from 2.3, with several frail hacks (the shlex
1571 1599 module is rather limited in 2.2). Thanks to a suggestion by Ville
1572 1600 Vainio <vivainio@kolumbus.fi>. For Python 2.3 there should be no
1573 1601 problem.
1574 1602
1575 1603 (Magic.magic_system_verbose): new toggle to print the actual
1576 1604 system calls made by ipython. Mainly for debugging purposes.
1577 1605
1578 1606 * IPython/GnuplotRuntime.py (gnu_out): fix bug for cygwin, which
1579 1607 doesn't support persistence. Reported (and fix suggested) by
1580 1608 Travis Caldwell <travis_caldwell2000@yahoo.com>.
1581 1609
1582 1610 2004-06-26 Fernando Perez <fperez@colorado.edu>
1583 1611
1584 1612 * IPython/Logger.py (Logger.log): fix to handle correctly empty
1585 1613 continue prompts.
1586 1614
1587 1615 * IPython/Extensions/InterpreterExec.py (pysh): moved the pysh()
1588 1616 function (basically a big docstring) and a few more things here to
1589 1617 speedup startup. pysh.py is now very lightweight. We want because
1590 1618 it gets execfile'd, while InterpreterExec gets imported, so
1591 1619 byte-compilation saves time.
1592 1620
1593 1621 2004-06-25 Fernando Perez <fperez@colorado.edu>
1594 1622
1595 1623 * IPython/Magic.py (Magic.magic_cd): Fixed to restore usage of 'cd
1596 1624 -NUM', which was recently broken.
1597 1625
1598 1626 * IPython/iplib.py (InteractiveShell.handle_shell_escape): allow !
1599 1627 in multi-line input (but not !!, which doesn't make sense there).
1600 1628
1601 1629 * IPython/UserConfig/ipythonrc: made autoindent on by default.
1602 1630 It's just too useful, and people can turn it off in the less
1603 1631 common cases where it's a problem.
1604 1632
1605 1633 2004-06-24 Fernando Perez <fperez@colorado.edu>
1606 1634
1607 1635 * IPython/iplib.py (InteractiveShell._prefilter): big change -
1608 1636 special syntaxes (like alias calling) is now allied in multi-line
1609 1637 input. This is still _very_ experimental, but it's necessary for
1610 1638 efficient shell usage combining python looping syntax with system
1611 1639 calls. For now it's restricted to aliases, I don't think it
1612 1640 really even makes sense to have this for magics.
1613 1641
1614 1642 2004-06-23 Fernando Perez <fperez@colorado.edu>
1615 1643
1616 1644 * IPython/Extensions/InterpreterExec.py (prefilter_shell): Added
1617 1645 $var=cmd <=> @sc var=cmd and $$var=cmd <=> @sc -l var=cmd.
1618 1646
1619 1647 * IPython/Magic.py (Magic.magic_rehashx): modified to handle
1620 1648 extensions under Windows (after code sent by Gary Bishop). The
1621 1649 extensions considered 'executable' are stored in IPython's rc
1622 1650 structure as win_exec_ext.
1623 1651
1624 1652 * IPython/genutils.py (shell): new function, like system() but
1625 1653 without return value. Very useful for interactive shell work.
1626 1654
1627 1655 * IPython/Magic.py (Magic.magic_unalias): New @unalias function to
1628 1656 delete aliases.
1629 1657
1630 1658 * IPython/iplib.py (InteractiveShell.alias_table_update): make
1631 1659 sure that the alias table doesn't contain python keywords.
1632 1660
1633 1661 2004-06-21 Fernando Perez <fperez@colorado.edu>
1634 1662
1635 1663 * IPython/Magic.py (Magic.magic_rehash): Fix crash when
1636 1664 non-existent items are found in $PATH. Reported by Thorsten.
1637 1665
1638 1666 2004-06-20 Fernando Perez <fperez@colorado.edu>
1639 1667
1640 1668 * IPython/iplib.py (complete): modified the completer so that the
1641 1669 order of priorities can be easily changed at runtime.
1642 1670
1643 1671 * IPython/Extensions/InterpreterExec.py (prefilter_shell):
1644 1672 Modified to auto-execute all lines beginning with '~', '/' or '.'.
1645 1673
1646 1674 * IPython/Magic.py (Magic.magic_sx): modified @sc and @sx to
1647 1675 expand Python variables prepended with $ in all system calls. The
1648 1676 same was done to InteractiveShell.handle_shell_escape. Now all
1649 1677 system access mechanisms (!, !!, @sc, @sx and aliases) allow the
1650 1678 expansion of python variables and expressions according to the
1651 1679 syntax of PEP-215 - http://www.python.org/peps/pep-0215.html.
1652 1680
1653 1681 Though PEP-215 has been rejected, a similar (but simpler) one
1654 1682 seems like it will go into Python 2.4, PEP-292 -
1655 1683 http://www.python.org/peps/pep-0292.html.
1656 1684
1657 1685 I'll keep the full syntax of PEP-215, since IPython has since the
1658 1686 start used Ka-Ping Yee's reference implementation discussed there
1659 1687 (Itpl), and I actually like the powerful semantics it offers.
1660 1688
1661 1689 In order to access normal shell variables, the $ has to be escaped
1662 1690 via an extra $. For example:
1663 1691
1664 1692 In [7]: PATH='a python variable'
1665 1693
1666 1694 In [8]: !echo $PATH
1667 1695 a python variable
1668 1696
1669 1697 In [9]: !echo $$PATH
1670 1698 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
1671 1699
1672 1700 (Magic.parse_options): escape $ so the shell doesn't evaluate
1673 1701 things prematurely.
1674 1702
1675 1703 * IPython/iplib.py (InteractiveShell.call_alias): added the
1676 1704 ability for aliases to expand python variables via $.
1677 1705
1678 1706 * IPython/Magic.py (Magic.magic_rehash): based on the new alias
1679 1707 system, now there's a @rehash/@rehashx pair of magics. These work
1680 1708 like the csh rehash command, and can be invoked at any time. They
1681 1709 build a table of aliases to everything in the user's $PATH
1682 1710 (@rehash uses everything, @rehashx is slower but only adds
1683 1711 executable files). With this, the pysh.py-based shell profile can
1684 1712 now simply call rehash upon startup, and full access to all
1685 1713 programs in the user's path is obtained.
1686 1714
1687 1715 * IPython/iplib.py (InteractiveShell.call_alias): The new alias
1688 1716 functionality is now fully in place. I removed the old dynamic
1689 1717 code generation based approach, in favor of a much lighter one
1690 1718 based on a simple dict. The advantage is that this allows me to
1691 1719 now have thousands of aliases with negligible cost (unthinkable
1692 1720 with the old system).
1693 1721
1694 1722 2004-06-19 Fernando Perez <fperez@colorado.edu>
1695 1723
1696 1724 * IPython/iplib.py (__init__): extended MagicCompleter class to
1697 1725 also complete (last in priority) on user aliases.
1698 1726
1699 1727 * IPython/Itpl.py (Itpl.__str__): fixed order of globals/locals in
1700 1728 call to eval.
1701 1729 (ItplNS.__init__): Added a new class which functions like Itpl,
1702 1730 but allows configuring the namespace for the evaluation to occur
1703 1731 in.
1704 1732
1705 1733 2004-06-18 Fernando Perez <fperez@colorado.edu>
1706 1734
1707 1735 * IPython/iplib.py (InteractiveShell.runcode): modify to print a
1708 1736 better message when 'exit' or 'quit' are typed (a common newbie
1709 1737 confusion).
1710 1738
1711 1739 * IPython/Magic.py (Magic.magic_colors): Added the runtime color
1712 1740 check for Windows users.
1713 1741
1714 1742 * IPython/iplib.py (InteractiveShell.user_setup): removed
1715 1743 disabling of colors for Windows. I'll test at runtime and issue a
1716 1744 warning if Gary's readline isn't found, as to nudge users to
1717 1745 download it.
1718 1746
1719 1747 2004-06-16 Fernando Perez <fperez@colorado.edu>
1720 1748
1721 1749 * IPython/genutils.py (Stream.__init__): changed to print errors
1722 1750 to sys.stderr. I had a circular dependency here. Now it's
1723 1751 possible to run ipython as IDLE's shell (consider this pre-alpha,
1724 1752 since true stdout things end up in the starting terminal instead
1725 1753 of IDLE's out).
1726 1754
1727 1755 * IPython/Prompts.py (Prompt2.set_colors): prevent crashes for
1728 1756 users who haven't # updated their prompt_in2 definitions. Remove
1729 1757 eventually.
1730 1758 (multiple_replace): added credit to original ASPN recipe.
1731 1759
1732 1760 2004-06-15 Fernando Perez <fperez@colorado.edu>
1733 1761
1734 1762 * IPython/iplib.py (InteractiveShell.__init__): add 'cp' to the
1735 1763 list of auto-defined aliases.
1736 1764
1737 1765 2004-06-13 Fernando Perez <fperez@colorado.edu>
1738 1766
1739 1767 * setup.py (scriptfiles): Don't trigger win_post_install unless an
1740 1768 install was really requested (so setup.py can be used for other
1741 1769 things under Windows).
1742 1770
1743 1771 2004-06-10 Fernando Perez <fperez@colorado.edu>
1744 1772
1745 1773 * IPython/Logger.py (Logger.create_log): Manually remove any old
1746 1774 backup, since os.remove may fail under Windows. Fixes bug
1747 1775 reported by Thorsten.
1748 1776
1749 1777 2004-06-09 Fernando Perez <fperez@colorado.edu>
1750 1778
1751 1779 * examples/example-embed.py: fixed all references to %n (replaced
1752 1780 with \\# for ps1/out prompts and with \\D for ps2 prompts). Done
1753 1781 for all examples and the manual as well.
1754 1782
1755 1783 2004-06-08 Fernando Perez <fperez@colorado.edu>
1756 1784
1757 1785 * IPython/Prompts.py (Prompt2.set_p_str): fixed all prompt
1758 1786 alignment and color management. All 3 prompt subsystems now
1759 1787 inherit from BasePrompt.
1760 1788
1761 1789 * tools/release: updates for windows installer build and tag rpms
1762 1790 with python version (since paths are fixed).
1763 1791
1764 1792 * IPython/UserConfig/ipythonrc: modified to use \# instead of %n,
1765 1793 which will become eventually obsolete. Also fixed the default
1766 1794 prompt_in2 to use \D, so at least new users start with the correct
1767 1795 defaults.
1768 1796 WARNING: Users with existing ipythonrc files will need to apply
1769 1797 this fix manually!
1770 1798
1771 1799 * setup.py: make windows installer (.exe). This is finally the
1772 1800 integration of an old patch by Cory Dodt <dodt-AT-fcoe.k12.ca.us>,
1773 1801 which I hadn't included because it required Python 2.3 (or recent
1774 1802 distutils).
1775 1803
1776 1804 * IPython/usage.py (__doc__): update docs (and manpage) to reflect
1777 1805 usage of new '\D' escape.
1778 1806
1779 1807 * IPython/Prompts.py (ROOT_SYMBOL): Small fix for Windows (which
1780 1808 lacks os.getuid())
1781 1809 (CachedOutput.set_colors): Added the ability to turn coloring
1782 1810 on/off with @colors even for manually defined prompt colors. It
1783 1811 uses a nasty global, but it works safely and via the generic color
1784 1812 handling mechanism.
1785 1813 (Prompt2.__init__): Introduced new escape '\D' for continuation
1786 1814 prompts. It represents the counter ('\#') as dots.
1787 1815 *** NOTE *** THIS IS A BACKWARDS-INCOMPATIBLE CHANGE. Users will
1788 1816 need to update their ipythonrc files and replace '%n' with '\D' in
1789 1817 their prompt_in2 settings everywhere. Sorry, but there's
1790 1818 otherwise no clean way to get all prompts to properly align. The
1791 1819 ipythonrc shipped with IPython has been updated.
1792 1820
1793 1821 2004-06-07 Fernando Perez <fperez@colorado.edu>
1794 1822
1795 1823 * setup.py (isfile): Pass local_icons option to latex2html, so the
1796 1824 resulting HTML file is self-contained. Thanks to
1797 1825 dryice-AT-liu.com.cn for the tip.
1798 1826
1799 1827 * pysh.py: I created a new profile 'shell', which implements a
1800 1828 _rudimentary_ IPython-based shell. This is in NO WAY a realy
1801 1829 system shell, nor will it become one anytime soon. It's mainly
1802 1830 meant to illustrate the use of the new flexible bash-like prompts.
1803 1831 I guess it could be used by hardy souls for true shell management,
1804 1832 but it's no tcsh/bash... pysh.py is loaded by the 'shell'
1805 1833 profile. This uses the InterpreterExec extension provided by
1806 1834 W.J. van der Laan <gnufnork-AT-hetdigitalegat.nl>
1807 1835
1808 1836 * IPython/Prompts.py (PromptOut.__str__): now it will correctly
1809 1837 auto-align itself with the length of the previous input prompt
1810 1838 (taking into account the invisible color escapes).
1811 1839 (CachedOutput.__init__): Large restructuring of this class. Now
1812 1840 all three prompts (primary1, primary2, output) are proper objects,
1813 1841 managed by the 'parent' CachedOutput class. The code is still a
1814 1842 bit hackish (all prompts share state via a pointer to the cache),
1815 1843 but it's overall far cleaner than before.
1816 1844
1817 1845 * IPython/genutils.py (getoutputerror): modified to add verbose,
1818 1846 debug and header options. This makes the interface of all getout*
1819 1847 functions uniform.
1820 1848 (SystemExec.getoutputerror): added getoutputerror to SystemExec.
1821 1849
1822 1850 * IPython/Magic.py (Magic.default_option): added a function to
1823 1851 allow registering default options for any magic command. This
1824 1852 makes it easy to have profiles which customize the magics globally
1825 1853 for a certain use. The values set through this function are
1826 1854 picked up by the parse_options() method, which all magics should
1827 1855 use to parse their options.
1828 1856
1829 1857 * IPython/genutils.py (warn): modified the warnings framework to
1830 1858 use the Term I/O class. I'm trying to slowly unify all of
1831 1859 IPython's I/O operations to pass through Term.
1832 1860
1833 1861 * IPython/Prompts.py (Prompt2._str_other): Added functionality in
1834 1862 the secondary prompt to correctly match the length of the primary
1835 1863 one for any prompt. Now multi-line code will properly line up
1836 1864 even for path dependent prompts, such as the new ones available
1837 1865 via the prompt_specials.
1838 1866
1839 1867 2004-06-06 Fernando Perez <fperez@colorado.edu>
1840 1868
1841 1869 * IPython/Prompts.py (prompt_specials): Added the ability to have
1842 1870 bash-like special sequences in the prompts, which get
1843 1871 automatically expanded. Things like hostname, current working
1844 1872 directory and username are implemented already, but it's easy to
1845 1873 add more in the future. Thanks to a patch by W.J. van der Laan
1846 1874 <gnufnork-AT-hetdigitalegat.nl>
1847 1875 (prompt_specials): Added color support for prompt strings, so
1848 1876 users can define arbitrary color setups for their prompts.
1849 1877
1850 1878 2004-06-05 Fernando Perez <fperez@colorado.edu>
1851 1879
1852 1880 * IPython/genutils.py (Term.reopen_all): Added Windows-specific
1853 1881 code to load Gary Bishop's readline and configure it
1854 1882 automatically. Thanks to Gary for help on this.
1855 1883
1856 1884 2004-06-01 Fernando Perez <fperez@colorado.edu>
1857 1885
1858 1886 * IPython/Logger.py (Logger.create_log): fix bug for logging
1859 1887 with no filename (previous fix was incomplete).
1860 1888
1861 1889 2004-05-25 Fernando Perez <fperez@colorado.edu>
1862 1890
1863 1891 * IPython/Magic.py (Magic.parse_options): fix bug where naked
1864 1892 parens would get passed to the shell.
1865 1893
1866 1894 2004-05-20 Fernando Perez <fperez@colorado.edu>
1867 1895
1868 1896 * IPython/Magic.py (Magic.magic_prun): changed default profile
1869 1897 sort order to 'time' (the more common profiling need).
1870 1898
1871 1899 * IPython/OInspect.py (Inspector.pinfo): flush the inspect cache
1872 1900 so that source code shown is guaranteed in sync with the file on
1873 1901 disk (also changed in psource). Similar fix to the one for
1874 1902 ultraTB on 2004-05-06. Thanks to a bug report by Yann Le Du
1875 1903 <yann.ledu-AT-noos.fr>.
1876 1904
1877 1905 * IPython/Magic.py (Magic.parse_options): Fixed bug where commands
1878 1906 with a single option would not be correctly parsed. Closes
1879 1907 http://www.scipy.net/roundup/ipython/issue14. This bug had been
1880 1908 introduced in 0.6.0 (on 2004-05-06).
1881 1909
1882 1910 2004-05-13 *** Released version 0.6.0
1883 1911
1884 1912 2004-05-13 Fernando Perez <fperez@colorado.edu>
1885 1913
1886 1914 * debian/: Added debian/ directory to CVS, so that debian support
1887 1915 is publicly accessible. The debian package is maintained by Jack
1888 1916 Moffit <jack-AT-xiph.org>.
1889 1917
1890 1918 * Documentation: included the notes about an ipython-based system
1891 1919 shell (the hypothetical 'pysh') into the new_design.pdf document,
1892 1920 so that these ideas get distributed to users along with the
1893 1921 official documentation.
1894 1922
1895 1923 2004-05-10 Fernando Perez <fperez@colorado.edu>
1896 1924
1897 1925 * IPython/Logger.py (Logger.create_log): fix recently introduced
1898 1926 bug (misindented line) where logstart would fail when not given an
1899 1927 explicit filename.
1900 1928
1901 1929 2004-05-09 Fernando Perez <fperez@colorado.edu>
1902 1930
1903 1931 * IPython/Magic.py (Magic.parse_options): skip system call when
1904 1932 there are no options to look for. Faster, cleaner for the common
1905 1933 case.
1906 1934
1907 1935 * Documentation: many updates to the manual: describing Windows
1908 1936 support better, Gnuplot updates, credits, misc small stuff. Also
1909 1937 updated the new_design doc a bit.
1910 1938
1911 1939 2004-05-06 *** Released version 0.6.0.rc1
1912 1940
1913 1941 2004-05-06 Fernando Perez <fperez@colorado.edu>
1914 1942
1915 1943 * IPython/ultraTB.py (ListTB.text): modified a ton of string +=
1916 1944 operations to use the vastly more efficient list/''.join() method.
1917 1945 (FormattedTB.text): Fix
1918 1946 http://www.scipy.net/roundup/ipython/issue12 - exception source
1919 1947 extract not updated after reload. Thanks to Mike Salib
1920 1948 <msalib-AT-mit.edu> for pinning the source of the problem.
1921 1949 Fortunately, the solution works inside ipython and doesn't require
1922 1950 any changes to python proper.
1923 1951
1924 1952 * IPython/Magic.py (Magic.parse_options): Improved to process the
1925 1953 argument list as a true shell would (by actually using the
1926 1954 underlying system shell). This way, all @magics automatically get
1927 1955 shell expansion for variables. Thanks to a comment by Alex
1928 1956 Schmolck.
1929 1957
1930 1958 2004-04-04 Fernando Perez <fperez@colorado.edu>
1931 1959
1932 1960 * IPython/iplib.py (InteractiveShell.interact): Added a special
1933 1961 trap for a debugger quit exception, which is basically impossible
1934 1962 to handle by normal mechanisms, given what pdb does to the stack.
1935 1963 This fixes a crash reported by <fgibbons-AT-llama.med.harvard.edu>.
1936 1964
1937 1965 2004-04-03 Fernando Perez <fperez@colorado.edu>
1938 1966
1939 1967 * IPython/genutils.py (Term): Standardized the names of the Term
1940 1968 class streams to cin/cout/cerr, following C++ naming conventions
1941 1969 (I can't use in/out/err because 'in' is not a valid attribute
1942 1970 name).
1943 1971
1944 1972 * IPython/iplib.py (InteractiveShell.interact): don't increment
1945 1973 the prompt if there's no user input. By Daniel 'Dang' Griffith
1946 1974 <pythondev-dang-AT-lazytwinacres.net>, after a suggestion from
1947 1975 Francois Pinard.
1948 1976
1949 1977 2004-04-02 Fernando Perez <fperez@colorado.edu>
1950 1978
1951 1979 * IPython/genutils.py (Stream.__init__): Modified to survive at
1952 1980 least importing in contexts where stdin/out/err aren't true file
1953 1981 objects, such as PyCrust (they lack fileno() and mode). However,
1954 1982 the recovery facilities which rely on these things existing will
1955 1983 not work.
1956 1984
1957 1985 2004-04-01 Fernando Perez <fperez@colorado.edu>
1958 1986
1959 1987 * IPython/Magic.py (Magic.magic_sx): modified (as well as @sc) to
1960 1988 use the new getoutputerror() function, so it properly
1961 1989 distinguishes stdout/err.
1962 1990
1963 1991 * IPython/genutils.py (getoutputerror): added a function to
1964 1992 capture separately the standard output and error of a command.
1965 1993 After a comment from dang on the mailing lists. This code is
1966 1994 basically a modified version of commands.getstatusoutput(), from
1967 1995 the standard library.
1968 1996
1969 1997 * IPython/iplib.py (InteractiveShell.handle_shell_escape): added
1970 1998 '!!' as a special syntax (shorthand) to access @sx.
1971 1999
1972 2000 * IPython/Magic.py (Magic.magic_sx): new magic, to execute a shell
1973 2001 command and return its output as a list split on '\n'.
1974 2002
1975 2003 2004-03-31 Fernando Perez <fperez@colorado.edu>
1976 2004
1977 2005 * IPython/FakeModule.py (FakeModule.__init__): added __nonzero__
1978 2006 method to dictionaries used as FakeModule instances if they lack
1979 2007 it. At least pydoc in python2.3 breaks for runtime-defined
1980 2008 functions without this hack. At some point I need to _really_
1981 2009 understand what FakeModule is doing, because it's a gross hack.
1982 2010 But it solves Arnd's problem for now...
1983 2011
1984 2012 2004-02-27 Fernando Perez <fperez@colorado.edu>
1985 2013
1986 2014 * IPython/Logger.py (Logger.create_log): Fix bug where 'rotate'
1987 2015 mode would behave erratically. Also increased the number of
1988 2016 possible logs in rotate mod to 999. Thanks to Rod Holland
1989 2017 <rhh@StructureLABS.com> for the report and fixes.
1990 2018
1991 2019 2004-02-26 Fernando Perez <fperez@colorado.edu>
1992 2020
1993 2021 * IPython/genutils.py (page): Check that the curses module really
1994 2022 has the initscr attribute before trying to use it. For some
1995 2023 reason, the Solaris curses module is missing this. I think this
1996 2024 should be considered a Solaris python bug, but I'm not sure.
1997 2025
1998 2026 2004-01-17 Fernando Perez <fperez@colorado.edu>
1999 2027
2000 2028 * IPython/genutils.py (Stream.__init__): Changes to try to make
2001 2029 ipython robust against stdin/out/err being closed by the user.
2002 2030 This is 'user error' (and blocks a normal python session, at least
2003 2031 the stdout case). However, Ipython should be able to survive such
2004 2032 instances of abuse as gracefully as possible. To simplify the
2005 2033 coding and maintain compatibility with Gary Bishop's Term
2006 2034 contributions, I've made use of classmethods for this. I think
2007 2035 this introduces a dependency on python 2.2.
2008 2036
2009 2037 2004-01-13 Fernando Perez <fperez@colorado.edu>
2010 2038
2011 2039 * IPython/numutils.py (exp_safe): simplified the code a bit and
2012 2040 removed the need for importing the kinds module altogether.
2013 2041
2014 2042 2004-01-06 Fernando Perez <fperez@colorado.edu>
2015 2043
2016 2044 * IPython/Magic.py (Magic.magic_sc): Made the shell capture system
2017 2045 a magic function instead, after some community feedback. No
2018 2046 special syntax will exist for it, but its name is deliberately
2019 2047 very short.
2020 2048
2021 2049 2003-12-20 Fernando Perez <fperez@colorado.edu>
2022 2050
2023 2051 * IPython/iplib.py (InteractiveShell.handle_shell_assign): Added
2024 2052 new functionality, to automagically assign the result of a shell
2025 2053 command to a variable. I'll solicit some community feedback on
2026 2054 this before making it permanent.
2027 2055
2028 2056 * IPython/OInspect.py (Inspector.pinfo): Fix crash when info was
2029 2057 requested about callables for which inspect couldn't obtain a
2030 2058 proper argspec. Thanks to a crash report sent by Etienne
2031 2059 Posthumus <etienne-AT-apple01.cs.vu.nl>.
2032 2060
2033 2061 2003-12-09 Fernando Perez <fperez@colorado.edu>
2034 2062
2035 2063 * IPython/genutils.py (page): patch for the pager to work across
2036 2064 various versions of Windows. By Gary Bishop.
2037 2065
2038 2066 2003-12-04 Fernando Perez <fperez@colorado.edu>
2039 2067
2040 2068 * IPython/Gnuplot2.py (PlotItems): Fixes for working with
2041 2069 Gnuplot.py version 1.7, whose internal names changed quite a bit.
2042 2070 While I tested this and it looks ok, there may still be corner
2043 2071 cases I've missed.
2044 2072
2045 2073 2003-12-01 Fernando Perez <fperez@colorado.edu>
2046 2074
2047 2075 * IPython/iplib.py (InteractiveShell._prefilter): Fixed a bug
2048 2076 where a line like 'p,q=1,2' would fail because the automagic
2049 2077 system would be triggered for @p.
2050 2078
2051 2079 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): Tab-related
2052 2080 cleanups, code unmodified.
2053 2081
2054 2082 * IPython/genutils.py (Term): added a class for IPython to handle
2055 2083 output. In most cases it will just be a proxy for stdout/err, but
2056 2084 having this allows modifications to be made for some platforms,
2057 2085 such as handling color escapes under Windows. All of this code
2058 2086 was contributed by Gary Bishop, with minor modifications by me.
2059 2087 The actual changes affect many files.
2060 2088
2061 2089 2003-11-30 Fernando Perez <fperez@colorado.edu>
2062 2090
2063 2091 * IPython/iplib.py (file_matches): new completion code, courtesy
2064 2092 of Jeff Collins. This enables filename completion again under
2065 2093 python 2.3, which disabled it at the C level.
2066 2094
2067 2095 2003-11-11 Fernando Perez <fperez@colorado.edu>
2068 2096
2069 2097 * IPython/numutils.py (amap): Added amap() fn. Simple shorthand
2070 2098 for Numeric.array(map(...)), but often convenient.
2071 2099
2072 2100 2003-11-05 Fernando Perez <fperez@colorado.edu>
2073 2101
2074 2102 * IPython/numutils.py (frange): Changed a call from int() to
2075 2103 int(round()) to prevent a problem reported with arange() in the
2076 2104 numpy list.
2077 2105
2078 2106 2003-10-06 Fernando Perez <fperez@colorado.edu>
2079 2107
2080 2108 * IPython/DPyGetOpt.py (DPyGetOpt.processArguments): changed to
2081 2109 prevent crashes if sys lacks an argv attribute (it happens with
2082 2110 embedded interpreters which build a bare-bones sys module).
2083 2111 Thanks to a report/bugfix by Adam Hupp <hupp-AT-cs.wisc.edu>.
2084 2112
2085 2113 2003-09-24 Fernando Perez <fperez@colorado.edu>
2086 2114
2087 2115 * IPython/Magic.py (Magic._ofind): blanket except around getattr()
2088 2116 to protect against poorly written user objects where __getattr__
2089 2117 raises exceptions other than AttributeError. Thanks to a bug
2090 2118 report by Oliver Sander <osander-AT-gmx.de>.
2091 2119
2092 2120 * IPython/FakeModule.py (FakeModule.__repr__): this method was
2093 2121 missing. Thanks to bug report by Ralf Schmitt <ralf-AT-brainbot.com>.
2094 2122
2095 2123 2003-09-09 Fernando Perez <fperez@colorado.edu>
2096 2124
2097 2125 * IPython/iplib.py (InteractiveShell._prefilter): fix bug where
2098 2126 unpacking a list whith a callable as first element would
2099 2127 mistakenly trigger autocalling. Thanks to a bug report by Jeffery
2100 2128 Collins.
2101 2129
2102 2130 2003-08-25 *** Released version 0.5.0
2103 2131
2104 2132 2003-08-22 Fernando Perez <fperez@colorado.edu>
2105 2133
2106 2134 * IPython/ultraTB.py (VerboseTB.linereader): Improved handling of
2107 2135 improperly defined user exceptions. Thanks to feedback from Mark
2108 2136 Russell <mrussell-AT-verio.net>.
2109 2137
2110 2138 2003-08-20 Fernando Perez <fperez@colorado.edu>
2111 2139
2112 2140 * IPython/OInspect.py (Inspector.pinfo): changed String Form
2113 2141 printing so that it would print multi-line string forms starting
2114 2142 with a new line. This way the formatting is better respected for
2115 2143 objects which work hard to make nice string forms.
2116 2144
2117 2145 * IPython/iplib.py (InteractiveShell.handle_auto): Fix bug where
2118 2146 autocall would overtake data access for objects with both
2119 2147 __getitem__ and __call__.
2120 2148
2121 2149 2003-08-19 *** Released version 0.5.0-rc1
2122 2150
2123 2151 2003-08-19 Fernando Perez <fperez@colorado.edu>
2124 2152
2125 2153 * IPython/deep_reload.py (load_tail): single tiny change here
2126 2154 seems to fix the long-standing bug of dreload() failing to work
2127 2155 for dotted names. But this module is pretty tricky, so I may have
2128 2156 missed some subtlety. Needs more testing!.
2129 2157
2130 2158 * IPython/ultraTB.py (VerboseTB.linereader): harden against user
2131 2159 exceptions which have badly implemented __str__ methods.
2132 2160 (VerboseTB.text): harden against inspect.getinnerframes crashing,
2133 2161 which I've been getting reports about from Python 2.3 users. I
2134 2162 wish I had a simple test case to reproduce the problem, so I could
2135 2163 either write a cleaner workaround or file a bug report if
2136 2164 necessary.
2137 2165
2138 2166 * IPython/Magic.py (Magic.magic_edit): fixed bug where after
2139 2167 making a class 'foo', file 'foo.py' couldn't be edited. Thanks to
2140 2168 a bug report by Tjabo Kloppenburg.
2141 2169
2142 2170 * IPython/ultraTB.py (VerboseTB.debugger): hardened against pdb
2143 2171 crashes. Wrapped the pdb call in a blanket try/except, since pdb
2144 2172 seems rather unstable. Thanks to a bug report by Tjabo
2145 2173 Kloppenburg <tjabo.kloppenburg-AT-unix-ag.uni-siegen.de>.
2146 2174
2147 2175 * IPython/Release.py (version): release 0.5.0-rc1. I want to put
2148 2176 this out soon because of the critical fixes in the inner loop for
2149 2177 generators.
2150 2178
2151 2179 * IPython/Magic.py (Magic.getargspec): removed. This (and
2152 2180 _get_def) have been obsoleted by OInspect for a long time, I
2153 2181 hadn't noticed that they were dead code.
2154 2182 (Magic._ofind): restored _ofind functionality for a few literals
2155 2183 (those in ["''",'""','[]','{}','()']). But it won't work anymore
2156 2184 for things like "hello".capitalize?, since that would require a
2157 2185 potentially dangerous eval() again.
2158 2186
2159 2187 * IPython/iplib.py (InteractiveShell._prefilter): reorganized the
2160 2188 logic a bit more to clean up the escapes handling and minimize the
2161 2189 use of _ofind to only necessary cases. The interactive 'feel' of
2162 2190 IPython should have improved quite a bit with the changes in
2163 2191 _prefilter and _ofind (besides being far safer than before).
2164 2192
2165 2193 * IPython/Magic.py (Magic.magic_edit): Fixed old bug (but rather
2166 2194 obscure, never reported). Edit would fail to find the object to
2167 2195 edit under some circumstances.
2168 2196 (Magic._ofind): CRITICAL FIX. Finally removed the eval() calls
2169 2197 which were causing double-calling of generators. Those eval calls
2170 2198 were _very_ dangerous, since code with side effects could be
2171 2199 triggered. As they say, 'eval is evil'... These were the
2172 2200 nastiest evals in IPython. Besides, _ofind is now far simpler,
2173 2201 and it should also be quite a bit faster. Its use of inspect is
2174 2202 also safer, so perhaps some of the inspect-related crashes I've
2175 2203 seen lately with Python 2.3 might be taken care of. That will
2176 2204 need more testing.
2177 2205
2178 2206 2003-08-17 Fernando Perez <fperez@colorado.edu>
2179 2207
2180 2208 * IPython/iplib.py (InteractiveShell._prefilter): significant
2181 2209 simplifications to the logic for handling user escapes. Faster
2182 2210 and simpler code.
2183 2211
2184 2212 2003-08-14 Fernando Perez <fperez@colorado.edu>
2185 2213
2186 2214 * IPython/numutils.py (sum_flat): rewrote to be non-recursive.
2187 2215 Now it requires O(N) storage (N=size(a)) for non-contiguous input,
2188 2216 but it should be quite a bit faster. And the recursive version
2189 2217 generated O(log N) intermediate storage for all rank>1 arrays,
2190 2218 even if they were contiguous.
2191 2219 (l1norm): Added this function.
2192 2220 (norm): Added this function for arbitrary norms (including
2193 2221 l-infinity). l1 and l2 are still special cases for convenience
2194 2222 and speed.
2195 2223
2196 2224 2003-08-03 Fernando Perez <fperez@colorado.edu>
2197 2225
2198 2226 * IPython/Magic.py (Magic.magic_edit): Removed all remaining string
2199 2227 exceptions, which now raise PendingDeprecationWarnings in Python
2200 2228 2.3. There were some in Magic and some in Gnuplot2.
2201 2229
2202 2230 2003-06-30 Fernando Perez <fperez@colorado.edu>
2203 2231
2204 2232 * IPython/genutils.py (page): modified to call curses only for
2205 2233 terminals where TERM=='xterm'. After problems under many other
2206 2234 terminals were reported by Keith Beattie <KSBeattie-AT-lbl.gov>.
2207 2235
2208 2236 * IPython/iplib.py (complete): removed spurious 'print "IE"' which
2209 2237 would be triggered when readline was absent. This was just an old
2210 2238 debugging statement I'd forgotten to take out.
2211 2239
2212 2240 2003-06-20 Fernando Perez <fperez@colorado.edu>
2213 2241
2214 2242 * IPython/genutils.py (clock): modified to return only user time
2215 2243 (not counting system time), after a discussion on scipy. While
2216 2244 system time may be a useful quantity occasionally, it may much
2217 2245 more easily be skewed by occasional swapping or other similar
2218 2246 activity.
2219 2247
2220 2248 2003-06-05 Fernando Perez <fperez@colorado.edu>
2221 2249
2222 2250 * IPython/numutils.py (identity): new function, for building
2223 2251 arbitrary rank Kronecker deltas (mostly backwards compatible with
2224 2252 Numeric.identity)
2225 2253
2226 2254 2003-06-03 Fernando Perez <fperez@colorado.edu>
2227 2255
2228 2256 * IPython/iplib.py (InteractiveShell.handle_magic): protect
2229 2257 arguments passed to magics with spaces, to allow trailing '\' to
2230 2258 work normally (mainly for Windows users).
2231 2259
2232 2260 2003-05-29 Fernando Perez <fperez@colorado.edu>
2233 2261
2234 2262 * IPython/ipmaker.py (make_IPython): Load site._Helper() as help
2235 2263 instead of pydoc.help. This fixes a bizarre behavior where
2236 2264 printing '%s' % locals() would trigger the help system. Now
2237 2265 ipython behaves like normal python does.
2238 2266
2239 2267 Note that if one does 'from pydoc import help', the bizarre
2240 2268 behavior returns, but this will also happen in normal python, so
2241 2269 it's not an ipython bug anymore (it has to do with how pydoc.help
2242 2270 is implemented).
2243 2271
2244 2272 2003-05-22 Fernando Perez <fperez@colorado.edu>
2245 2273
2246 2274 * IPython/FlexCompleter.py (Completer.attr_matches): fixed to
2247 2275 return [] instead of None when nothing matches, also match to end
2248 2276 of line. Patch by Gary Bishop.
2249 2277
2250 2278 * IPython/ipmaker.py (make_IPython): Added same sys.excepthook
2251 2279 protection as before, for files passed on the command line. This
2252 2280 prevents the CrashHandler from kicking in if user files call into
2253 2281 sys.excepthook (such as PyQt and WxWindows have a nasty habit of
2254 2282 doing). After a report by Kasper Souren <Kasper.Souren-AT-ircam.fr>
2255 2283
2256 2284 2003-05-20 *** Released version 0.4.0
2257 2285
2258 2286 2003-05-20 Fernando Perez <fperez@colorado.edu>
2259 2287
2260 2288 * setup.py: added support for manpages. It's a bit hackish b/c of
2261 2289 a bug in the way the bdist_rpm distutils target handles gzipped
2262 2290 manpages, but it works. After a patch by Jack.
2263 2291
2264 2292 2003-05-19 Fernando Perez <fperez@colorado.edu>
2265 2293
2266 2294 * IPython/numutils.py: added a mockup of the kinds module, since
2267 2295 it was recently removed from Numeric. This way, numutils will
2268 2296 work for all users even if they are missing kinds.
2269 2297
2270 2298 * IPython/Magic.py (Magic._ofind): Harden against an inspect
2271 2299 failure, which can occur with SWIG-wrapped extensions. After a
2272 2300 crash report from Prabhu.
2273 2301
2274 2302 2003-05-16 Fernando Perez <fperez@colorado.edu>
2275 2303
2276 2304 * IPython/iplib.py (InteractiveShell.excepthook): New method to
2277 2305 protect ipython from user code which may call directly
2278 2306 sys.excepthook (this looks like an ipython crash to the user, even
2279 2307 when it isn't). After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2280 2308 This is especially important to help users of WxWindows, but may
2281 2309 also be useful in other cases.
2282 2310
2283 2311 * IPython/ultraTB.py (AutoFormattedTB.__call__): Changed to allow
2284 2312 an optional tb_offset to be specified, and to preserve exception
2285 2313 info if given. After a patch by Gary Bishop <gb-AT-cs.unc.edu>.
2286 2314
2287 2315 * ipython.1 (Default): Thanks to Jack's work, we now have manpages!
2288 2316
2289 2317 2003-05-15 Fernando Perez <fperez@colorado.edu>
2290 2318
2291 2319 * IPython/iplib.py (InteractiveShell.user_setup): Fix crash when
2292 2320 installing for a new user under Windows.
2293 2321
2294 2322 2003-05-12 Fernando Perez <fperez@colorado.edu>
2295 2323
2296 2324 * IPython/iplib.py (InteractiveShell.handle_emacs): New line
2297 2325 handler for Emacs comint-based lines. Currently it doesn't do
2298 2326 much (but importantly, it doesn't update the history cache). In
2299 2327 the future it may be expanded if Alex needs more functionality
2300 2328 there.
2301 2329
2302 2330 * IPython/CrashHandler.py (CrashHandler.__call__): Added platform
2303 2331 info to crash reports.
2304 2332
2305 2333 * IPython/iplib.py (InteractiveShell.mainloop): Added -c option,
2306 2334 just like Python's -c. Also fixed crash with invalid -color
2307 2335 option value at startup. Thanks to Will French
2308 2336 <wfrench-AT-bestweb.net> for the bug report.
2309 2337
2310 2338 2003-05-09 Fernando Perez <fperez@colorado.edu>
2311 2339
2312 2340 * IPython/genutils.py (EvalDict.__getitem__): Renamed EvalString
2313 2341 to EvalDict (it's a mapping, after all) and simplified its code
2314 2342 quite a bit, after a nice discussion on c.l.py where Gustavo
2315 2343 Córdova <gcordova-AT-sismex.com> suggested the new version.
2316 2344
2317 2345 2003-04-30 Fernando Perez <fperez@colorado.edu>
2318 2346
2319 2347 * IPython/genutils.py (timings_out): modified it to reduce its
2320 2348 overhead in the common reps==1 case.
2321 2349
2322 2350 2003-04-29 Fernando Perez <fperez@colorado.edu>
2323 2351
2324 2352 * IPython/genutils.py (timings_out): Modified to use the resource
2325 2353 module, which avoids the wraparound problems of time.clock().
2326 2354
2327 2355 2003-04-17 *** Released version 0.2.15pre4
2328 2356
2329 2357 2003-04-17 Fernando Perez <fperez@colorado.edu>
2330 2358
2331 2359 * setup.py (scriptfiles): Split windows-specific stuff over to a
2332 2360 separate file, in an attempt to have a Windows GUI installer.
2333 2361 That didn't work, but part of the groundwork is done.
2334 2362
2335 2363 * IPython/UserConfig/ipythonrc: Added M-i, M-o and M-I for
2336 2364 indent/unindent with 4 spaces. Particularly useful in combination
2337 2365 with the new auto-indent option.
2338 2366
2339 2367 2003-04-16 Fernando Perez <fperez@colorado.edu>
2340 2368
2341 2369 * IPython/Magic.py: various replacements of self.rc for
2342 2370 self.shell.rc. A lot more remains to be done to fully disentangle
2343 2371 this class from the main Shell class.
2344 2372
2345 2373 * IPython/GnuplotRuntime.py: added checks for mouse support so
2346 2374 that we don't try to enable it if the current gnuplot doesn't
2347 2375 really support it. Also added checks so that we don't try to
2348 2376 enable persist under Windows (where Gnuplot doesn't recognize the
2349 2377 option).
2350 2378
2351 2379 * IPython/iplib.py (InteractiveShell.interact): Added optional
2352 2380 auto-indenting code, after a patch by King C. Shu
2353 2381 <kingshu-AT-myrealbox.com>. It's off by default because it doesn't
2354 2382 get along well with pasting indented code. If I ever figure out
2355 2383 how to make that part go well, it will become on by default.
2356 2384
2357 2385 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixed bug which would
2358 2386 crash ipython if there was an unmatched '%' in the user's prompt
2359 2387 string. Reported by Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2360 2388
2361 2389 * IPython/iplib.py (InteractiveShell.interact): removed the
2362 2390 ability to ask the user whether he wants to crash or not at the
2363 2391 'last line' exception handler. Calling functions at that point
2364 2392 changes the stack, and the error reports would have incorrect
2365 2393 tracebacks.
2366 2394
2367 2395 * IPython/Magic.py (Magic.magic_page): Added new @page magic, to
2368 2396 pass through a peger a pretty-printed form of any object. After a
2369 2397 contribution by Olivier Aubert <oaubert-AT-bat710.univ-lyon1.fr>
2370 2398
2371 2399 2003-04-14 Fernando Perez <fperez@colorado.edu>
2372 2400
2373 2401 * IPython/iplib.py (InteractiveShell.user_setup): Fixed bug where
2374 2402 all files in ~ would be modified at first install (instead of
2375 2403 ~/.ipython). This could be potentially disastrous, as the
2376 2404 modification (make line-endings native) could damage binary files.
2377 2405
2378 2406 2003-04-10 Fernando Perez <fperez@colorado.edu>
2379 2407
2380 2408 * IPython/iplib.py (InteractiveShell.handle_help): Modified to
2381 2409 handle only lines which are invalid python. This now means that
2382 2410 lines like 'x=1 #?' execute properly. Thanks to Jeffery Collins
2383 2411 for the bug report.
2384 2412
2385 2413 2003-04-01 Fernando Perez <fperez@colorado.edu>
2386 2414
2387 2415 * IPython/iplib.py (InteractiveShell.showtraceback): Fixed bug
2388 2416 where failing to set sys.last_traceback would crash pdb.pm().
2389 2417 Thanks to Jeffery D. Collins <Jeff.Collins-AT-vexcel.com> for the bug
2390 2418 report.
2391 2419
2392 2420 2003-03-25 Fernando Perez <fperez@colorado.edu>
2393 2421
2394 2422 * IPython/Magic.py (Magic.magic_prun): rstrip() output of profiler
2395 2423 before printing it (it had a lot of spurious blank lines at the
2396 2424 end).
2397 2425
2398 2426 * IPython/Gnuplot2.py (Gnuplot.hardcopy): fixed bug where lpr
2399 2427 output would be sent 21 times! Obviously people don't use this
2400 2428 too often, or I would have heard about it.
2401 2429
2402 2430 2003-03-24 Fernando Perez <fperez@colorado.edu>
2403 2431
2404 2432 * setup.py (scriptfiles): renamed the data_files parameter from
2405 2433 'base' to 'data' to fix rpm build issues. Thanks to Ralf Ahlbrink
2406 2434 for the patch.
2407 2435
2408 2436 2003-03-20 Fernando Perez <fperez@colorado.edu>
2409 2437
2410 2438 * IPython/genutils.py (error): added error() and fatal()
2411 2439 functions.
2412 2440
2413 2441 2003-03-18 *** Released version 0.2.15pre3
2414 2442
2415 2443 2003-03-18 Fernando Perez <fperez@colorado.edu>
2416 2444
2417 2445 * setupext/install_data_ext.py
2418 2446 (install_data_ext.initialize_options): Class contributed by Jack
2419 2447 Moffit for fixing the old distutils hack. He is sending this to
2420 2448 the distutils folks so in the future we may not need it as a
2421 2449 private fix.
2422 2450
2423 2451 * MANIFEST.in: Extensive reorganization, based on Jack Moffit's
2424 2452 changes for Debian packaging. See his patch for full details.
2425 2453 The old distutils hack of making the ipythonrc* files carry a
2426 2454 bogus .py extension is gone, at last. Examples were moved to a
2427 2455 separate subdir under doc/, and the separate executable scripts
2428 2456 now live in their own directory. Overall a great cleanup. The
2429 2457 manual was updated to use the new files, and setup.py has been
2430 2458 fixed for this setup.
2431 2459
2432 2460 * IPython/PyColorize.py (Parser.usage): made non-executable and
2433 2461 created a pycolor wrapper around it to be included as a script.
2434 2462
2435 2463 2003-03-12 *** Released version 0.2.15pre2
2436 2464
2437 2465 2003-03-12 Fernando Perez <fperez@colorado.edu>
2438 2466
2439 2467 * IPython/ColorANSI.py (make_color_table): Finally fixed the
2440 2468 long-standing problem with garbage characters in some terminals.
2441 2469 The issue was really that the \001 and \002 escapes must _only_ be
2442 2470 passed to input prompts (which call readline), but _never_ to
2443 2471 normal text to be printed on screen. I changed ColorANSI to have
2444 2472 two classes: TermColors and InputTermColors, each with the
2445 2473 appropriate escapes for input prompts or normal text. The code in
2446 2474 Prompts.py got slightly more complicated, but this very old and
2447 2475 annoying bug is finally fixed.
2448 2476
2449 2477 All the credit for nailing down the real origin of this problem
2450 2478 and the correct solution goes to Jack Moffit <jack-AT-xiph.org>.
2451 2479 *Many* thanks to him for spending quite a bit of effort on this.
2452 2480
2453 2481 2003-03-05 *** Released version 0.2.15pre1
2454 2482
2455 2483 2003-03-03 Fernando Perez <fperez@colorado.edu>
2456 2484
2457 2485 * IPython/FakeModule.py: Moved the former _FakeModule to a
2458 2486 separate file, because it's also needed by Magic (to fix a similar
2459 2487 pickle-related issue in @run).
2460 2488
2461 2489 2003-03-02 Fernando Perez <fperez@colorado.edu>
2462 2490
2463 2491 * IPython/Magic.py (Magic.magic_autocall): new magic to control
2464 2492 the autocall option at runtime.
2465 2493 (Magic.magic_dhist): changed self.user_ns to self.shell.user_ns
2466 2494 across Magic.py to start separating Magic from InteractiveShell.
2467 2495 (Magic._ofind): Fixed to return proper namespace for dotted
2468 2496 names. Before, a dotted name would always return 'not currently
2469 2497 defined', because it would find the 'parent'. s.x would be found,
2470 2498 but since 'x' isn't defined by itself, it would get confused.
2471 2499 (Magic.magic_run): Fixed pickling problems reported by Ralf
2472 2500 Ahlbrink <RAhlbrink-AT-RosenInspection.net>. The fix was similar to
2473 2501 that I'd used when Mike Heeter reported similar issues at the
2474 2502 top-level, but now for @run. It boils down to injecting the
2475 2503 namespace where code is being executed with something that looks
2476 2504 enough like a module to fool pickle.dump(). Since a pickle stores
2477 2505 a named reference to the importing module, we need this for
2478 2506 pickles to save something sensible.
2479 2507
2480 2508 * IPython/ipmaker.py (make_IPython): added an autocall option.
2481 2509
2482 2510 * IPython/iplib.py (InteractiveShell._prefilter): reordered all of
2483 2511 the auto-eval code. Now autocalling is an option, and the code is
2484 2512 also vastly safer. There is no more eval() involved at all.
2485 2513
2486 2514 2003-03-01 Fernando Perez <fperez@colorado.edu>
2487 2515
2488 2516 * IPython/Magic.py (Magic._ofind): Changed interface to return a
2489 2517 dict with named keys instead of a tuple.
2490 2518
2491 2519 * IPython: Started using CVS for IPython as of 0.2.15pre1.
2492 2520
2493 2521 * setup.py (make_shortcut): Fixed message about directories
2494 2522 created during Windows installation (the directories were ok, just
2495 2523 the printed message was misleading). Thanks to Chris Liechti
2496 2524 <cliechti-AT-gmx.net> for the heads up.
2497 2525
2498 2526 2003-02-21 Fernando Perez <fperez@colorado.edu>
2499 2527
2500 2528 * IPython/iplib.py (InteractiveShell._prefilter): Fixed catching
2501 2529 of ValueError exception when checking for auto-execution. This
2502 2530 one is raised by things like Numeric arrays arr.flat when the
2503 2531 array is non-contiguous.
2504 2532
2505 2533 2003-01-31 Fernando Perez <fperez@colorado.edu>
2506 2534
2507 2535 * IPython/genutils.py (SystemExec.bq): Fixed bug where bq would
2508 2536 not return any value at all (even though the command would get
2509 2537 executed).
2510 2538 (xsys): Flush stdout right after printing the command to ensure
2511 2539 proper ordering of commands and command output in the total
2512 2540 output.
2513 2541 (SystemExec/xsys/bq): Switched the names of xsys/bq and
2514 2542 system/getoutput as defaults. The old ones are kept for
2515 2543 compatibility reasons, so no code which uses this library needs
2516 2544 changing.
2517 2545
2518 2546 2003-01-27 *** Released version 0.2.14
2519 2547
2520 2548 2003-01-25 Fernando Perez <fperez@colorado.edu>
2521 2549
2522 2550 * IPython/Magic.py (Magic.magic_edit): Fixed problem where
2523 2551 functions defined in previous edit sessions could not be re-edited
2524 2552 (because the temp files were immediately removed). Now temp files
2525 2553 are removed only at IPython's exit.
2526 2554 (Magic.magic_run): Improved @run to perform shell-like expansions
2527 2555 on its arguments (~users and $VARS). With this, @run becomes more
2528 2556 like a normal command-line.
2529 2557
2530 2558 * IPython/Shell.py (IPShellEmbed.__call__): Fixed a bunch of small
2531 2559 bugs related to embedding and cleaned up that code. A fairly
2532 2560 important one was the impossibility to access the global namespace
2533 2561 through the embedded IPython (only local variables were visible).
2534 2562
2535 2563 2003-01-14 Fernando Perez <fperez@colorado.edu>
2536 2564
2537 2565 * IPython/iplib.py (InteractiveShell._prefilter): Fixed
2538 2566 auto-calling to be a bit more conservative. Now it doesn't get
2539 2567 triggered if any of '!=()<>' are in the rest of the input line, to
2540 2568 allow comparing callables. Thanks to Alex for the heads up.
2541 2569
2542 2570 2003-01-07 Fernando Perez <fperez@colorado.edu>
2543 2571
2544 2572 * IPython/genutils.py (page): fixed estimation of the number of
2545 2573 lines in a string to be paged to simply count newlines. This
2546 2574 prevents over-guessing due to embedded escape sequences. A better
2547 2575 long-term solution would involve stripping out the control chars
2548 2576 for the count, but it's potentially so expensive I just don't
2549 2577 think it's worth doing.
2550 2578
2551 2579 2002-12-19 *** Released version 0.2.14pre50
2552 2580
2553 2581 2002-12-19 Fernando Perez <fperez@colorado.edu>
2554 2582
2555 2583 * tools/release (version): Changed release scripts to inform
2556 2584 Andrea and build a NEWS file with a list of recent changes.
2557 2585
2558 2586 * IPython/ColorANSI.py (__all__): changed terminal detection
2559 2587 code. Seems to work better for xterms without breaking
2560 2588 konsole. Will need more testing to determine if WinXP and Mac OSX
2561 2589 also work ok.
2562 2590
2563 2591 2002-12-18 *** Released version 0.2.14pre49
2564 2592
2565 2593 2002-12-18 Fernando Perez <fperez@colorado.edu>
2566 2594
2567 2595 * Docs: added new info about Mac OSX, from Andrea.
2568 2596
2569 2597 * IPython/Gnuplot2.py (String): Added a String PlotItem class to
2570 2598 allow direct plotting of python strings whose format is the same
2571 2599 of gnuplot data files.
2572 2600
2573 2601 2002-12-16 Fernando Perez <fperez@colorado.edu>
2574 2602
2575 2603 * IPython/iplib.py (InteractiveShell.interact): fixed default (y)
2576 2604 value of exit question to be acknowledged.
2577 2605
2578 2606 2002-12-03 Fernando Perez <fperez@colorado.edu>
2579 2607
2580 2608 * IPython/ipmaker.py: removed generators, which had been added
2581 2609 by mistake in an earlier debugging run. This was causing trouble
2582 2610 to users of python 2.1.x. Thanks to Abel Daniel <abli-AT-freemail.hu>
2583 2611 for pointing this out.
2584 2612
2585 2613 2002-11-17 Fernando Perez <fperez@colorado.edu>
2586 2614
2587 2615 * Manual: updated the Gnuplot section.
2588 2616
2589 2617 * IPython/GnuplotRuntime.py: refactored a lot all this code, with
2590 2618 a much better split of what goes in Runtime and what goes in
2591 2619 Interactive.
2592 2620
2593 2621 * IPython/ipmaker.py: fixed bug where import_fail_info wasn't
2594 2622 being imported from iplib.
2595 2623
2596 2624 * IPython/GnuplotInteractive.py (magic_gpc): renamed @gp to @gpc
2597 2625 for command-passing. Now the global Gnuplot instance is called
2598 2626 'gp' instead of 'g', which was really a far too fragile and
2599 2627 common name.
2600 2628
2601 2629 * IPython/Gnuplot2.py (eps_fix_bbox): added this to fix broken
2602 2630 bounding boxes generated by Gnuplot for square plots.
2603 2631
2604 2632 * IPython/genutils.py (popkey): new function added. I should
2605 2633 suggest this on c.l.py as a dict method, it seems useful.
2606 2634
2607 2635 * IPython/Gnuplot2.py (Gnuplot.plot): Overhauled plot and replot
2608 2636 to transparently handle PostScript generation. MUCH better than
2609 2637 the previous plot_eps/replot_eps (which I removed now). The code
2610 2638 is also fairly clean and well documented now (including
2611 2639 docstrings).
2612 2640
2613 2641 2002-11-13 Fernando Perez <fperez@colorado.edu>
2614 2642
2615 2643 * IPython/Magic.py (Magic.magic_edit): fixed docstring
2616 2644 (inconsistent with options).
2617 2645
2618 2646 * IPython/Gnuplot2.py (Gnuplot.hardcopy): hardcopy had been
2619 2647 manually disabled, I don't know why. Fixed it.
2620 2648 (Gnuplot._plot_eps): added new plot_eps/replot_eps to get directly
2621 2649 eps output.
2622 2650
2623 2651 2002-11-12 Fernando Perez <fperez@colorado.edu>
2624 2652
2625 2653 * IPython/genutils.py (ask_yes_no): trap EOF and ^C so that they
2626 2654 don't propagate up to caller. Fixes crash reported by François
2627 2655 Pinard.
2628 2656
2629 2657 2002-11-09 Fernando Perez <fperez@colorado.edu>
2630 2658
2631 2659 * IPython/ipmaker.py (make_IPython): fixed problem with writing
2632 2660 history file for new users.
2633 2661 (make_IPython): fixed bug where initial install would leave the
2634 2662 user running in the .ipython dir.
2635 2663 (make_IPython): fixed bug where config dir .ipython would be
2636 2664 created regardless of the given -ipythondir option. Thanks to Cory
2637 2665 Dodt <cdodt-AT-fcoe.k12.ca.us> for the bug report.
2638 2666
2639 2667 * IPython/genutils.py (ask_yes_no): new function for asking yes/no
2640 2668 type confirmations. Will need to use it in all of IPython's code
2641 2669 consistently.
2642 2670
2643 2671 * IPython/CrashHandler.py (CrashHandler.__call__): changed the
2644 2672 context to print 31 lines instead of the default 5. This will make
2645 2673 the crash reports extremely detailed in case the problem is in
2646 2674 libraries I don't have access to.
2647 2675
2648 2676 * IPython/iplib.py (InteractiveShell.interact): changed the 'last
2649 2677 line of defense' code to still crash, but giving users fair
2650 2678 warning. I don't want internal errors to go unreported: if there's
2651 2679 an internal problem, IPython should crash and generate a full
2652 2680 report.
2653 2681
2654 2682 2002-11-08 Fernando Perez <fperez@colorado.edu>
2655 2683
2656 2684 * IPython/iplib.py (InteractiveShell.interact): added code to trap
2657 2685 otherwise uncaught exceptions which can appear if people set
2658 2686 sys.stdout to something badly broken. Thanks to a crash report
2659 2687 from henni-AT-mail.brainbot.com.
2660 2688
2661 2689 2002-11-04 Fernando Perez <fperez@colorado.edu>
2662 2690
2663 2691 * IPython/iplib.py (InteractiveShell.interact): added
2664 2692 __IPYTHON__active to the builtins. It's a flag which goes on when
2665 2693 the interaction starts and goes off again when it stops. This
2666 2694 allows embedding code to detect being inside IPython. Before this
2667 2695 was done via __IPYTHON__, but that only shows that an IPython
2668 2696 instance has been created.
2669 2697
2670 2698 * IPython/Magic.py (Magic.magic_env): I realized that in a
2671 2699 UserDict, instance.data holds the data as a normal dict. So I
2672 2700 modified @env to return os.environ.data instead of rebuilding a
2673 2701 dict by hand.
2674 2702
2675 2703 2002-11-02 Fernando Perez <fperez@colorado.edu>
2676 2704
2677 2705 * IPython/genutils.py (warn): changed so that level 1 prints no
2678 2706 header. Level 2 is now the default (with 'WARNING' header, as
2679 2707 before). I think I tracked all places where changes were needed in
2680 2708 IPython, but outside code using the old level numbering may have
2681 2709 broken.
2682 2710
2683 2711 * IPython/iplib.py (InteractiveShell.runcode): added this to
2684 2712 handle the tracebacks in SystemExit traps correctly. The previous
2685 2713 code (through interact) was printing more of the stack than
2686 2714 necessary, showing IPython internal code to the user.
2687 2715
2688 2716 * IPython/UserConfig/ipythonrc.py: Made confirm_exit 1 by
2689 2717 default. Now that the default at the confirmation prompt is yes,
2690 2718 it's not so intrusive. François' argument that ipython sessions
2691 2719 tend to be complex enough not to lose them from an accidental C-d,
2692 2720 is a valid one.
2693 2721
2694 2722 * IPython/iplib.py (InteractiveShell.interact): added a
2695 2723 showtraceback() call to the SystemExit trap, and modified the exit
2696 2724 confirmation to have yes as the default.
2697 2725
2698 2726 * IPython/UserConfig/ipythonrc.py: removed 'session' option from
2699 2727 this file. It's been gone from the code for a long time, this was
2700 2728 simply leftover junk.
2701 2729
2702 2730 2002-11-01 Fernando Perez <fperez@colorado.edu>
2703 2731
2704 2732 * IPython/UserConfig/ipythonrc.py: new confirm_exit option
2705 2733 added. If set, IPython now traps EOF and asks for
2706 2734 confirmation. After a request by François Pinard.
2707 2735
2708 2736 * IPython/Magic.py (Magic.magic_Exit): New @Exit and @Quit instead
2709 2737 of @abort, and with a new (better) mechanism for handling the
2710 2738 exceptions.
2711 2739
2712 2740 2002-10-27 Fernando Perez <fperez@colorado.edu>
2713 2741
2714 2742 * IPython/usage.py (__doc__): updated the --help information and
2715 2743 the ipythonrc file to indicate that -log generates
2716 2744 ./ipython.log. Also fixed the corresponding info in @logstart.
2717 2745 This and several other fixes in the manuals thanks to reports by
2718 2746 François Pinard <pinard-AT-iro.umontreal.ca>.
2719 2747
2720 2748 * IPython/Logger.py (Logger.switch_log): Fixed error message to
2721 2749 refer to @logstart (instead of @log, which doesn't exist).
2722 2750
2723 2751 * IPython/iplib.py (InteractiveShell._prefilter): fixed
2724 2752 AttributeError crash. Thanks to Christopher Armstrong
2725 2753 <radix-AT-twistedmatrix.com> for the report/fix. This bug had been
2726 2754 introduced recently (in 0.2.14pre37) with the fix to the eval
2727 2755 problem mentioned below.
2728 2756
2729 2757 2002-10-17 Fernando Perez <fperez@colorado.edu>
2730 2758
2731 2759 * IPython/ConfigLoader.py (ConfigLoader.load): Fixes for Windows
2732 2760 installation. Thanks to Leonardo Santagada <retype-AT-terra.com.br>.
2733 2761
2734 2762 * IPython/iplib.py (InteractiveShell._prefilter): Many changes to
2735 2763 this function to fix a problem reported by Alex Schmolck. He saw
2736 2764 it with list comprehensions and generators, which were getting
2737 2765 called twice. The real problem was an 'eval' call in testing for
2738 2766 automagic which was evaluating the input line silently.
2739 2767
2740 2768 This is a potentially very nasty bug, if the input has side
2741 2769 effects which must not be repeated. The code is much cleaner now,
2742 2770 without any blanket 'except' left and with a regexp test for
2743 2771 actual function names.
2744 2772
2745 2773 But an eval remains, which I'm not fully comfortable with. I just
2746 2774 don't know how to find out if an expression could be a callable in
2747 2775 the user's namespace without doing an eval on the string. However
2748 2776 that string is now much more strictly checked so that no code
2749 2777 slips by, so the eval should only happen for things that can
2750 2778 really be only function/method names.
2751 2779
2752 2780 2002-10-15 Fernando Perez <fperez@colorado.edu>
2753 2781
2754 2782 * Updated LyX to 1.2.1 so I can work on the docs again. Added Mac
2755 2783 OSX information to main manual, removed README_Mac_OSX file from
2756 2784 distribution. Also updated credits for recent additions.
2757 2785
2758 2786 2002-10-10 Fernando Perez <fperez@colorado.edu>
2759 2787
2760 2788 * README_Mac_OSX: Added a README for Mac OSX users for fixing
2761 2789 terminal-related issues. Many thanks to Andrea Riciputi
2762 2790 <andrea.riciputi-AT-libero.it> for writing it.
2763 2791
2764 2792 * IPython/UserConfig/ipythonrc.py: Fixes to various small issues,
2765 2793 thanks to Thorsten Kampe <thorsten-AT-thorstenkampe.de>.
2766 2794
2767 2795 * setup.py (make_shortcut): Fixes for Windows installation. Thanks
2768 2796 to Fredrik Kant <fredrik.kant-AT-front.com> and Syver Enstad
2769 2797 <syver-en-AT-online.no> who both submitted patches for this problem.
2770 2798
2771 2799 * IPython/iplib.py (InteractiveShell.embed_mainloop): Patch for
2772 2800 global embedding to make sure that things don't overwrite user
2773 2801 globals accidentally. Thanks to Richard <rxe-AT-renre-europe.com>
2774 2802
2775 2803 * IPython/Gnuplot2.py (gp): Patch for Gnuplot.py 1.6
2776 2804 compatibility. Thanks to Hayden Callow
2777 2805 <h.callow-AT-elec.canterbury.ac.nz>
2778 2806
2779 2807 2002-10-04 Fernando Perez <fperez@colorado.edu>
2780 2808
2781 2809 * IPython/Gnuplot2.py (PlotItem): Added 'index' option for
2782 2810 Gnuplot.File objects.
2783 2811
2784 2812 2002-07-23 Fernando Perez <fperez@colorado.edu>
2785 2813
2786 2814 * IPython/genutils.py (timing): Added timings() and timing() for
2787 2815 quick access to the most commonly needed data, the execution
2788 2816 times. Old timing() renamed to timings_out().
2789 2817
2790 2818 2002-07-18 Fernando Perez <fperez@colorado.edu>
2791 2819
2792 2820 * IPython/Shell.py (IPShellEmbed.restore_system_completer): fixed
2793 2821 bug with nested instances disrupting the parent's tab completion.
2794 2822
2795 2823 * IPython/iplib.py (all_completions): Added Alex Schmolck's
2796 2824 all_completions code to begin the emacs integration.
2797 2825
2798 2826 * IPython/Gnuplot2.py (zip_items): Added optional 'titles'
2799 2827 argument to allow titling individual arrays when plotting.
2800 2828
2801 2829 2002-07-15 Fernando Perez <fperez@colorado.edu>
2802 2830
2803 2831 * setup.py (make_shortcut): changed to retrieve the value of
2804 2832 'Program Files' directory from the registry (this value changes in
2805 2833 non-english versions of Windows). Thanks to Thomas Fanslau
2806 2834 <tfanslau-AT-gmx.de> for the report.
2807 2835
2808 2836 2002-07-10 Fernando Perez <fperez@colorado.edu>
2809 2837
2810 2838 * IPython/ultraTB.py (VerboseTB.debugger): enabled workaround for
2811 2839 a bug in pdb, which crashes if a line with only whitespace is
2812 2840 entered. Bug report submitted to sourceforge.
2813 2841
2814 2842 2002-07-09 Fernando Perez <fperez@colorado.edu>
2815 2843
2816 2844 * IPython/ultraTB.py (VerboseTB.nullrepr): fixed rare crash when
2817 2845 reporting exceptions (it's a bug in inspect.py, I just set a
2818 2846 workaround).
2819 2847
2820 2848 2002-07-08 Fernando Perez <fperez@colorado.edu>
2821 2849
2822 2850 * IPython/iplib.py (InteractiveShell.__init__): fixed reference to
2823 2851 __IPYTHON__ in __builtins__ to show up in user_ns.
2824 2852
2825 2853 2002-07-03 Fernando Perez <fperez@colorado.edu>
2826 2854
2827 2855 * IPython/GnuplotInteractive.py (magic_gp_set_default): changed
2828 2856 name from @gp_set_instance to @gp_set_default.
2829 2857
2830 2858 * IPython/ipmaker.py (make_IPython): default editor value set to
2831 2859 '0' (a string), to match the rc file. Otherwise will crash when
2832 2860 .strip() is called on it.
2833 2861
2834 2862
2835 2863 2002-06-28 Fernando Perez <fperez@colorado.edu>
2836 2864
2837 2865 * IPython/iplib.py (InteractiveShell.safe_execfile): fix importing
2838 2866 of files in current directory when a file is executed via
2839 2867 @run. Patch also by RA <ralf_ahlbrink-AT-web.de>.
2840 2868
2841 2869 * setup.py (manfiles): fix for rpm builds, submitted by RA
2842 2870 <ralf_ahlbrink-AT-web.de>. Now we have RPMs!
2843 2871
2844 2872 * IPython/ipmaker.py (make_IPython): fixed lookup of default
2845 2873 editor when set to '0'. Problem was, '0' evaluates to True (it's a
2846 2874 string!). A. Schmolck caught this one.
2847 2875
2848 2876 2002-06-27 Fernando Perez <fperez@colorado.edu>
2849 2877
2850 2878 * IPython/ipmaker.py (make_IPython): fixed bug when running user
2851 2879 defined files at the cmd line. __name__ wasn't being set to
2852 2880 __main__.
2853 2881
2854 2882 * IPython/Gnuplot2.py (zip_items): improved it so it can plot also
2855 2883 regular lists and tuples besides Numeric arrays.
2856 2884
2857 2885 * IPython/Prompts.py (CachedOutput.__call__): Added output
2858 2886 supression for input ending with ';'. Similar to Mathematica and
2859 2887 Matlab. The _* vars and Out[] list are still updated, just like
2860 2888 Mathematica behaves.
2861 2889
2862 2890 2002-06-25 Fernando Perez <fperez@colorado.edu>
2863 2891
2864 2892 * IPython/ConfigLoader.py (ConfigLoader.load): fixed checking of
2865 2893 .ini extensions for profiels under Windows.
2866 2894
2867 2895 * IPython/OInspect.py (Inspector.pinfo): improved alignment of
2868 2896 string form. Fix contributed by Alexander Schmolck
2869 2897 <a.schmolck-AT-gmx.net>
2870 2898
2871 2899 * IPython/GnuplotRuntime.py (gp_new): new function. Returns a
2872 2900 pre-configured Gnuplot instance.
2873 2901
2874 2902 2002-06-21 Fernando Perez <fperez@colorado.edu>
2875 2903
2876 2904 * IPython/numutils.py (exp_safe): new function, works around the
2877 2905 underflow problems in Numeric.
2878 2906 (log2): New fn. Safe log in base 2: returns exact integer answer
2879 2907 for exact integer powers of 2.
2880 2908
2881 2909 * IPython/Magic.py (get_py_filename): fixed it not expanding '~'
2882 2910 properly.
2883 2911
2884 2912 2002-06-20 Fernando Perez <fperez@colorado.edu>
2885 2913
2886 2914 * IPython/genutils.py (timing): new function like
2887 2915 Mathematica's. Similar to time_test, but returns more info.
2888 2916
2889 2917 2002-06-18 Fernando Perez <fperez@colorado.edu>
2890 2918
2891 2919 * IPython/Magic.py (Magic.magic_save): modified @save and @r
2892 2920 according to Mike Heeter's suggestions.
2893 2921
2894 2922 2002-06-16 Fernando Perez <fperez@colorado.edu>
2895 2923
2896 2924 * IPython/GnuplotRuntime.py: Massive overhaul to the Gnuplot
2897 2925 system. GnuplotMagic is gone as a user-directory option. New files
2898 2926 make it easier to use all the gnuplot stuff both from external
2899 2927 programs as well as from IPython. Had to rewrite part of
2900 2928 hardcopy() b/c of a strange bug: often the ps files simply don't
2901 2929 get created, and require a repeat of the command (often several
2902 2930 times).
2903 2931
2904 2932 * IPython/ultraTB.py (AutoFormattedTB.__call__): changed to
2905 2933 resolve output channel at call time, so that if sys.stderr has
2906 2934 been redirected by user this gets honored.
2907 2935
2908 2936 2002-06-13 Fernando Perez <fperez@colorado.edu>
2909 2937
2910 2938 * IPython/Shell.py (IPShell.__init__): Changed IPythonShell to
2911 2939 IPShell. Kept a copy with the old names to avoid breaking people's
2912 2940 embedded code.
2913 2941
2914 2942 * IPython/ipython: simplified it to the bare minimum after
2915 2943 Holger's suggestions. Added info about how to use it in
2916 2944 PYTHONSTARTUP.
2917 2945
2918 2946 * IPython/Shell.py (IPythonShell): changed the options passing
2919 2947 from a string with funky %s replacements to a straight list. Maybe
2920 2948 a bit more typing, but it follows sys.argv conventions, so there's
2921 2949 less special-casing to remember.
2922 2950
2923 2951 2002-06-12 Fernando Perez <fperez@colorado.edu>
2924 2952
2925 2953 * IPython/Magic.py (Magic.magic_r): new magic auto-repeat
2926 2954 command. Thanks to a suggestion by Mike Heeter.
2927 2955 (Magic.magic_pfile): added behavior to look at filenames if given
2928 2956 arg is not a defined object.
2929 2957 (Magic.magic_save): New @save function to save code snippets. Also
2930 2958 a Mike Heeter idea.
2931 2959
2932 2960 * IPython/UserConfig/GnuplotMagic.py (plot): Improvements to
2933 2961 plot() and replot(). Much more convenient now, especially for
2934 2962 interactive use.
2935 2963
2936 2964 * IPython/Magic.py (Magic.magic_run): Added .py automatically to
2937 2965 filenames.
2938 2966
2939 2967 2002-06-02 Fernando Perez <fperez@colorado.edu>
2940 2968
2941 2969 * IPython/Struct.py (Struct.__init__): modified to admit
2942 2970 initialization via another struct.
2943 2971
2944 2972 * IPython/genutils.py (SystemExec.__init__): New stateful
2945 2973 interface to xsys and bq. Useful for writing system scripts.
2946 2974
2947 2975 2002-05-30 Fernando Perez <fperez@colorado.edu>
2948 2976
2949 2977 * MANIFEST.in: Changed docfile selection to exclude all the lyx
2950 2978 documents. This will make the user download smaller (it's getting
2951 2979 too big).
2952 2980
2953 2981 2002-05-29 Fernando Perez <fperez@colorado.edu>
2954 2982
2955 2983 * IPython/iplib.py (_FakeModule.__init__): New class introduced to
2956 2984 fix problems with shelve and pickle. Seems to work, but I don't
2957 2985 know if corner cases break it. Thanks to Mike Heeter
2958 2986 <korora-AT-SDF.LONESTAR.ORG> for the bug reports and test cases.
2959 2987
2960 2988 2002-05-24 Fernando Perez <fperez@colorado.edu>
2961 2989
2962 2990 * IPython/Magic.py (Macro.__init__): fixed magics embedded in
2963 2991 macros having broken.
2964 2992
2965 2993 2002-05-21 Fernando Perez <fperez@colorado.edu>
2966 2994
2967 2995 * IPython/Magic.py (Magic.magic_logstart): fixed recently
2968 2996 introduced logging bug: all history before logging started was
2969 2997 being written one character per line! This came from the redesign
2970 2998 of the input history as a special list which slices to strings,
2971 2999 not to lists.
2972 3000
2973 3001 2002-05-20 Fernando Perez <fperez@colorado.edu>
2974 3002
2975 3003 * IPython/Prompts.py (CachedOutput.__init__): made the color table
2976 3004 be an attribute of all classes in this module. The design of these
2977 3005 classes needs some serious overhauling.
2978 3006
2979 3007 * IPython/DPyGetOpt.py (DPyGetOpt.setPosixCompliance): fixed bug
2980 3008 which was ignoring '_' in option names.
2981 3009
2982 3010 * IPython/ultraTB.py (FormattedTB.__init__): Changed
2983 3011 'Verbose_novars' to 'Context' and made it the new default. It's a
2984 3012 bit more readable and also safer than verbose.
2985 3013
2986 3014 * IPython/PyColorize.py (Parser.__call__): Fixed coloring of
2987 3015 triple-quoted strings.
2988 3016
2989 3017 * IPython/OInspect.py (__all__): new module exposing the object
2990 3018 introspection facilities. Now the corresponding magics are dummy
2991 3019 wrappers around this. Having this module will make it much easier
2992 3020 to put these functions into our modified pdb.
2993 3021 This new object inspector system uses the new colorizing module,
2994 3022 so source code and other things are nicely syntax highlighted.
2995 3023
2996 3024 2002-05-18 Fernando Perez <fperez@colorado.edu>
2997 3025
2998 3026 * IPython/ColorANSI.py: Split the coloring tools into a separate
2999 3027 module so I can use them in other code easier (they were part of
3000 3028 ultraTB).
3001 3029
3002 3030 2002-05-17 Fernando Perez <fperez@colorado.edu>
3003 3031
3004 3032 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3005 3033 fixed it to set the global 'g' also to the called instance, as
3006 3034 long as 'g' was still a gnuplot instance (so it doesn't overwrite
3007 3035 user's 'g' variables).
3008 3036
3009 3037 * IPython/iplib.py (InteractiveShell.__init__): Added In/Out
3010 3038 global variables (aliases to _ih,_oh) so that users which expect
3011 3039 In[5] or Out[7] to work aren't unpleasantly surprised.
3012 3040 (InputList.__getslice__): new class to allow executing slices of
3013 3041 input history directly. Very simple class, complements the use of
3014 3042 macros.
3015 3043
3016 3044 2002-05-16 Fernando Perez <fperez@colorado.edu>
3017 3045
3018 3046 * setup.py (docdirbase): make doc directory be just doc/IPython
3019 3047 without version numbers, it will reduce clutter for users.
3020 3048
3021 3049 * IPython/Magic.py (Magic.magic_run): Add explicit local dict to
3022 3050 execfile call to prevent possible memory leak. See for details:
3023 3051 http://mail.python.org/pipermail/python-list/2002-February/088476.html
3024 3052
3025 3053 2002-05-15 Fernando Perez <fperez@colorado.edu>
3026 3054
3027 3055 * IPython/Magic.py (Magic.magic_psource): made the object
3028 3056 introspection names be more standard: pdoc, pdef, pfile and
3029 3057 psource. They all print/page their output, and it makes
3030 3058 remembering them easier. Kept old names for compatibility as
3031 3059 aliases.
3032 3060
3033 3061 2002-05-14 Fernando Perez <fperez@colorado.edu>
3034 3062
3035 3063 * IPython/UserConfig/GnuplotMagic.py: I think I finally understood
3036 3064 what the mouse problem was. The trick is to use gnuplot with temp
3037 3065 files and NOT with pipes (for data communication), because having
3038 3066 both pipes and the mouse on is bad news.
3039 3067
3040 3068 2002-05-13 Fernando Perez <fperez@colorado.edu>
3041 3069
3042 3070 * IPython/Magic.py (Magic._ofind): fixed namespace order search
3043 3071 bug. Information would be reported about builtins even when
3044 3072 user-defined functions overrode them.
3045 3073
3046 3074 2002-05-11 Fernando Perez <fperez@colorado.edu>
3047 3075
3048 3076 * IPython/__init__.py (__all__): removed FlexCompleter from
3049 3077 __all__ so that things don't fail in platforms without readline.
3050 3078
3051 3079 2002-05-10 Fernando Perez <fperez@colorado.edu>
3052 3080
3053 3081 * IPython/__init__.py (__all__): removed numutils from __all__ b/c
3054 3082 it requires Numeric, effectively making Numeric a dependency for
3055 3083 IPython.
3056 3084
3057 3085 * Released 0.2.13
3058 3086
3059 3087 * IPython/Magic.py (Magic.magic_prun): big overhaul to the
3060 3088 profiler interface. Now all the major options from the profiler
3061 3089 module are directly supported in IPython, both for single
3062 3090 expressions (@prun) and for full programs (@run -p).
3063 3091
3064 3092 2002-05-09 Fernando Perez <fperez@colorado.edu>
3065 3093
3066 3094 * IPython/Magic.py (Magic.magic_doc): fixed to show docstrings of
3067 3095 magic properly formatted for screen.
3068 3096
3069 3097 * setup.py (make_shortcut): Changed things to put pdf version in
3070 3098 doc/ instead of doc/manual (had to change lyxport a bit).
3071 3099
3072 3100 * IPython/Magic.py (Profile.string_stats): made profile runs go
3073 3101 through pager (they are long and a pager allows searching, saving,
3074 3102 etc.)
3075 3103
3076 3104 2002-05-08 Fernando Perez <fperez@colorado.edu>
3077 3105
3078 3106 * Released 0.2.12
3079 3107
3080 3108 2002-05-06 Fernando Perez <fperez@colorado.edu>
3081 3109
3082 3110 * IPython/Magic.py (Magic.magic_hist): small bug fixed (recently
3083 3111 introduced); 'hist n1 n2' was broken.
3084 3112 (Magic.magic_pdb): added optional on/off arguments to @pdb
3085 3113 (Magic.magic_run): added option -i to @run, which executes code in
3086 3114 the IPython namespace instead of a clean one. Also added @irun as
3087 3115 an alias to @run -i.
3088 3116
3089 3117 * IPython/UserConfig/GnuplotMagic.py (magic_gp_set_instance):
3090 3118 fixed (it didn't really do anything, the namespaces were wrong).
3091 3119
3092 3120 * IPython/Debugger.py (__init__): Added workaround for python 2.1
3093 3121
3094 3122 * IPython/__init__.py (__all__): Fixed package namespace, now
3095 3123 'import IPython' does give access to IPython.<all> as
3096 3124 expected. Also renamed __release__ to Release.
3097 3125
3098 3126 * IPython/Debugger.py (__license__): created new Pdb class which
3099 3127 functions like a drop-in for the normal pdb.Pdb but does NOT
3100 3128 import readline by default. This way it doesn't muck up IPython's
3101 3129 readline handling, and now tab-completion finally works in the
3102 3130 debugger -- sort of. It completes things globally visible, but the
3103 3131 completer doesn't track the stack as pdb walks it. That's a bit
3104 3132 tricky, and I'll have to implement it later.
3105 3133
3106 3134 2002-05-05 Fernando Perez <fperez@colorado.edu>
3107 3135
3108 3136 * IPython/Magic.py (Magic.magic_oinfo): fixed formatting bug for
3109 3137 magic docstrings when printed via ? (explicit \'s were being
3110 3138 printed).
3111 3139
3112 3140 * IPython/ipmaker.py (make_IPython): fixed namespace
3113 3141 identification bug. Now variables loaded via logs or command-line
3114 3142 files are recognized in the interactive namespace by @who.
3115 3143
3116 3144 * IPython/iplib.py (InteractiveShell.safe_execfile): Fixed bug in
3117 3145 log replay system stemming from the string form of Structs.
3118 3146
3119 3147 * IPython/Magic.py (Macro.__init__): improved macros to properly
3120 3148 handle magic commands in them.
3121 3149 (Magic.magic_logstart): usernames are now expanded so 'logstart
3122 3150 ~/mylog' now works.
3123 3151
3124 3152 * IPython/iplib.py (complete): fixed bug where paths starting with
3125 3153 '/' would be completed as magic names.
3126 3154
3127 3155 2002-05-04 Fernando Perez <fperez@colorado.edu>
3128 3156
3129 3157 * IPython/Magic.py (Magic.magic_run): added options -p and -f to
3130 3158 allow running full programs under the profiler's control.
3131 3159
3132 3160 * IPython/ultraTB.py (FormattedTB.__init__): Added Verbose_novars
3133 3161 mode to report exceptions verbosely but without formatting
3134 3162 variables. This addresses the issue of ipython 'freezing' (it's
3135 3163 not frozen, but caught in an expensive formatting loop) when huge
3136 3164 variables are in the context of an exception.
3137 3165 (VerboseTB.text): Added '--->' markers at line where exception was
3138 3166 triggered. Much clearer to read, especially in NoColor modes.
3139 3167
3140 3168 * IPython/Magic.py (Magic.magic_run): bugfix: -n option had been
3141 3169 implemented in reverse when changing to the new parse_options().
3142 3170
3143 3171 2002-05-03 Fernando Perez <fperez@colorado.edu>
3144 3172
3145 3173 * IPython/Magic.py (Magic.parse_options): new function so that
3146 3174 magics can parse options easier.
3147 3175 (Magic.magic_prun): new function similar to profile.run(),
3148 3176 suggested by Chris Hart.
3149 3177 (Magic.magic_cd): fixed behavior so that it only changes if
3150 3178 directory actually is in history.
3151 3179
3152 3180 * IPython/usage.py (__doc__): added information about potential
3153 3181 slowness of Verbose exception mode when there are huge data
3154 3182 structures to be formatted (thanks to Archie Paulson).
3155 3183
3156 3184 * IPython/ipmaker.py (make_IPython): Changed default logging
3157 3185 (when simply called with -log) to use curr_dir/ipython.log in
3158 3186 rotate mode. Fixed crash which was occuring with -log before
3159 3187 (thanks to Jim Boyle).
3160 3188
3161 3189 2002-05-01 Fernando Perez <fperez@colorado.edu>
3162 3190
3163 3191 * Released 0.2.11 for these fixes (mainly the ultraTB one which
3164 3192 was nasty -- though somewhat of a corner case).
3165 3193
3166 3194 * IPython/ultraTB.py (AutoFormattedTB.text): renamed __text to
3167 3195 text (was a bug).
3168 3196
3169 3197 2002-04-30 Fernando Perez <fperez@colorado.edu>
3170 3198
3171 3199 * IPython/UserConfig/GnuplotMagic.py (magic_gp): Minor fix to add
3172 3200 a print after ^D or ^C from the user so that the In[] prompt
3173 3201 doesn't over-run the gnuplot one.
3174 3202
3175 3203 2002-04-29 Fernando Perez <fperez@colorado.edu>
3176 3204
3177 3205 * Released 0.2.10
3178 3206
3179 3207 * IPython/__release__.py (version): get date dynamically.
3180 3208
3181 3209 * Misc. documentation updates thanks to Arnd's comments. Also ran
3182 3210 a full spellcheck on the manual (hadn't been done in a while).
3183 3211
3184 3212 2002-04-27 Fernando Perez <fperez@colorado.edu>
3185 3213
3186 3214 * IPython/Magic.py (Magic.magic_logstart): Fixed bug where
3187 3215 starting a log in mid-session would reset the input history list.
3188 3216
3189 3217 2002-04-26 Fernando Perez <fperez@colorado.edu>
3190 3218
3191 3219 * IPython/iplib.py (InteractiveShell.wait): Fixed bug where not
3192 3220 all files were being included in an update. Now anything in
3193 3221 UserConfig that matches [A-Za-z]*.py will go (this excludes
3194 3222 __init__.py)
3195 3223
3196 3224 2002-04-25 Fernando Perez <fperez@colorado.edu>
3197 3225
3198 3226 * IPython/iplib.py (InteractiveShell.__init__): Added __IPYTHON__
3199 3227 to __builtins__ so that any form of embedded or imported code can
3200 3228 test for being inside IPython.
3201 3229
3202 3230 * IPython/UserConfig/GnuplotMagic.py: (magic_gp_set_instance):
3203 3231 changed to GnuplotMagic because it's now an importable module,
3204 3232 this makes the name follow that of the standard Gnuplot module.
3205 3233 GnuplotMagic can now be loaded at any time in mid-session.
3206 3234
3207 3235 2002-04-24 Fernando Perez <fperez@colorado.edu>
3208 3236
3209 3237 * IPython/numutils.py: removed SIUnits. It doesn't properly set
3210 3238 the globals (IPython has its own namespace) and the
3211 3239 PhysicalQuantity stuff is much better anyway.
3212 3240
3213 3241 * IPython/UserConfig/example-gnuplot.py (g2): Added gnuplot
3214 3242 embedding example to standard user directory for
3215 3243 distribution. Also put it in the manual.
3216 3244
3217 3245 * IPython/numutils.py (gnuplot_exec): Changed to take a gnuplot
3218 3246 instance as first argument (so it doesn't rely on some obscure
3219 3247 hidden global).
3220 3248
3221 3249 * IPython/UserConfig/ipythonrc.py: put () back in accepted
3222 3250 delimiters. While it prevents ().TAB from working, it allows
3223 3251 completions in open (... expressions. This is by far a more common
3224 3252 case.
3225 3253
3226 3254 2002-04-23 Fernando Perez <fperez@colorado.edu>
3227 3255
3228 3256 * IPython/Extensions/InterpreterPasteInput.py: new
3229 3257 syntax-processing module for pasting lines with >>> or ... at the
3230 3258 start.
3231 3259
3232 3260 * IPython/Extensions/PhysicalQ_Interactive.py
3233 3261 (PhysicalQuantityInteractive.__int__): fixed to work with either
3234 3262 Numeric or math.
3235 3263
3236 3264 * IPython/UserConfig/ipythonrc-numeric.py: reorganized the
3237 3265 provided profiles. Now we have:
3238 3266 -math -> math module as * and cmath with its own namespace.
3239 3267 -numeric -> Numeric as *, plus gnuplot & grace
3240 3268 -physics -> same as before
3241 3269
3242 3270 * IPython/Magic.py (Magic.magic_magic): Fixed bug where
3243 3271 user-defined magics wouldn't be found by @magic if they were
3244 3272 defined as class methods. Also cleaned up the namespace search
3245 3273 logic and the string building (to use %s instead of many repeated
3246 3274 string adds).
3247 3275
3248 3276 * IPython/UserConfig/example-magic.py (magic_foo): updated example
3249 3277 of user-defined magics to operate with class methods (cleaner, in
3250 3278 line with the gnuplot code).
3251 3279
3252 3280 2002-04-22 Fernando Perez <fperez@colorado.edu>
3253 3281
3254 3282 * setup.py: updated dependency list so that manual is updated when
3255 3283 all included files change.
3256 3284
3257 3285 * IPython/ipmaker.py (make_IPython): Fixed bug which was ignoring
3258 3286 the delimiter removal option (the fix is ugly right now).
3259 3287
3260 3288 * IPython/UserConfig/ipythonrc-physics.py: simplified not to load
3261 3289 all of the math profile (quicker loading, no conflict between
3262 3290 g-9.8 and g-gnuplot).
3263 3291
3264 3292 * IPython/CrashHandler.py (CrashHandler.__call__): changed default
3265 3293 name of post-mortem files to IPython_crash_report.txt.
3266 3294
3267 3295 * Cleanup/update of the docs. Added all the new readline info and
3268 3296 formatted all lists as 'real lists'.
3269 3297
3270 3298 * IPython/ipmaker.py (make_IPython): removed now-obsolete
3271 3299 tab-completion options, since the full readline parse_and_bind is
3272 3300 now accessible.
3273 3301
3274 3302 * IPython/iplib.py (InteractiveShell.init_readline): Changed
3275 3303 handling of readline options. Now users can specify any string to
3276 3304 be passed to parse_and_bind(), as well as the delimiters to be
3277 3305 removed.
3278 3306 (InteractiveShell.__init__): Added __name__ to the global
3279 3307 namespace so that things like Itpl which rely on its existence
3280 3308 don't crash.
3281 3309 (InteractiveShell._prefilter): Defined the default with a _ so
3282 3310 that prefilter() is easier to override, while the default one
3283 3311 remains available.
3284 3312
3285 3313 2002-04-18 Fernando Perez <fperez@colorado.edu>
3286 3314
3287 3315 * Added information about pdb in the docs.
3288 3316
3289 3317 2002-04-17 Fernando Perez <fperez@colorado.edu>
3290 3318
3291 3319 * IPython/ipmaker.py (make_IPython): added rc_override option to
3292 3320 allow passing config options at creation time which may override
3293 3321 anything set in the config files or command line. This is
3294 3322 particularly useful for configuring embedded instances.
3295 3323
3296 3324 2002-04-15 Fernando Perez <fperez@colorado.edu>
3297 3325
3298 3326 * IPython/Logger.py (Logger.log): Fixed a nasty bug which could
3299 3327 crash embedded instances because of the input cache falling out of
3300 3328 sync with the output counter.
3301 3329
3302 3330 * IPython/Shell.py (IPythonShellEmbed.__init__): added a debug
3303 3331 mode which calls pdb after an uncaught exception in IPython itself.
3304 3332
3305 3333 2002-04-14 Fernando Perez <fperez@colorado.edu>
3306 3334
3307 3335 * IPython/iplib.py (InteractiveShell.showtraceback): pdb mucks up
3308 3336 readline, fix it back after each call.
3309 3337
3310 3338 * IPython/ultraTB.py (AutoFormattedTB.__text): made text a private
3311 3339 method to force all access via __call__(), which guarantees that
3312 3340 traceback references are properly deleted.
3313 3341
3314 3342 * IPython/Prompts.py (CachedOutput._display): minor fixes to
3315 3343 improve printing when pprint is in use.
3316 3344
3317 3345 2002-04-13 Fernando Perez <fperez@colorado.edu>
3318 3346
3319 3347 * IPython/Shell.py (IPythonShellEmbed.__call__): SystemExit
3320 3348 exceptions aren't caught anymore. If the user triggers one, he
3321 3349 should know why he's doing it and it should go all the way up,
3322 3350 just like any other exception. So now @abort will fully kill the
3323 3351 embedded interpreter and the embedding code (unless that happens
3324 3352 to catch SystemExit).
3325 3353
3326 3354 * IPython/ultraTB.py (VerboseTB.__init__): added a call_pdb flag
3327 3355 and a debugger() method to invoke the interactive pdb debugger
3328 3356 after printing exception information. Also added the corresponding
3329 3357 -pdb option and @pdb magic to control this feature, and updated
3330 3358 the docs. After a suggestion from Christopher Hart
3331 3359 (hart-AT-caltech.edu).
3332 3360
3333 3361 2002-04-12 Fernando Perez <fperez@colorado.edu>
3334 3362
3335 3363 * IPython/Shell.py (IPythonShellEmbed.__init__): modified to use
3336 3364 the exception handlers defined by the user (not the CrashHandler)
3337 3365 so that user exceptions don't trigger an ipython bug report.
3338 3366
3339 3367 * IPython/ultraTB.py (ColorTB.__init__): made the color scheme
3340 3368 configurable (it should have always been so).
3341 3369
3342 3370 2002-03-26 Fernando Perez <fperez@colorado.edu>
3343 3371
3344 3372 * IPython/Shell.py (IPythonShellEmbed.__call__): many changes here
3345 3373 and there to fix embedding namespace issues. This should all be
3346 3374 done in a more elegant way.
3347 3375
3348 3376 2002-03-25 Fernando Perez <fperez@colorado.edu>
3349 3377
3350 3378 * IPython/genutils.py (get_home_dir): Try to make it work under
3351 3379 win9x also.
3352 3380
3353 3381 2002-03-20 Fernando Perez <fperez@colorado.edu>
3354 3382
3355 3383 * IPython/Shell.py (IPythonShellEmbed.__init__): leave
3356 3384 sys.displayhook untouched upon __init__.
3357 3385
3358 3386 2002-03-19 Fernando Perez <fperez@colorado.edu>
3359 3387
3360 3388 * Released 0.2.9 (for embedding bug, basically).
3361 3389
3362 3390 * IPython/Shell.py (IPythonShellEmbed.__call__): Trap SystemExit
3363 3391 exceptions so that enclosing shell's state can be restored.
3364 3392
3365 3393 * Changed magic_gnuplot.py to magic-gnuplot.py to standardize
3366 3394 naming conventions in the .ipython/ dir.
3367 3395
3368 3396 * IPython/iplib.py (InteractiveShell.init_readline): removed '-'
3369 3397 from delimiters list so filenames with - in them get expanded.
3370 3398
3371 3399 * IPython/Shell.py (IPythonShellEmbed.__call__): fixed bug with
3372 3400 sys.displayhook not being properly restored after an embedded call.
3373 3401
3374 3402 2002-03-18 Fernando Perez <fperez@colorado.edu>
3375 3403
3376 3404 * Released 0.2.8
3377 3405
3378 3406 * IPython/iplib.py (InteractiveShell.user_setup): fixed bug where
3379 3407 some files weren't being included in a -upgrade.
3380 3408 (InteractiveShell.init_readline): Added 'set show-all-if-ambiguous
3381 3409 on' so that the first tab completes.
3382 3410 (InteractiveShell.handle_magic): fixed bug with spaces around
3383 3411 quotes breaking many magic commands.
3384 3412
3385 3413 * setup.py: added note about ignoring the syntax error messages at
3386 3414 installation.
3387 3415
3388 3416 * IPython/UserConfig/magic_gnuplot.py (magic_gp): finished
3389 3417 streamlining the gnuplot interface, now there's only one magic @gp.
3390 3418
3391 3419 2002-03-17 Fernando Perez <fperez@colorado.edu>
3392 3420
3393 3421 * IPython/UserConfig/magic_gnuplot.py: new name for the
3394 3422 example-magic_pm.py file. Much enhanced system, now with a shell
3395 3423 for communicating directly with gnuplot, one command at a time.
3396 3424
3397 3425 * IPython/Magic.py (Magic.magic_run): added option -n to prevent
3398 3426 setting __name__=='__main__'.
3399 3427
3400 3428 * IPython/UserConfig/example-magic_pm.py (magic_pm): Added
3401 3429 mini-shell for accessing gnuplot from inside ipython. Should
3402 3430 extend it later for grace access too. Inspired by Arnd's
3403 3431 suggestion.
3404 3432
3405 3433 * IPython/iplib.py (InteractiveShell.handle_magic): fixed bug when
3406 3434 calling magic functions with () in their arguments. Thanks to Arnd
3407 3435 Baecker for pointing this to me.
3408 3436
3409 3437 * IPython/numutils.py (sum_flat): fixed bug. Would recurse
3410 3438 infinitely for integer or complex arrays (only worked with floats).
3411 3439
3412 3440 2002-03-16 Fernando Perez <fperez@colorado.edu>
3413 3441
3414 3442 * setup.py: Merged setup and setup_windows into a single script
3415 3443 which properly handles things for windows users.
3416 3444
3417 3445 2002-03-15 Fernando Perez <fperez@colorado.edu>
3418 3446
3419 3447 * Big change to the manual: now the magics are all automatically
3420 3448 documented. This information is generated from their docstrings
3421 3449 and put in a latex file included by the manual lyx file. This way
3422 3450 we get always up to date information for the magics. The manual
3423 3451 now also has proper version information, also auto-synced.
3424 3452
3425 3453 For this to work, an undocumented --magic_docstrings option was added.
3426 3454
3427 3455 2002-03-13 Fernando Perez <fperez@colorado.edu>
3428 3456
3429 3457 * IPython/ultraTB.py (TermColors): fixed problem with dark colors
3430 3458 under CDE terminals. An explicit ;2 color reset is needed in the escapes.
3431 3459
3432 3460 2002-03-12 Fernando Perez <fperez@colorado.edu>
3433 3461
3434 3462 * IPython/ultraTB.py (TermColors): changed color escapes again to
3435 3463 fix the (old, reintroduced) line-wrapping bug. Basically, if
3436 3464 \001..\002 aren't given in the color escapes, lines get wrapped
3437 3465 weirdly. But giving those screws up old xterms and emacs terms. So
3438 3466 I added some logic for emacs terms to be ok, but I can't identify old
3439 3467 xterms separately ($TERM=='xterm' for many terminals, like konsole).
3440 3468
3441 3469 2002-03-10 Fernando Perez <fperez@colorado.edu>
3442 3470
3443 3471 * IPython/usage.py (__doc__): Various documentation cleanups and
3444 3472 updates, both in usage docstrings and in the manual.
3445 3473
3446 3474 * IPython/Prompts.py (CachedOutput.set_colors): cleanups for
3447 3475 handling of caching. Set minimum acceptabe value for having a
3448 3476 cache at 20 values.
3449 3477
3450 3478 * IPython/iplib.py (InteractiveShell.user_setup): moved the
3451 3479 install_first_time function to a method, renamed it and added an
3452 3480 'upgrade' mode. Now people can update their config directory with
3453 3481 a simple command line switch (-upgrade, also new).
3454 3482
3455 3483 * IPython/Magic.py (Magic.magic_pfile): Made @pfile an alias to
3456 3484 @file (convenient for automagic users under Python >= 2.2).
3457 3485 Removed @files (it seemed more like a plural than an abbrev. of
3458 3486 'file show').
3459 3487
3460 3488 * IPython/iplib.py (install_first_time): Fixed crash if there were
3461 3489 backup files ('~') in .ipython/ install directory.
3462 3490
3463 3491 * IPython/ipmaker.py (make_IPython): fixes for new prompt
3464 3492 system. Things look fine, but these changes are fairly
3465 3493 intrusive. Test them for a few days.
3466 3494
3467 3495 * IPython/Prompts.py (CachedOutput.__init__): Massive rewrite of
3468 3496 the prompts system. Now all in/out prompt strings are user
3469 3497 controllable. This is particularly useful for embedding, as one
3470 3498 can tag embedded instances with particular prompts.
3471 3499
3472 3500 Also removed global use of sys.ps1/2, which now allows nested
3473 3501 embeddings without any problems. Added command-line options for
3474 3502 the prompt strings.
3475 3503
3476 3504 2002-03-08 Fernando Perez <fperez@colorado.edu>
3477 3505
3478 3506 * IPython/UserConfig/example-embed-short.py (ipshell): added
3479 3507 example file with the bare minimum code for embedding.
3480 3508
3481 3509 * IPython/Shell.py (IPythonShellEmbed.set_dummy_mode): added
3482 3510 functionality for the embeddable shell to be activated/deactivated
3483 3511 either globally or at each call.
3484 3512
3485 3513 * IPython/Prompts.py (Prompt1.auto_rewrite): Fixes the problem of
3486 3514 rewriting the prompt with '--->' for auto-inputs with proper
3487 3515 coloring. Now the previous UGLY hack in handle_auto() is gone, and
3488 3516 this is handled by the prompts class itself, as it should.
3489 3517
3490 3518 2002-03-05 Fernando Perez <fperez@colorado.edu>
3491 3519
3492 3520 * IPython/Magic.py (Magic.magic_logstart): Changed @log to
3493 3521 @logstart to avoid name clashes with the math log function.
3494 3522
3495 3523 * Big updates to X/Emacs section of the manual.
3496 3524
3497 3525 * Removed ipython_emacs. Milan explained to me how to pass
3498 3526 arguments to ipython through Emacs. Some day I'm going to end up
3499 3527 learning some lisp...
3500 3528
3501 3529 2002-03-04 Fernando Perez <fperez@colorado.edu>
3502 3530
3503 3531 * IPython/ipython_emacs: Created script to be used as the
3504 3532 py-python-command Emacs variable so we can pass IPython
3505 3533 parameters. I can't figure out how to tell Emacs directly to pass
3506 3534 parameters to IPython, so a dummy shell script will do it.
3507 3535
3508 3536 Other enhancements made for things to work better under Emacs'
3509 3537 various types of terminals. Many thanks to Milan Zamazal
3510 3538 <pdm-AT-zamazal.org> for all the suggestions and pointers.
3511 3539
3512 3540 2002-03-01 Fernando Perez <fperez@colorado.edu>
3513 3541
3514 3542 * IPython/ipmaker.py (make_IPython): added a --readline! option so
3515 3543 that loading of readline is now optional. This gives better
3516 3544 control to emacs users.
3517 3545
3518 3546 * IPython/ultraTB.py (__date__): Modified color escape sequences
3519 3547 and now things work fine under xterm and in Emacs' term buffers
3520 3548 (though not shell ones). Well, in emacs you get colors, but all
3521 3549 seem to be 'light' colors (no difference between dark and light
3522 3550 ones). But the garbage chars are gone, and also in xterms. It
3523 3551 seems that now I'm using 'cleaner' ansi sequences.
3524 3552
3525 3553 2002-02-21 Fernando Perez <fperez@colorado.edu>
3526 3554
3527 3555 * Released 0.2.7 (mainly to publish the scoping fix).
3528 3556
3529 3557 * IPython/Logger.py (Logger.logstate): added. A corresponding
3530 3558 @logstate magic was created.
3531 3559
3532 3560 * IPython/Magic.py: fixed nested scoping problem under Python
3533 3561 2.1.x (automagic wasn't working).
3534 3562
3535 3563 2002-02-20 Fernando Perez <fperez@colorado.edu>
3536 3564
3537 3565 * Released 0.2.6.
3538 3566
3539 3567 * IPython/OutputTrap.py (OutputTrap.__init__): added a 'quiet'
3540 3568 option so that logs can come out without any headers at all.
3541 3569
3542 3570 * IPython/UserConfig/ipythonrc-scipy.py: created a profile for
3543 3571 SciPy.
3544 3572
3545 3573 * IPython/iplib.py (InteractiveShell.embed_mainloop): Changed so
3546 3574 that embedded IPython calls don't require vars() to be explicitly
3547 3575 passed. Now they are extracted from the caller's frame (code
3548 3576 snatched from Eric Jones' weave). Added better documentation to
3549 3577 the section on embedding and the example file.
3550 3578
3551 3579 * IPython/genutils.py (page): Changed so that under emacs, it just
3552 3580 prints the string. You can then page up and down in the emacs
3553 3581 buffer itself. This is how the builtin help() works.
3554 3582
3555 3583 * IPython/Prompts.py (CachedOutput.__call__): Fixed issue with
3556 3584 macro scoping: macros need to be executed in the user's namespace
3557 3585 to work as if they had been typed by the user.
3558 3586
3559 3587 * IPython/Magic.py (Magic.magic_macro): Changed macros so they
3560 3588 execute automatically (no need to type 'exec...'). They then
3561 3589 behave like 'true macros'. The printing system was also modified
3562 3590 for this to work.
3563 3591
3564 3592 2002-02-19 Fernando Perez <fperez@colorado.edu>
3565 3593
3566 3594 * IPython/genutils.py (page_file): new function for paging files
3567 3595 in an OS-independent way. Also necessary for file viewing to work
3568 3596 well inside Emacs buffers.
3569 3597 (page): Added checks for being in an emacs buffer.
3570 3598 (page): fixed bug for Windows ($TERM isn't set in Windows). Fixed
3571 3599 same bug in iplib.
3572 3600
3573 3601 2002-02-18 Fernando Perez <fperez@colorado.edu>
3574 3602
3575 3603 * IPython/iplib.py (InteractiveShell.init_readline): modified use
3576 3604 of readline so that IPython can work inside an Emacs buffer.
3577 3605
3578 3606 * IPython/ultraTB.py (AutoFormattedTB.__call__): some fixes to
3579 3607 method signatures (they weren't really bugs, but it looks cleaner
3580 3608 and keeps PyChecker happy).
3581 3609
3582 3610 * IPython/ipmaker.py (make_IPython): added hooks Struct to __IP
3583 3611 for implementing various user-defined hooks. Currently only
3584 3612 display is done.
3585 3613
3586 3614 * IPython/Prompts.py (CachedOutput._display): changed display
3587 3615 functions so that they can be dynamically changed by users easily.
3588 3616
3589 3617 * IPython/Extensions/numeric_formats.py (num_display): added an
3590 3618 extension for printing NumPy arrays in flexible manners. It
3591 3619 doesn't do anything yet, but all the structure is in
3592 3620 place. Ultimately the plan is to implement output format control
3593 3621 like in Octave.
3594 3622
3595 3623 * IPython/Magic.py (Magic.lsmagic): changed so that bound magic
3596 3624 methods are found at run-time by all the automatic machinery.
3597 3625
3598 3626 2002-02-17 Fernando Perez <fperez@colorado.edu>
3599 3627
3600 3628 * setup_Windows.py (make_shortcut): documented. Cleaned up the
3601 3629 whole file a little.
3602 3630
3603 3631 * ToDo: closed this document. Now there's a new_design.lyx
3604 3632 document for all new ideas. Added making a pdf of it for the
3605 3633 end-user distro.
3606 3634
3607 3635 * IPython/Logger.py (Logger.switch_log): Created this to replace
3608 3636 logon() and logoff(). It also fixes a nasty crash reported by
3609 3637 Philip Hisley <compsys-AT-starpower.net>. Many thanks to him.
3610 3638
3611 3639 * IPython/iplib.py (complete): got auto-completion to work with
3612 3640 automagic (I had wanted this for a long time).
3613 3641
3614 3642 * IPython/Magic.py (Magic.magic_files): Added @files as an alias
3615 3643 to @file, since file() is now a builtin and clashes with automagic
3616 3644 for @file.
3617 3645
3618 3646 * Made some new files: Prompts, CrashHandler, Magic, Logger. All
3619 3647 of this was previously in iplib, which had grown to more than 2000
3620 3648 lines, way too long. No new functionality, but it makes managing
3621 3649 the code a bit easier.
3622 3650
3623 3651 * IPython/iplib.py (IPythonCrashHandler.__call__): Added version
3624 3652 information to crash reports.
3625 3653
3626 3654 2002-02-12 Fernando Perez <fperez@colorado.edu>
3627 3655
3628 3656 * Released 0.2.5.
3629 3657
3630 3658 2002-02-11 Fernando Perez <fperez@colorado.edu>
3631 3659
3632 3660 * Wrote a relatively complete Windows installer. It puts
3633 3661 everything in place, creates Start Menu entries and fixes the
3634 3662 color issues. Nothing fancy, but it works.
3635 3663
3636 3664 2002-02-10 Fernando Perez <fperez@colorado.edu>
3637 3665
3638 3666 * IPython/iplib.py (InteractiveShell.safe_execfile): added an
3639 3667 os.path.expanduser() call so that we can type @run ~/myfile.py and
3640 3668 have thigs work as expected.
3641 3669
3642 3670 * IPython/genutils.py (page): fixed exception handling so things
3643 3671 work both in Unix and Windows correctly. Quitting a pager triggers
3644 3672 an IOError/broken pipe in Unix, and in windows not finding a pager
3645 3673 is also an IOError, so I had to actually look at the return value
3646 3674 of the exception, not just the exception itself. Should be ok now.
3647 3675
3648 3676 * IPython/ultraTB.py (ColorSchemeTable.set_active_scheme):
3649 3677 modified to allow case-insensitive color scheme changes.
3650 3678
3651 3679 2002-02-09 Fernando Perez <fperez@colorado.edu>
3652 3680
3653 3681 * IPython/genutils.py (native_line_ends): new function to leave
3654 3682 user config files with os-native line-endings.
3655 3683
3656 3684 * README and manual updates.
3657 3685
3658 3686 * IPython/genutils.py: fixed unicode bug: use types.StringTypes
3659 3687 instead of StringType to catch Unicode strings.
3660 3688
3661 3689 * IPython/genutils.py (filefind): fixed bug for paths with
3662 3690 embedded spaces (very common in Windows).
3663 3691
3664 3692 * IPython/ipmaker.py (make_IPython): added a '.ini' to the rc
3665 3693 files under Windows, so that they get automatically associated
3666 3694 with a text editor. Windows makes it a pain to handle
3667 3695 extension-less files.
3668 3696
3669 3697 * IPython/iplib.py (InteractiveShell.init_readline): Made the
3670 3698 warning about readline only occur for Posix. In Windows there's no
3671 3699 way to get readline, so why bother with the warning.
3672 3700
3673 3701 * IPython/Struct.py (Struct.__str__): fixed to use self.__dict__
3674 3702 for __str__ instead of dir(self), since dir() changed in 2.2.
3675 3703
3676 3704 * Ported to Windows! Tested on XP, I suspect it should work fine
3677 3705 on NT/2000, but I don't think it will work on 98 et al. That
3678 3706 series of Windows is such a piece of junk anyway that I won't try
3679 3707 porting it there. The XP port was straightforward, showed a few
3680 3708 bugs here and there (fixed all), in particular some string
3681 3709 handling stuff which required considering Unicode strings (which
3682 3710 Windows uses). This is good, but hasn't been too tested :) No
3683 3711 fancy installer yet, I'll put a note in the manual so people at
3684 3712 least make manually a shortcut.
3685 3713
3686 3714 * IPython/iplib.py (Magic.magic_colors): Unified the color options
3687 3715 into a single one, "colors". This now controls both prompt and
3688 3716 exception color schemes, and can be changed both at startup
3689 3717 (either via command-line switches or via ipythonrc files) and at
3690 3718 runtime, with @colors.
3691 3719 (Magic.magic_run): renamed @prun to @run and removed the old
3692 3720 @run. The two were too similar to warrant keeping both.
3693 3721
3694 3722 2002-02-03 Fernando Perez <fperez@colorado.edu>
3695 3723
3696 3724 * IPython/iplib.py (install_first_time): Added comment on how to
3697 3725 configure the color options for first-time users. Put a <return>
3698 3726 request at the end so that small-terminal users get a chance to
3699 3727 read the startup info.
3700 3728
3701 3729 2002-01-23 Fernando Perez <fperez@colorado.edu>
3702 3730
3703 3731 * IPython/iplib.py (CachedOutput.update): Changed output memory
3704 3732 variable names from _o,_oo,_ooo,_o<n> to simply _,__,___,_<n>. For
3705 3733 input history we still use _i. Did this b/c these variable are
3706 3734 very commonly used in interactive work, so the less we need to
3707 3735 type the better off we are.
3708 3736 (Magic.magic_prun): updated @prun to better handle the namespaces
3709 3737 the file will run in, including a fix for __name__ not being set
3710 3738 before.
3711 3739
3712 3740 2002-01-20 Fernando Perez <fperez@colorado.edu>
3713 3741
3714 3742 * IPython/ultraTB.py (VerboseTB.linereader): Fixed printing of
3715 3743 extra garbage for Python 2.2. Need to look more carefully into
3716 3744 this later.
3717 3745
3718 3746 2002-01-19 Fernando Perez <fperez@colorado.edu>
3719 3747
3720 3748 * IPython/iplib.py (InteractiveShell.showtraceback): fixed to
3721 3749 display SyntaxError exceptions properly formatted when they occur
3722 3750 (they can be triggered by imported code).
3723 3751
3724 3752 2002-01-18 Fernando Perez <fperez@colorado.edu>
3725 3753
3726 3754 * IPython/iplib.py (InteractiveShell.safe_execfile): now
3727 3755 SyntaxError exceptions are reported nicely formatted, instead of
3728 3756 spitting out only offset information as before.
3729 3757 (Magic.magic_prun): Added the @prun function for executing
3730 3758 programs with command line args inside IPython.
3731 3759
3732 3760 2002-01-16 Fernando Perez <fperez@colorado.edu>
3733 3761
3734 3762 * IPython/iplib.py (Magic.magic_hist): Changed @hist and @dhist
3735 3763 to *not* include the last item given in a range. This brings their
3736 3764 behavior in line with Python's slicing:
3737 3765 a[n1:n2] -> a[n1]...a[n2-1]
3738 3766 It may be a bit less convenient, but I prefer to stick to Python's
3739 3767 conventions *everywhere*, so users never have to wonder.
3740 3768 (Magic.magic_macro): Added @macro function to ease the creation of
3741 3769 macros.
3742 3770
3743 3771 2002-01-05 Fernando Perez <fperez@colorado.edu>
3744 3772
3745 3773 * Released 0.2.4.
3746 3774
3747 3775 * IPython/iplib.py (Magic.magic_pdef):
3748 3776 (InteractiveShell.safe_execfile): report magic lines and error
3749 3777 lines without line numbers so one can easily copy/paste them for
3750 3778 re-execution.
3751 3779
3752 3780 * Updated manual with recent changes.
3753 3781
3754 3782 * IPython/iplib.py (Magic.magic_oinfo): added constructor
3755 3783 docstring printing when class? is called. Very handy for knowing
3756 3784 how to create class instances (as long as __init__ is well
3757 3785 documented, of course :)
3758 3786 (Magic.magic_doc): print both class and constructor docstrings.
3759 3787 (Magic.magic_pdef): give constructor info if passed a class and
3760 3788 __call__ info for callable object instances.
3761 3789
3762 3790 2002-01-04 Fernando Perez <fperez@colorado.edu>
3763 3791
3764 3792 * Made deep_reload() off by default. It doesn't always work
3765 3793 exactly as intended, so it's probably safer to have it off. It's
3766 3794 still available as dreload() anyway, so nothing is lost.
3767 3795
3768 3796 2002-01-02 Fernando Perez <fperez@colorado.edu>
3769 3797
3770 3798 * Released 0.2.3 (contacted R.Singh at CU about biopython course,
3771 3799 so I wanted an updated release).
3772 3800
3773 3801 2001-12-27 Fernando Perez <fperez@colorado.edu>
3774 3802
3775 3803 * IPython/iplib.py (InteractiveShell.interact): Added the original
3776 3804 code from 'code.py' for this module in order to change the
3777 3805 handling of a KeyboardInterrupt. This was necessary b/c otherwise
3778 3806 the history cache would break when the user hit Ctrl-C, and
3779 3807 interact() offers no way to add any hooks to it.
3780 3808
3781 3809 2001-12-23 Fernando Perez <fperez@colorado.edu>
3782 3810
3783 3811 * setup.py: added check for 'MANIFEST' before trying to remove
3784 3812 it. Thanks to Sean Reifschneider.
3785 3813
3786 3814 2001-12-22 Fernando Perez <fperez@colorado.edu>
3787 3815
3788 3816 * Released 0.2.2.
3789 3817
3790 3818 * Finished (reasonably) writing the manual. Later will add the
3791 3819 python-standard navigation stylesheets, but for the time being
3792 3820 it's fairly complete. Distribution will include html and pdf
3793 3821 versions.
3794 3822
3795 3823 * Bugfix: '.' wasn't being added to sys.path. Thanks to Prabhu
3796 3824 (MayaVi author).
3797 3825
3798 3826 2001-12-21 Fernando Perez <fperez@colorado.edu>
3799 3827
3800 3828 * Released 0.2.1. Barring any nasty bugs, this is it as far as a
3801 3829 good public release, I think (with the manual and the distutils
3802 3830 installer). The manual can use some work, but that can go
3803 3831 slowly. Otherwise I think it's quite nice for end users. Next
3804 3832 summer, rewrite the guts of it...
3805 3833
3806 3834 * Changed format of ipythonrc files to use whitespace as the
3807 3835 separator instead of an explicit '='. Cleaner.
3808 3836
3809 3837 2001-12-20 Fernando Perez <fperez@colorado.edu>
3810 3838
3811 3839 * Started a manual in LyX. For now it's just a quick merge of the
3812 3840 various internal docstrings and READMEs. Later it may grow into a
3813 3841 nice, full-blown manual.
3814 3842
3815 3843 * Set up a distutils based installer. Installation should now be
3816 3844 trivially simple for end-users.
3817 3845
3818 3846 2001-12-11 Fernando Perez <fperez@colorado.edu>
3819 3847
3820 3848 * Released 0.2.0. First public release, announced it at
3821 3849 comp.lang.python. From now on, just bugfixes...
3822 3850
3823 3851 * Went through all the files, set copyright/license notices and
3824 3852 cleaned up things. Ready for release.
3825 3853
3826 3854 2001-12-10 Fernando Perez <fperez@colorado.edu>
3827 3855
3828 3856 * Changed the first-time installer not to use tarfiles. It's more
3829 3857 robust now and less unix-dependent. Also makes it easier for
3830 3858 people to later upgrade versions.
3831 3859
3832 3860 * Changed @exit to @abort to reflect the fact that it's pretty
3833 3861 brutal (a sys.exit()). The difference between @abort and Ctrl-D
3834 3862 becomes significant only when IPyhton is embedded: in that case,
3835 3863 C-D closes IPython only, but @abort kills the enclosing program
3836 3864 too (unless it had called IPython inside a try catching
3837 3865 SystemExit).
3838 3866
3839 3867 * Created Shell module which exposes the actuall IPython Shell
3840 3868 classes, currently the normal and the embeddable one. This at
3841 3869 least offers a stable interface we won't need to change when
3842 3870 (later) the internals are rewritten. That rewrite will be confined
3843 3871 to iplib and ipmaker, but the Shell interface should remain as is.
3844 3872
3845 3873 * Added embed module which offers an embeddable IPShell object,
3846 3874 useful to fire up IPython *inside* a running program. Great for
3847 3875 debugging or dynamical data analysis.
3848 3876
3849 3877 2001-12-08 Fernando Perez <fperez@colorado.edu>
3850 3878
3851 3879 * Fixed small bug preventing seeing info from methods of defined
3852 3880 objects (incorrect namespace in _ofind()).
3853 3881
3854 3882 * Documentation cleanup. Moved the main usage docstrings to a
3855 3883 separate file, usage.py (cleaner to maintain, and hopefully in the
3856 3884 future some perlpod-like way of producing interactive, man and
3857 3885 html docs out of it will be found).
3858 3886
3859 3887 * Added @profile to see your profile at any time.
3860 3888
3861 3889 * Added @p as an alias for 'print'. It's especially convenient if
3862 3890 using automagic ('p x' prints x).
3863 3891
3864 3892 * Small cleanups and fixes after a pychecker run.
3865 3893
3866 3894 * Changed the @cd command to handle @cd - and @cd -<n> for
3867 3895 visiting any directory in _dh.
3868 3896
3869 3897 * Introduced _dh, a history of visited directories. @dhist prints
3870 3898 it out with numbers.
3871 3899
3872 3900 2001-12-07 Fernando Perez <fperez@colorado.edu>
3873 3901
3874 3902 * Released 0.1.22
3875 3903
3876 3904 * Made initialization a bit more robust against invalid color
3877 3905 options in user input (exit, not traceback-crash).
3878 3906
3879 3907 * Changed the bug crash reporter to write the report only in the
3880 3908 user's .ipython directory. That way IPython won't litter people's
3881 3909 hard disks with crash files all over the place. Also print on
3882 3910 screen the necessary mail command.
3883 3911
3884 3912 * With the new ultraTB, implemented LightBG color scheme for light
3885 3913 background terminals. A lot of people like white backgrounds, so I
3886 3914 guess we should at least give them something readable.
3887 3915
3888 3916 2001-12-06 Fernando Perez <fperez@colorado.edu>
3889 3917
3890 3918 * Modified the structure of ultraTB. Now there's a proper class
3891 3919 for tables of color schemes which allow adding schemes easily and
3892 3920 switching the active scheme without creating a new instance every
3893 3921 time (which was ridiculous). The syntax for creating new schemes
3894 3922 is also cleaner. I think ultraTB is finally done, with a clean
3895 3923 class structure. Names are also much cleaner (now there's proper
3896 3924 color tables, no need for every variable to also have 'color' in
3897 3925 its name).
3898 3926
3899 3927 * Broke down genutils into separate files. Now genutils only
3900 3928 contains utility functions, and classes have been moved to their
3901 3929 own files (they had enough independent functionality to warrant
3902 3930 it): ConfigLoader, OutputTrap, Struct.
3903 3931
3904 3932 2001-12-05 Fernando Perez <fperez@colorado.edu>
3905 3933
3906 3934 * IPython turns 21! Released version 0.1.21, as a candidate for
3907 3935 public consumption. If all goes well, release in a few days.
3908 3936
3909 3937 * Fixed path bug (files in Extensions/ directory wouldn't be found
3910 3938 unless IPython/ was explicitly in sys.path).
3911 3939
3912 3940 * Extended the FlexCompleter class as MagicCompleter to allow
3913 3941 completion of @-starting lines.
3914 3942
3915 3943 * Created __release__.py file as a central repository for release
3916 3944 info that other files can read from.
3917 3945
3918 3946 * Fixed small bug in logging: when logging was turned on in
3919 3947 mid-session, old lines with special meanings (!@?) were being
3920 3948 logged without the prepended comment, which is necessary since
3921 3949 they are not truly valid python syntax. This should make session
3922 3950 restores produce less errors.
3923 3951
3924 3952 * The namespace cleanup forced me to make a FlexCompleter class
3925 3953 which is nothing but a ripoff of rlcompleter, but with selectable
3926 3954 namespace (rlcompleter only works in __main__.__dict__). I'll try
3927 3955 to submit a note to the authors to see if this change can be
3928 3956 incorporated in future rlcompleter releases (Dec.6: done)
3929 3957
3930 3958 * More fixes to namespace handling. It was a mess! Now all
3931 3959 explicit references to __main__.__dict__ are gone (except when
3932 3960 really needed) and everything is handled through the namespace
3933 3961 dicts in the IPython instance. We seem to be getting somewhere
3934 3962 with this, finally...
3935 3963
3936 3964 * Small documentation updates.
3937 3965
3938 3966 * Created the Extensions directory under IPython (with an
3939 3967 __init__.py). Put the PhysicalQ stuff there. This directory should
3940 3968 be used for all special-purpose extensions.
3941 3969
3942 3970 * File renaming:
3943 3971 ipythonlib --> ipmaker
3944 3972 ipplib --> iplib
3945 3973 This makes a bit more sense in terms of what these files actually do.
3946 3974
3947 3975 * Moved all the classes and functions in ipythonlib to ipplib, so
3948 3976 now ipythonlib only has make_IPython(). This will ease up its
3949 3977 splitting in smaller functional chunks later.
3950 3978
3951 3979 * Cleaned up (done, I think) output of @whos. Better column
3952 3980 formatting, and now shows str(var) for as much as it can, which is
3953 3981 typically what one gets with a 'print var'.
3954 3982
3955 3983 2001-12-04 Fernando Perez <fperez@colorado.edu>
3956 3984
3957 3985 * Fixed namespace problems. Now builtin/IPyhton/user names get
3958 3986 properly reported in their namespace. Internal namespace handling
3959 3987 is finally getting decent (not perfect yet, but much better than
3960 3988 the ad-hoc mess we had).
3961 3989
3962 3990 * Removed -exit option. If people just want to run a python
3963 3991 script, that's what the normal interpreter is for. Less
3964 3992 unnecessary options, less chances for bugs.
3965 3993
3966 3994 * Added a crash handler which generates a complete post-mortem if
3967 3995 IPython crashes. This will help a lot in tracking bugs down the
3968 3996 road.
3969 3997
3970 3998 * Fixed nasty bug in auto-evaluation part of prefilter(). Names
3971 3999 which were boud to functions being reassigned would bypass the
3972 4000 logger, breaking the sync of _il with the prompt counter. This
3973 4001 would then crash IPython later when a new line was logged.
3974 4002
3975 4003 2001-12-02 Fernando Perez <fperez@colorado.edu>
3976 4004
3977 4005 * Made IPython a package. This means people don't have to clutter
3978 4006 their sys.path with yet another directory. Changed the INSTALL
3979 4007 file accordingly.
3980 4008
3981 4009 * Cleaned up the output of @who_ls, @who and @whos. @who_ls now
3982 4010 sorts its output (so @who shows it sorted) and @whos formats the
3983 4011 table according to the width of the first column. Nicer, easier to
3984 4012 read. Todo: write a generic table_format() which takes a list of
3985 4013 lists and prints it nicely formatted, with optional row/column
3986 4014 separators and proper padding and justification.
3987 4015
3988 4016 * Released 0.1.20
3989 4017
3990 4018 * Fixed bug in @log which would reverse the inputcache list (a
3991 4019 copy operation was missing).
3992 4020
3993 4021 * Code cleanup. @config was changed to use page(). Better, since
3994 4022 its output is always quite long.
3995 4023
3996 4024 * Itpl is back as a dependency. I was having too many problems
3997 4025 getting the parametric aliases to work reliably, and it's just
3998 4026 easier to code weird string operations with it than playing %()s
3999 4027 games. It's only ~6k, so I don't think it's too big a deal.
4000 4028
4001 4029 * Found (and fixed) a very nasty bug with history. !lines weren't
4002 4030 getting cached, and the out of sync caches would crash
4003 4031 IPython. Fixed it by reorganizing the prefilter/handlers/logger
4004 4032 division of labor a bit better. Bug fixed, cleaner structure.
4005 4033
4006 4034 2001-12-01 Fernando Perez <fperez@colorado.edu>
4007 4035
4008 4036 * Released 0.1.19
4009 4037
4010 4038 * Added option -n to @hist to prevent line number printing. Much
4011 4039 easier to copy/paste code this way.
4012 4040
4013 4041 * Created global _il to hold the input list. Allows easy
4014 4042 re-execution of blocks of code by slicing it (inspired by Janko's
4015 4043 comment on 'macros').
4016 4044
4017 4045 * Small fixes and doc updates.
4018 4046
4019 4047 * Rewrote @history function (was @h). Renamed it to @hist, @h is
4020 4048 much too fragile with automagic. Handles properly multi-line
4021 4049 statements and takes parameters.
4022 4050
4023 4051 2001-11-30 Fernando Perez <fperez@colorado.edu>
4024 4052
4025 4053 * Version 0.1.18 released.
4026 4054
4027 4055 * Fixed nasty namespace bug in initial module imports.
4028 4056
4029 4057 * Added copyright/license notes to all code files (except
4030 4058 DPyGetOpt). For the time being, LGPL. That could change.
4031 4059
4032 4060 * Rewrote a much nicer README, updated INSTALL, cleaned up
4033 4061 ipythonrc-* samples.
4034 4062
4035 4063 * Overall code/documentation cleanup. Basically ready for
4036 4064 release. Only remaining thing: licence decision (LGPL?).
4037 4065
4038 4066 * Converted load_config to a class, ConfigLoader. Now recursion
4039 4067 control is better organized. Doesn't include the same file twice.
4040 4068
4041 4069 2001-11-29 Fernando Perez <fperez@colorado.edu>
4042 4070
4043 4071 * Got input history working. Changed output history variables from
4044 4072 _p to _o so that _i is for input and _o for output. Just cleaner
4045 4073 convention.
4046 4074
4047 4075 * Implemented parametric aliases. This pretty much allows the
4048 4076 alias system to offer full-blown shell convenience, I think.
4049 4077
4050 4078 * Version 0.1.17 released, 0.1.18 opened.
4051 4079
4052 4080 * dot_ipython/ipythonrc (alias): added documentation.
4053 4081 (xcolor): Fixed small bug (xcolors -> xcolor)
4054 4082
4055 4083 * Changed the alias system. Now alias is a magic command to define
4056 4084 aliases just like the shell. Rationale: the builtin magics should
4057 4085 be there for things deeply connected to IPython's
4058 4086 architecture. And this is a much lighter system for what I think
4059 4087 is the really important feature: allowing users to define quickly
4060 4088 magics that will do shell things for them, so they can customize
4061 4089 IPython easily to match their work habits. If someone is really
4062 4090 desperate to have another name for a builtin alias, they can
4063 4091 always use __IP.magic_newname = __IP.magic_oldname. Hackish but
4064 4092 works.
4065 4093
4066 4094 2001-11-28 Fernando Perez <fperez@colorado.edu>
4067 4095
4068 4096 * Changed @file so that it opens the source file at the proper
4069 4097 line. Since it uses less, if your EDITOR environment is
4070 4098 configured, typing v will immediately open your editor of choice
4071 4099 right at the line where the object is defined. Not as quick as
4072 4100 having a direct @edit command, but for all intents and purposes it
4073 4101 works. And I don't have to worry about writing @edit to deal with
4074 4102 all the editors, less does that.
4075 4103
4076 4104 * Version 0.1.16 released, 0.1.17 opened.
4077 4105
4078 4106 * Fixed some nasty bugs in the page/page_dumb combo that could
4079 4107 crash IPython.
4080 4108
4081 4109 2001-11-27 Fernando Perez <fperez@colorado.edu>
4082 4110
4083 4111 * Version 0.1.15 released, 0.1.16 opened.
4084 4112
4085 4113 * Finally got ? and ?? to work for undefined things: now it's
4086 4114 possible to type {}.get? and get information about the get method
4087 4115 of dicts, or os.path? even if only os is defined (so technically
4088 4116 os.path isn't). Works at any level. For example, after import os,
4089 4117 os?, os.path?, os.path.abspath? all work. This is great, took some
4090 4118 work in _ofind.
4091 4119
4092 4120 * Fixed more bugs with logging. The sanest way to do it was to add
4093 4121 to @log a 'mode' parameter. Killed two in one shot (this mode
4094 4122 option was a request of Janko's). I think it's finally clean
4095 4123 (famous last words).
4096 4124
4097 4125 * Added a page_dumb() pager which does a decent job of paging on
4098 4126 screen, if better things (like less) aren't available. One less
4099 4127 unix dependency (someday maybe somebody will port this to
4100 4128 windows).
4101 4129
4102 4130 * Fixed problem in magic_log: would lock of logging out if log
4103 4131 creation failed (because it would still think it had succeeded).
4104 4132
4105 4133 * Improved the page() function using curses to auto-detect screen
4106 4134 size. Now it can make a much better decision on whether to print
4107 4135 or page a string. Option screen_length was modified: a value 0
4108 4136 means auto-detect, and that's the default now.
4109 4137
4110 4138 * Version 0.1.14 released, 0.1.15 opened. I think this is ready to
4111 4139 go out. I'll test it for a few days, then talk to Janko about
4112 4140 licences and announce it.
4113 4141
4114 4142 * Fixed the length of the auto-generated ---> prompt which appears
4115 4143 for auto-parens and auto-quotes. Getting this right isn't trivial,
4116 4144 with all the color escapes, different prompt types and optional
4117 4145 separators. But it seems to be working in all the combinations.
4118 4146
4119 4147 2001-11-26 Fernando Perez <fperez@colorado.edu>
4120 4148
4121 4149 * Wrote a regexp filter to get option types from the option names
4122 4150 string. This eliminates the need to manually keep two duplicate
4123 4151 lists.
4124 4152
4125 4153 * Removed the unneeded check_option_names. Now options are handled
4126 4154 in a much saner manner and it's easy to visually check that things
4127 4155 are ok.
4128 4156
4129 4157 * Updated version numbers on all files I modified to carry a
4130 4158 notice so Janko and Nathan have clear version markers.
4131 4159
4132 4160 * Updated docstring for ultraTB with my changes. I should send
4133 4161 this to Nathan.
4134 4162
4135 4163 * Lots of small fixes. Ran everything through pychecker again.
4136 4164
4137 4165 * Made loading of deep_reload an cmd line option. If it's not too
4138 4166 kosher, now people can just disable it. With -nodeep_reload it's
4139 4167 still available as dreload(), it just won't overwrite reload().
4140 4168
4141 4169 * Moved many options to the no| form (-opt and -noopt
4142 4170 accepted). Cleaner.
4143 4171
4144 4172 * Changed magic_log so that if called with no parameters, it uses
4145 4173 'rotate' mode. That way auto-generated logs aren't automatically
4146 4174 over-written. For normal logs, now a backup is made if it exists
4147 4175 (only 1 level of backups). A new 'backup' mode was added to the
4148 4176 Logger class to support this. This was a request by Janko.
4149 4177
4150 4178 * Added @logoff/@logon to stop/restart an active log.
4151 4179
4152 4180 * Fixed a lot of bugs in log saving/replay. It was pretty
4153 4181 broken. Now special lines (!@,/) appear properly in the command
4154 4182 history after a log replay.
4155 4183
4156 4184 * Tried and failed to implement full session saving via pickle. My
4157 4185 idea was to pickle __main__.__dict__, but modules can't be
4158 4186 pickled. This would be a better alternative to replaying logs, but
4159 4187 seems quite tricky to get to work. Changed -session to be called
4160 4188 -logplay, which more accurately reflects what it does. And if we
4161 4189 ever get real session saving working, -session is now available.
4162 4190
4163 4191 * Implemented color schemes for prompts also. As for tracebacks,
4164 4192 currently only NoColor and Linux are supported. But now the
4165 4193 infrastructure is in place, based on a generic ColorScheme
4166 4194 class. So writing and activating new schemes both for the prompts
4167 4195 and the tracebacks should be straightforward.
4168 4196
4169 4197 * Version 0.1.13 released, 0.1.14 opened.
4170 4198
4171 4199 * Changed handling of options for output cache. Now counter is
4172 4200 hardwired starting at 1 and one specifies the maximum number of
4173 4201 entries *in the outcache* (not the max prompt counter). This is
4174 4202 much better, since many statements won't increase the cache
4175 4203 count. It also eliminated some confusing options, now there's only
4176 4204 one: cache_size.
4177 4205
4178 4206 * Added 'alias' magic function and magic_alias option in the
4179 4207 ipythonrc file. Now the user can easily define whatever names he
4180 4208 wants for the magic functions without having to play weird
4181 4209 namespace games. This gives IPython a real shell-like feel.
4182 4210
4183 4211 * Fixed doc/?/?? for magics. Now all work, in all forms (explicit
4184 4212 @ or not).
4185 4213
4186 4214 This was one of the last remaining 'visible' bugs (that I know
4187 4215 of). I think if I can clean up the session loading so it works
4188 4216 100% I'll release a 0.2.0 version on c.p.l (talk to Janko first
4189 4217 about licensing).
4190 4218
4191 4219 2001-11-25 Fernando Perez <fperez@colorado.edu>
4192 4220
4193 4221 * Rewrote somewhat oinfo (?/??). Nicer, now uses page() and
4194 4222 there's a cleaner distinction between what ? and ?? show.
4195 4223
4196 4224 * Added screen_length option. Now the user can define his own
4197 4225 screen size for page() operations.
4198 4226
4199 4227 * Implemented magic shell-like functions with automatic code
4200 4228 generation. Now adding another function is just a matter of adding
4201 4229 an entry to a dict, and the function is dynamically generated at
4202 4230 run-time. Python has some really cool features!
4203 4231
4204 4232 * Renamed many options to cleanup conventions a little. Now all
4205 4233 are lowercase, and only underscores where needed. Also in the code
4206 4234 option name tables are clearer.
4207 4235
4208 4236 * Changed prompts a little. Now input is 'In [n]:' instead of
4209 4237 'In[n]:='. This allows it the numbers to be aligned with the
4210 4238 Out[n] numbers, and removes usage of ':=' which doesn't exist in
4211 4239 Python (it was a Mathematica thing). The '...' continuation prompt
4212 4240 was also changed a little to align better.
4213 4241
4214 4242 * Fixed bug when flushing output cache. Not all _p<n> variables
4215 4243 exist, so their deletion needs to be wrapped in a try:
4216 4244
4217 4245 * Figured out how to properly use inspect.formatargspec() (it
4218 4246 requires the args preceded by *). So I removed all the code from
4219 4247 _get_pdef in Magic, which was just replicating that.
4220 4248
4221 4249 * Added test to prefilter to allow redefining magic function names
4222 4250 as variables. This is ok, since the @ form is always available,
4223 4251 but whe should allow the user to define a variable called 'ls' if
4224 4252 he needs it.
4225 4253
4226 4254 * Moved the ToDo information from README into a separate ToDo.
4227 4255
4228 4256 * General code cleanup and small bugfixes. I think it's close to a
4229 4257 state where it can be released, obviously with a big 'beta'
4230 4258 warning on it.
4231 4259
4232 4260 * Got the magic function split to work. Now all magics are defined
4233 4261 in a separate class. It just organizes things a bit, and now
4234 4262 Xemacs behaves nicer (it was choking on InteractiveShell b/c it
4235 4263 was too long).
4236 4264
4237 4265 * Changed @clear to @reset to avoid potential confusions with
4238 4266 the shell command clear. Also renamed @cl to @clear, which does
4239 4267 exactly what people expect it to from their shell experience.
4240 4268
4241 4269 Added a check to the @reset command (since it's so
4242 4270 destructive, it's probably a good idea to ask for confirmation).
4243 4271 But now reset only works for full namespace resetting. Since the
4244 4272 del keyword is already there for deleting a few specific
4245 4273 variables, I don't see the point of having a redundant magic
4246 4274 function for the same task.
4247 4275
4248 4276 2001-11-24 Fernando Perez <fperez@colorado.edu>
4249 4277
4250 4278 * Updated the builtin docs (esp. the ? ones).
4251 4279
4252 4280 * Ran all the code through pychecker. Not terribly impressed with
4253 4281 it: lots of spurious warnings and didn't really find anything of
4254 4282 substance (just a few modules being imported and not used).
4255 4283
4256 4284 * Implemented the new ultraTB functionality into IPython. New
4257 4285 option: xcolors. This chooses color scheme. xmode now only selects
4258 4286 between Plain and Verbose. Better orthogonality.
4259 4287
4260 4288 * Large rewrite of ultraTB. Much cleaner now, with a separation of
4261 4289 mode and color scheme for the exception handlers. Now it's
4262 4290 possible to have the verbose traceback with no coloring.
4263 4291
4264 4292 2001-11-23 Fernando Perez <fperez@colorado.edu>
4265 4293
4266 4294 * Version 0.1.12 released, 0.1.13 opened.
4267 4295
4268 4296 * Removed option to set auto-quote and auto-paren escapes by
4269 4297 user. The chances of breaking valid syntax are just too high. If
4270 4298 someone *really* wants, they can always dig into the code.
4271 4299
4272 4300 * Made prompt separators configurable.
4273 4301
4274 4302 2001-11-22 Fernando Perez <fperez@colorado.edu>
4275 4303
4276 4304 * Small bugfixes in many places.
4277 4305
4278 4306 * Removed the MyCompleter class from ipplib. It seemed redundant
4279 4307 with the C-p,C-n history search functionality. Less code to
4280 4308 maintain.
4281 4309
4282 4310 * Moved all the original ipython.py code into ipythonlib.py. Right
4283 4311 now it's just one big dump into a function called make_IPython, so
4284 4312 no real modularity has been gained. But at least it makes the
4285 4313 wrapper script tiny, and since ipythonlib is a module, it gets
4286 4314 compiled and startup is much faster.
4287 4315
4288 4316 This is a reasobably 'deep' change, so we should test it for a
4289 4317 while without messing too much more with the code.
4290 4318
4291 4319 2001-11-21 Fernando Perez <fperez@colorado.edu>
4292 4320
4293 4321 * Version 0.1.11 released, 0.1.12 opened for further work.
4294 4322
4295 4323 * Removed dependency on Itpl. It was only needed in one place. It
4296 4324 would be nice if this became part of python, though. It makes life
4297 4325 *a lot* easier in some cases.
4298 4326
4299 4327 * Simplified the prefilter code a bit. Now all handlers are
4300 4328 expected to explicitly return a value (at least a blank string).
4301 4329
4302 4330 * Heavy edits in ipplib. Removed the help system altogether. Now
4303 4331 obj?/?? is used for inspecting objects, a magic @doc prints
4304 4332 docstrings, and full-blown Python help is accessed via the 'help'
4305 4333 keyword. This cleans up a lot of code (less to maintain) and does
4306 4334 the job. Since 'help' is now a standard Python component, might as
4307 4335 well use it and remove duplicate functionality.
4308 4336
4309 4337 Also removed the option to use ipplib as a standalone program. By
4310 4338 now it's too dependent on other parts of IPython to function alone.
4311 4339
4312 4340 * Fixed bug in genutils.pager. It would crash if the pager was
4313 4341 exited immediately after opening (broken pipe).
4314 4342
4315 4343 * Trimmed down the VerboseTB reporting a little. The header is
4316 4344 much shorter now and the repeated exception arguments at the end
4317 4345 have been removed. For interactive use the old header seemed a bit
4318 4346 excessive.
4319 4347
4320 4348 * Fixed small bug in output of @whos for variables with multi-word
4321 4349 types (only first word was displayed).
4322 4350
4323 4351 2001-11-17 Fernando Perez <fperez@colorado.edu>
4324 4352
4325 4353 * Version 0.1.10 released, 0.1.11 opened for further work.
4326 4354
4327 4355 * Modified dirs and friends. dirs now *returns* the stack (not
4328 4356 prints), so one can manipulate it as a variable. Convenient to
4329 4357 travel along many directories.
4330 4358
4331 4359 * Fixed bug in magic_pdef: would only work with functions with
4332 4360 arguments with default values.
4333 4361
4334 4362 2001-11-14 Fernando Perez <fperez@colorado.edu>
4335 4363
4336 4364 * Added the PhysicsInput stuff to dot_ipython so it ships as an
4337 4365 example with IPython. Various other minor fixes and cleanups.
4338 4366
4339 4367 * Version 0.1.9 released, 0.1.10 opened for further work.
4340 4368
4341 4369 * Added sys.path to the list of directories searched in the
4342 4370 execfile= option. It used to be the current directory and the
4343 4371 user's IPYTHONDIR only.
4344 4372
4345 4373 2001-11-13 Fernando Perez <fperez@colorado.edu>
4346 4374
4347 4375 * Reinstated the raw_input/prefilter separation that Janko had
4348 4376 initially. This gives a more convenient setup for extending the
4349 4377 pre-processor from the outside: raw_input always gets a string,
4350 4378 and prefilter has to process it. We can then redefine prefilter
4351 4379 from the outside and implement extensions for special
4352 4380 purposes.
4353 4381
4354 4382 Today I got one for inputting PhysicalQuantity objects
4355 4383 (from Scientific) without needing any function calls at
4356 4384 all. Extremely convenient, and it's all done as a user-level
4357 4385 extension (no IPython code was touched). Now instead of:
4358 4386 a = PhysicalQuantity(4.2,'m/s**2')
4359 4387 one can simply say
4360 4388 a = 4.2 m/s**2
4361 4389 or even
4362 4390 a = 4.2 m/s^2
4363 4391
4364 4392 I use this, but it's also a proof of concept: IPython really is
4365 4393 fully user-extensible, even at the level of the parsing of the
4366 4394 command line. It's not trivial, but it's perfectly doable.
4367 4395
4368 4396 * Added 'add_flip' method to inclusion conflict resolver. Fixes
4369 4397 the problem of modules being loaded in the inverse order in which
4370 4398 they were defined in
4371 4399
4372 4400 * Version 0.1.8 released, 0.1.9 opened for further work.
4373 4401
4374 4402 * Added magics pdef, source and file. They respectively show the
4375 4403 definition line ('prototype' in C), source code and full python
4376 4404 file for any callable object. The object inspector oinfo uses
4377 4405 these to show the same information.
4378 4406
4379 4407 * Version 0.1.7 released, 0.1.8 opened for further work.
4380 4408
4381 4409 * Separated all the magic functions into a class called Magic. The
4382 4410 InteractiveShell class was becoming too big for Xemacs to handle
4383 4411 (de-indenting a line would lock it up for 10 seconds while it
4384 4412 backtracked on the whole class!)
4385 4413
4386 4414 FIXME: didn't work. It can be done, but right now namespaces are
4387 4415 all messed up. Do it later (reverted it for now, so at least
4388 4416 everything works as before).
4389 4417
4390 4418 * Got the object introspection system (magic_oinfo) working! I
4391 4419 think this is pretty much ready for release to Janko, so he can
4392 4420 test it for a while and then announce it. Pretty much 100% of what
4393 4421 I wanted for the 'phase 1' release is ready. Happy, tired.
4394 4422
4395 4423 2001-11-12 Fernando Perez <fperez@colorado.edu>
4396 4424
4397 4425 * Version 0.1.6 released, 0.1.7 opened for further work.
4398 4426
4399 4427 * Fixed bug in printing: it used to test for truth before
4400 4428 printing, so 0 wouldn't print. Now checks for None.
4401 4429
4402 4430 * Fixed bug where auto-execs increase the prompt counter by 2 (b/c
4403 4431 they have to call len(str(sys.ps1)) ). But the fix is ugly, it
4404 4432 reaches by hand into the outputcache. Think of a better way to do
4405 4433 this later.
4406 4434
4407 4435 * Various small fixes thanks to Nathan's comments.
4408 4436
4409 4437 * Changed magic_pprint to magic_Pprint. This way it doesn't
4410 4438 collide with pprint() and the name is consistent with the command
4411 4439 line option.
4412 4440
4413 4441 * Changed prompt counter behavior to be fully like
4414 4442 Mathematica's. That is, even input that doesn't return a result
4415 4443 raises the prompt counter. The old behavior was kind of confusing
4416 4444 (getting the same prompt number several times if the operation
4417 4445 didn't return a result).
4418 4446
4419 4447 * Fixed Nathan's last name in a couple of places (Gray, not Graham).
4420 4448
4421 4449 * Fixed -Classic mode (wasn't working anymore).
4422 4450
4423 4451 * Added colored prompts using Nathan's new code. Colors are
4424 4452 currently hardwired, they can be user-configurable. For
4425 4453 developers, they can be chosen in file ipythonlib.py, at the
4426 4454 beginning of the CachedOutput class def.
4427 4455
4428 4456 2001-11-11 Fernando Perez <fperez@colorado.edu>
4429 4457
4430 4458 * Version 0.1.5 released, 0.1.6 opened for further work.
4431 4459
4432 4460 * Changed magic_env to *return* the environment as a dict (not to
4433 4461 print it). This way it prints, but it can also be processed.
4434 4462
4435 4463 * Added Verbose exception reporting to interactive
4436 4464 exceptions. Very nice, now even 1/0 at the prompt gives a verbose
4437 4465 traceback. Had to make some changes to the ultraTB file. This is
4438 4466 probably the last 'big' thing in my mental todo list. This ties
4439 4467 in with the next entry:
4440 4468
4441 4469 * Changed -Xi and -Xf to a single -xmode option. Now all the user
4442 4470 has to specify is Plain, Color or Verbose for all exception
4443 4471 handling.
4444 4472
4445 4473 * Removed ShellServices option. All this can really be done via
4446 4474 the magic system. It's easier to extend, cleaner and has automatic
4447 4475 namespace protection and documentation.
4448 4476
4449 4477 2001-11-09 Fernando Perez <fperez@colorado.edu>
4450 4478
4451 4479 * Fixed bug in output cache flushing (missing parameter to
4452 4480 __init__). Other small bugs fixed (found using pychecker).
4453 4481
4454 4482 * Version 0.1.4 opened for bugfixing.
4455 4483
4456 4484 2001-11-07 Fernando Perez <fperez@colorado.edu>
4457 4485
4458 4486 * Version 0.1.3 released, mainly because of the raw_input bug.
4459 4487
4460 4488 * Fixed NASTY bug in raw_input: input line wasn't properly parsed
4461 4489 and when testing for whether things were callable, a call could
4462 4490 actually be made to certain functions. They would get called again
4463 4491 once 'really' executed, with a resulting double call. A disaster
4464 4492 in many cases (list.reverse() would never work!).
4465 4493
4466 4494 * Removed prefilter() function, moved its code to raw_input (which
4467 4495 after all was just a near-empty caller for prefilter). This saves
4468 4496 a function call on every prompt, and simplifies the class a tiny bit.
4469 4497
4470 4498 * Fix _ip to __ip name in magic example file.
4471 4499
4472 4500 * Changed 'tar -x -f' to 'tar xvf' in auto-installer. This should
4473 4501 work with non-gnu versions of tar.
4474 4502
4475 4503 2001-11-06 Fernando Perez <fperez@colorado.edu>
4476 4504
4477 4505 * Version 0.1.2. Just to keep track of the recent changes.
4478 4506
4479 4507 * Fixed nasty bug in output prompt routine. It used to check 'if
4480 4508 arg != None...'. Problem is, this fails if arg implements a
4481 4509 special comparison (__cmp__) which disallows comparing to
4482 4510 None. Found it when trying to use the PhysicalQuantity module from
4483 4511 ScientificPython.
4484 4512
4485 4513 2001-11-05 Fernando Perez <fperez@colorado.edu>
4486 4514
4487 4515 * Also added dirs. Now the pushd/popd/dirs family functions
4488 4516 basically like the shell, with the added convenience of going home
4489 4517 when called with no args.
4490 4518
4491 4519 * pushd/popd slightly modified to mimic shell behavior more
4492 4520 closely.
4493 4521
4494 4522 * Added env,pushd,popd from ShellServices as magic functions. I
4495 4523 think the cleanest will be to port all desired functions from
4496 4524 ShellServices as magics and remove ShellServices altogether. This
4497 4525 will provide a single, clean way of adding functionality
4498 4526 (shell-type or otherwise) to IP.
4499 4527
4500 4528 2001-11-04 Fernando Perez <fperez@colorado.edu>
4501 4529
4502 4530 * Added .ipython/ directory to sys.path. This way users can keep
4503 4531 customizations there and access them via import.
4504 4532
4505 4533 2001-11-03 Fernando Perez <fperez@colorado.edu>
4506 4534
4507 4535 * Opened version 0.1.1 for new changes.
4508 4536
4509 4537 * Changed version number to 0.1.0: first 'public' release, sent to
4510 4538 Nathan and Janko.
4511 4539
4512 4540 * Lots of small fixes and tweaks.
4513 4541
4514 4542 * Minor changes to whos format. Now strings are shown, snipped if
4515 4543 too long.
4516 4544
4517 4545 * Changed ShellServices to work on __main__ so they show up in @who
4518 4546
4519 4547 * Help also works with ? at the end of a line:
4520 4548 ?sin and sin?
4521 4549 both produce the same effect. This is nice, as often I use the
4522 4550 tab-complete to find the name of a method, but I used to then have
4523 4551 to go to the beginning of the line to put a ? if I wanted more
4524 4552 info. Now I can just add the ? and hit return. Convenient.
4525 4553
4526 4554 2001-11-02 Fernando Perez <fperez@colorado.edu>
4527 4555
4528 4556 * Python version check (>=2.1) added.
4529 4557
4530 4558 * Added LazyPython documentation. At this point the docs are quite
4531 4559 a mess. A cleanup is in order.
4532 4560
4533 4561 * Auto-installer created. For some bizarre reason, the zipfiles
4534 4562 module isn't working on my system. So I made a tar version
4535 4563 (hopefully the command line options in various systems won't kill
4536 4564 me).
4537 4565
4538 4566 * Fixes to Struct in genutils. Now all dictionary-like methods are
4539 4567 protected (reasonably).
4540 4568
4541 4569 * Added pager function to genutils and changed ? to print usage
4542 4570 note through it (it was too long).
4543 4571
4544 4572 * Added the LazyPython functionality. Works great! I changed the
4545 4573 auto-quote escape to ';', it's on home row and next to '. But
4546 4574 both auto-quote and auto-paren (still /) escapes are command-line
4547 4575 parameters.
4548 4576
4549 4577
4550 4578 2001-11-01 Fernando Perez <fperez@colorado.edu>
4551 4579
4552 4580 * Version changed to 0.0.7. Fairly large change: configuration now
4553 4581 is all stored in a directory, by default .ipython. There, all
4554 4582 config files have normal looking names (not .names)
4555 4583
4556 4584 * Version 0.0.6 Released first to Lucas and Archie as a test
4557 4585 run. Since it's the first 'semi-public' release, change version to
4558 4586 > 0.0.6 for any changes now.
4559 4587
4560 4588 * Stuff I had put in the ipplib.py changelog:
4561 4589
4562 4590 Changes to InteractiveShell:
4563 4591
4564 4592 - Made the usage message a parameter.
4565 4593
4566 4594 - Require the name of the shell variable to be given. It's a bit
4567 4595 of a hack, but allows the name 'shell' not to be hardwire in the
4568 4596 magic (@) handler, which is problematic b/c it requires
4569 4597 polluting the global namespace with 'shell'. This in turn is
4570 4598 fragile: if a user redefines a variable called shell, things
4571 4599 break.
4572 4600
4573 4601 - magic @: all functions available through @ need to be defined
4574 4602 as magic_<name>, even though they can be called simply as
4575 4603 @<name>. This allows the special command @magic to gather
4576 4604 information automatically about all existing magic functions,
4577 4605 even if they are run-time user extensions, by parsing the shell
4578 4606 instance __dict__ looking for special magic_ names.
4579 4607
4580 4608 - mainloop: added *two* local namespace parameters. This allows
4581 4609 the class to differentiate between parameters which were there
4582 4610 before and after command line initialization was processed. This
4583 4611 way, later @who can show things loaded at startup by the
4584 4612 user. This trick was necessary to make session saving/reloading
4585 4613 really work: ideally after saving/exiting/reloading a session,
4586 4614 *everythin* should look the same, including the output of @who. I
4587 4615 was only able to make this work with this double namespace
4588 4616 trick.
4589 4617
4590 4618 - added a header to the logfile which allows (almost) full
4591 4619 session restoring.
4592 4620
4593 4621 - prepend lines beginning with @ or !, with a and log
4594 4622 them. Why? !lines: may be useful to know what you did @lines:
4595 4623 they may affect session state. So when restoring a session, at
4596 4624 least inform the user of their presence. I couldn't quite get
4597 4625 them to properly re-execute, but at least the user is warned.
4598 4626
4599 4627 * Started ChangeLog.
@@ -1,391 +1,390 b''
1 1 .\" Hey, EMACS: -*- nroff -*-
2 2 .\" First parameter, NAME, should be all caps
3 3 .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
4 4 .\" other parameters are allowed: see man(7), man(1)
5 5 .TH IPYTHON 1 "November 30, 2004"
6 6 .\" Please adjust this date whenever revising the manpage.
7 7 .\"
8 8 .\" Some roff macros, for reference:
9 9 .\" .nh disable hyphenation
10 10 .\" .hy enable hyphenation
11 11 .\" .ad l left justify
12 12 .\" .ad b justify to both left and right margins
13 13 .\" .nf disable filling
14 14 .\" .fi enable filling
15 15 .\" .br insert line break
16 16 .\" .sp <n> insert n+1 empty lines
17 17 .\" for manpage-specific macros, see man(7) and groff_man(7)
18 18 .\" .SH section heading
19 19 .\" .SS secondary section heading
20 20 .\"
21 21 .\"
22 22 .\" To preview this page as plain text: nroff -man ipython.1
23 23 .\"
24 24 .SH NAME
25 25 ipython \- An Enhanced Interactive Python
26 26 .SH SYNOPSIS
27 27 .B ipython
28 28 .RI [ options ] " files" ...
29 29 .SH DESCRIPTION
30 30 An interactive Python shell with automatic history (input and output),
31 31 dynamic object introspection, easier configuration, command
32 32 completion, access to the system shell, integration with numerical and
33 33 scientific computing tools, and more.
34 34 .SH SPECIAL THREADING OPTIONS
35 35 The following special options are ONLY valid at the beginning of the command
36 36 line, and not later. This is because they control the initialization of
37 37 ipython itself, before the normal option-handling mechanism is active.
38 38 .TP
39 39 .B \-gthread, \-qthread, \-wthread, \-pylab
40 40 Only ONE of these can be given, and it can only be given as the first option
41 41 passed to IPython (it will have no effect in any other position). They
42 42 provide threading support for the GTK, QT and WXWidgets toolkits, and for the
43 43 matplotlib library.
44 44 .br
45 45 .sp 1
46 46 With any of the first three options, IPython starts running a separate thread
47 47 for the graphical toolkit's operation, so that you can open and control
48 48 graphical elements from within an IPython command line, without blocking. All
49 49 three provide essentially the same functionality, respectively for GTK, QT and
50 50 WXWidgets (via their Python interfaces).
51 51 .br
52 52 .sp 1
53 53 If \-pylab is given, IPython loads special support for the matplotlib library
54 54 (http://matplotlib.sourceforge.net), allowing interactive usage of any of its
55 55 backends as defined in the user's .matplotlibrc file. It automatically
56 56 activates GTK, QT or WX threading for IPyhton if the choice of matplotlib
57 57 backend requires it. It also modifies the %run command to correctly execute
58 58 (without blocking) any matplotlib-based script which calls show() at the end.
59 59 .TP
60 60 .B \-tk
61 61 The \-g/q/wthread options, and \-pylab (if matplotlib is configured to use
62 62 GTK, QT or WX), will normally block Tk graphical interfaces. This means that
63 63 when GTK, QT or WX threading is active, any attempt to open a Tk GUI will
64 64 result in a dead window, and possibly cause the Python interpreter to crash.
65 65 An extra option, \-tk, is available to address this issue. It can ONLY be
66 66 given as a SECOND option after any of the above (\-gthread, \-qthread,
67 67 \-wthread or \-pylab).
68 68 .br
69 69 .sp 1
70 70 If \-tk is given, IPython will try to coordinate Tk threading with GTK, QT or
71 71 WX. This is however potentially unreliable, and you will have to test on your
72 72 platform and Python configuration to determine whether it works for you.
73 73 Debian users have reported success, apparently due to the fact that Debian
74 74 builds all of Tcl, Tk, Tkinter and Python with pthreads support. Under other
75 75 Linux environments (such as Fedora Core 2), this option has caused random
76 76 crashes and lockups of the Python interpreter. Under other operating systems
77 77 (Mac OSX and Windows), you'll need to try it to find out, since currently no
78 78 user reports are available.
79 79 .br
80 80 .sp 1
81 81 There is unfortunately no way for IPython to determine at runtime whether \-tk
82 82 will work reliably or not, so you will need to do some experiments before
83 83 relying on it for regular work.
84 84 .
85 85 .SS A WARNING ABOUT SIGNALS AND THREADS
86 86 When any of the thread systems (GTK, QT or WX) are active, either directly or
87 87 via \-pylab with a threaded backend, it is impossible to interrupt
88 88 long-running Python code via Ctrl\-C. IPython can not pass the
89 89 KeyboardInterrupt exception (or the underlying SIGINT) across threads, so any
90 90 long-running process started from IPython will run to completion, or will have
91 91 to be killed via an external (OS-based) mechanism.
92 92 .br
93 93 .sp 1
94 94 To the best of my knowledge, this limitation is imposed by the Python
95 95 interpreter itself, and it comes from the difficulty of writing portable
96 96 signal/threaded code. If any user is an expert on this topic and can suggest
97 97 a better solution, I would love to hear about it. In the IPython sources,
98 98 look at the Shell.py module, and in particular at the runcode() method.
99 99 .
100 100 .SH REGULAR OPTIONS
101 101 After the above threading options have been given, regular options can follow
102 102 in any order. All options can be abbreviated to their shortest non-ambiguous
103 103 form and are case-sensitive. One or two dashes can be used. Some options
104 104 have an alternate short form, indicated after a |.
105 105 .br
106 106 .sp 1
107 107 Most options can also be set from your ipythonrc configuration file.
108 108 See the provided examples for assistance. Options given on the
109 109 commandline override the values set in the ipythonrc file.
110 110 .br
111 111 .sp 1
112 112 All options with a [no] prepended can be specified in negated form
113 113 (\-nooption instead of \-option) to turn the feature off.
114 114 .TP
115 115 .B \-h, \-\-help
116 116 Show summary of options.
117 117 .TP
118 118 .B \-[no]autocall
119 119 Make IPython automatically call any callable object even if you didn't type
120 120 explicit parentheses. For example, 'str 43' becomes 'str(43)' automatically.
121 121 .TP
122 122 .B \-[no]autoindent
123 123 Turn automatic indentation on/off.
124 124 .TP
125 125 .B \-[no]automagic
126 126 Make magic commands automatic (without needing their first character
127 127 to be %). Type %magic at the IPython prompt for more information.
128 128 .TP
129 129 .B \-[no]autoedit_syntax
130 130 When a syntax error occurs after editing a file, automatically open the file
131 131 to the trouble causing line for convenient fixing.
132 132 .TP
133 133 .B \-[no]banner
134 134 Print the intial information banner (default on).
135 135 .TP
136 136 .B \-c <command>
137 137 Execute the given command string, and set sys.argv to ['c']. This is similar
138 138 to the \-c option in the normal Python interpreter.
139 139 .TP
140 140 .B \-cache_size|cs <n>
141 141 Size of the output cache (maximum number of entries to hold in
142 142 memory). The default is 1000, you can change it permanently in your
143 143 config file. Setting it to 0 completely disables the caching system,
144 144 and the minimum value accepted is 20 (if you provide a value less than
145 145 20, it is reset to 0 and a warning is issued). This limit is defined
146 146 because otherwise you'll spend more time re-flushing a too small cache
147 147 than working.
148 148 .TP
149 149 .B \-classic|cl
150 150 Gives IPython a similar feel to the classic Python prompt.
151 151 .TP
152 152 .B \-colors <scheme>
153 153 Color scheme for prompts and exception reporting. Currently
154 154 implemented: NoColor, Linux, and LightBG.
155 155 .TP
156 156 .B \-[no]color_info
157 157 IPython can display information about objects via a set of functions,
158 158 and optionally can use colors for this, syntax highlighting source
159 159 code and various other elements. However, because this information is
160 160 passed through a pager (like 'less') and many pagers get confused with
161 161 color codes, this option is off by default. You can test it and turn
162 162 it on permanently in your ipythonrc file if it works for you. As a
163 163 reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
164 164 that in RedHat 7.2 doesn't.
165 165 .br
166 166 .sp 1
167 167 Test it and turn it on permanently if it works with your system. The
168 168 magic function @color_info allows you to toggle this interactively for
169 169 testing.
170 170 .TP
171 171 .B \-[no]confirm_exit
172 172 Set to confirm when you try to exit IPython with an EOF (Control-D in
173 173 Unix, Control-Z/Enter in Windows). Note that using the magic functions
174 174 @Exit or @Quit you can force a direct exit, bypassing any
175 175 confirmation.
176 176 .TP
177 177 .B \-[no]debug
178 178 Show information about the loading process. Very useful to pin down
179 179 problems with your configuration files or to get details about session
180 180 restores.
181 181 .TP
182 182 .B \-[no]deep_reload
183 183 IPython can use the deep_reload module which reloads changes in
184 184 modules recursively (it replaces the reload() function, so you don't
185 185 need to change anything to use it). deep_reload() forces a full reload
186 186 of modules whose code may have changed, which the default reload()
187 187 function does not.
188 188 .br
189 189 .sp 1
190 190 When deep_reload is off, IPython will use the normal reload(), but
191 191 deep_reload will still be available as dreload(). This feature is off
192 192 by default [which means that you have both normal reload() and
193 193 dreload()].
194 194 .TP
195 195 .B \-editor <name>
196 196 Which editor to use with the @edit command. By default, IPython will
197 197 honor your EDITOR environment variable (if not set, vi is the Unix
198 198 default and notepad the Windows one). Since this editor is invoked on
199 199 the fly by IPython and is meant for editing small code snippets, you
200 200 may want to use a small, lightweight editor here (in case your default
201 201 EDITOR is something like Emacs).
202 202 .TP
203 203 .B \-ipythondir <name>
204 204 The name of your IPython configuration directory IPYTHONDIR. This can
205 205 also be specified through the environment variable IPYTHONDIR.
206 206 .TP
207 207 .B \-log|l
208 Generate a log file of all input. The file is named ipython.log in
209 your current directory (which prevents logs from multiple IPython
210 sessions from trampling each other). You can use this to later restore
211 a session by loading your logfile as a file to be executed with option
212 -logplay (see below).
208 Generate a log file of all input. The file is named ipython_log.py in your
209 current directory (which prevents logs from multiple IPython sessions from
210 trampling each other). You can use this to later restore a session by loading
211 your logfile as a file to be executed with option -logplay (see below).
213 212 .TP
214 213 .B \-logfile|lf
215 Specifu the name of your logfile.
214 Specify the name of your logfile.
216 215 .TP
217 216 .B \-logplay|lp
218 217 Replay a previous log. For restoring a session as close as possible to
219 218 the state you left it in, use this option (don't just run the
220 219 logfile). With \-logplay, IPython will try to reconstruct the previous
221 220 working environment in full, not just execute the commands in the
222 221 logfile.
223 222 .br
224 223 .sh 1
225 224 When a session is restored, logging is automatically turned on again
226 225 with the name of the logfile it was invoked with (it is read from the
227 226 log header). So once you've turned logging on for a session, you can
228 227 quit IPython and reload it as many times as you want and it will
229 228 continue to log its history and restore from the beginning every time.
230 229 .br
231 230 .sp 1
232 231 Caveats: there are limitations in this option. The history variables
233 232 _i*,_* and _dh don't get restored properly. In the future we will try
234 233 to implement full session saving by writing and retrieving a
235 234 'snapshot' of the memory state of IPython. But our first attempts
236 235 failed because of inherent limitations of Python's Pickle module, so
237 236 this may have to wait.
238 237 .TP
239 238 .B \-[no]messages
240 239 Print messages which IPython collects about its startup process
241 240 (default on).
242 241 .TP
243 242 .B \-[no]pdb
244 243 Automatically call the pdb debugger after every uncaught exception. If
245 244 you are used to debugging using pdb, this puts you automatically
246 245 inside of it after any call (either in IPython or in code called by
247 246 it) which triggers an exception which goes uncaught.
248 247 .TP
249 248 .B \-[no]pprint
250 249 IPython can optionally use the pprint (pretty printer) module for
251 250 displaying results. pprint tends to give a nicer display of nested
252 251 data structures. If you like it, you can turn it on permanently in
253 252 your config file (default off).
254 253 .TP
255 254 .B \-profile|p <name>
256 255 Assume that your config file is ipythonrc-<name> (looks in current dir
257 256 first, then in IPYTHONDIR). This is a quick way to keep and load
258 257 multiple config files for different tasks, especially if you use the
259 258 include option of config files. You can keep a basic
260 259 IPYTHONDIR/ipythonrc file and then have other 'profiles' which include
261 260 this one and load extra things for particular tasks. For example:
262 261 .br
263 262 .sp 1
264 263 1) $HOME/.ipython/ipythonrc : load basic things you always want.
265 264 .br
266 265 2) $HOME/.ipython/ipythonrc-math : load (1) and basic math-related
267 266 modules.
268 267 .br
269 268 3) $HOME/.ipython/ipythonrc-numeric : load (1) and Numeric and
270 269 plotting modules.
271 270 .br
272 271 .sp 1
273 272 Since it is possible to create an endless loop by having circular file
274 273 inclusions, IPython will stop if it reaches 15 recursive inclusions.
275 274 .TP
276 275 .B \-prompt_in1|pi1 <string>
277 276 Specify the string used for input prompts. Note that if you are using
278 277 numbered prompts, the number is represented with a '\\#' in the
279 278 string. Don't forget to quote strings with spaces embedded in
280 279 them. Default: 'In [\\#]:'.
281 280 .br
282 281 .sp 1
283 282 Most bash-like escapes can be used to customize IPython's prompts, as well as
284 283 a few additional ones which are IPython-specific. All valid prompt escapes
285 284 are described in detail in the Customization section of the IPython HTML/PDF
286 285 manual.
287 286 .TP
288 287 .B \-prompt_in2|pi2 <string>
289 288 Similar to the previous option, but used for the continuation prompts. The
290 289 special sequence '\\D' is similar to '\\#', but with all digits replaced dots
291 290 (so you can have your continuation prompt aligned with your input
292 291 prompt). Default: ' .\\D.:' (note three spaces at the start for alignment
293 292 with 'In [\\#]').
294 293 .TP
295 294 .B \-prompt_out|po <string>
296 295 String used for output prompts, also uses numbers like prompt_in1.
297 296 Default: 'Out[\\#]:'.
298 297 .TP
299 298 .B \-quick
300 299 Start in bare bones mode (no config file loaded).
301 300 .TP
302 301 .B \-rcfile <name>
303 302 Name of your IPython resource configuration file. normally IPython
304 303 loads ipythonrc (from current directory) or IPYTHONDIR/ipythonrc. If
305 304 the loading of your config file fails, IPython starts with a bare
306 305 bones configuration (no modules loaded at all).
307 306 .TP
308 307 .B \-[no]readline
309 308 Use the readline library, which is needed to support name completion
310 309 and command history, among other things. It is enabled by default, but
311 310 may cause problems for users of X/Emacs in Python comint or shell
312 311 buffers.
313 312 .br
314 313 .sp 1
315 314 Note that emacs 'eterm' buffers (opened with M-x term) support
316 315 IPython's readline and syntax coloring fine, only 'emacs' (M-x shell
317 316 and C-c !) buffers do not.
318 317 .TP
319 318 .B \-screen_length|sl <n>
320 319 Number of lines of your screen. This is used to control printing of
321 320 very long strings. Strings longer than this number of lines will be
322 321 sent through a pager instead of directly printed.
323 322 .br
324 323 .sp 1
325 324 The default value for this is 0, which means IPython will auto-detect
326 325 your screen size every time it needs to print certain potentially long
327 326 strings (this doesn't change the behavior of the 'print' keyword, it's
328 327 only triggered internally). If for some reason this isn't working well
329 328 (it needs curses support), specify it yourself. Otherwise don't change
330 329 the default.
331 330 .TP
332 331 .B \-separate_in|si <string>
333 332 Separator before input prompts. Default '\n'.
334 333 .TP
335 334 .B \-separate_out|so <string>
336 335 Separator before output prompts. Default: 0 (nothing).
337 336 .TP
338 337 .B \-separate_out2|so2 <string>
339 338 Separator after output prompts. Default: 0 (nothing).
340 339 .TP
341 340 .B \-nosep
342 341 Shorthand for '\-separate_in 0 \-separate_out 0 \-separate_out2 0'.
343 342 Simply removes all input/output separators.
344 343 .TP
345 344 .B \-upgrade
346 345 Allows you to upgrade your IPYTHONDIR configuration when you install a
347 346 new version of IPython. Since new versions may include new command
348 347 lines options or example files, this copies updated ipythonrc-type
349 348 files. However, it backs up (with a .old extension) all files which
350 349 it overwrites so that you can merge back any custimizations you might
351 350 have in your personal files.
352 351 .TP
353 352 .B \-Version
354 353 Print version information and exit.
355 354 .TP
356 355 .B \-xmode <modename>
357 356 Mode for exception reporting. The valid modes are Plain, Context, and
358 357 Verbose.
359 358 .br
360 359 .sp 1
361 360 \- Plain: similar to python's normal traceback printing.
362 361 .br
363 362 .sp 1
364 363 \- Context: prints 5 lines of context source code around each line in the
365 364 traceback.
366 365 .br
367 366 .sp 1
368 367 \- Verbose: similar to Context, but additionally prints the variables
369 368 currently visible where the exception happened (shortening their strings if
370 369 too long). This can potentially be very slow, if you happen to have a huge
371 370 data structure whose string representation is complex to compute. Your
372 371 computer may appear to freeze for a while with cpu usage at 100%. If this
373 372 occurs, you can cancel the traceback with Ctrl-C (maybe hitting it more than
374 373 once).
375 374 .
376 375 .SH EMBEDDING
377 376 It is possible to start an IPython instance inside your own Python
378 377 programs. In the documentation example files there are some
379 378 illustrations on how to do this.
380 379 .br
381 380 .sp 1
382 381 This feature allows you to evalutate dynamically the state of your
383 382 code, operate with your variables, analyze them, etc. Note however
384 383 that any changes you make to values while in the shell do NOT
385 384 propagate back to the running code, so it is safe to modify your
386 385 values because you won't break your code in bizarre ways by doing so.
387 386 .SH AUTHOR
388 387 IPython was written by Fernando Perez <fperez@colorado.edu>, based on earlier
389 388 code by Janko Hauser <jh@comunit.de> and Nathaniel Gray
390 389 <n8gray@caltech.edu>. This manual page was written by Jack Moffitt
391 390 <jack@xiph.org>, for the Debian project (but may be used by others).
@@ -1,9151 +1,9152 b''
1 1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 2 \lyxformat 221
3 3 \textclass article
4 4 \begin_preamble
5 5 %\usepackage{ae,aecompl}
6 6 \usepackage{color}
7 7
8 8 % A few colors to replace the defaults for certain link types
9 9 \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
10 10 \definecolor{darkorange}{rgb}{.71,0.21,0.01}
11 11 \definecolor{darkred}{rgb}{.52,0.08,0.01}
12 12 \definecolor{darkgreen}{rgb}{.12,.54,.11}
13 13
14 14 % Use and configure listings package for nicely formatted code
15 15 \usepackage{listings}
16 16 \lstset{
17 17 language=Python,
18 18 basicstyle=\small\ttfamily,
19 19 commentstyle=\ttfamily\color{blue},
20 20 stringstyle=\ttfamily\color{darkorange},
21 21 showstringspaces=false,
22 22 breaklines=true,
23 23 postbreak = \space\dots
24 24 }
25 25
26 26 \usepackage[%pdftex, % needed for pdflatex
27 27 breaklinks=true, % so long urls are correctly broken across lines
28 28 colorlinks=true,
29 29 urlcolor=blue,
30 30 linkcolor=darkred,
31 31 citecolor=darkgreen,
32 32 ]{hyperref}
33 33
34 34 \usepackage{html}
35 35
36 36 % This helps prevent overly long lines that stretch beyond the margins
37 37 \sloppy
38 38
39 39 % Define a \codelist command which either uses listings for latex, or
40 40 % plain verbatim for html (since latex2html doesn't understand the
41 41 % listings package).
42 42 \usepackage{verbatim}
43 43 \newcommand{\codelist}[1] {
44 44 \latex{\lstinputlisting{#1}}
45 45 \html{\verbatiminput{#1}}
46 46 }
47 47 \end_preamble
48 48 \language english
49 49 \inputencoding latin1
50 50 \fontscheme palatino
51 51 \graphics default
52 52 \paperfontsize 10
53 53 \spacing single
54 54 \papersize Default
55 55 \paperpackage a4
56 56 \use_geometry 1
57 57 \use_amsmath 0
58 58 \use_natbib 0
59 59 \use_numerical_citations 0
60 60 \paperorientation portrait
61 61 \leftmargin 1.1in
62 62 \topmargin 1in
63 63 \rightmargin 1.1in
64 64 \bottommargin 1in
65 65 \secnumdepth 3
66 66 \tocdepth 3
67 67 \paragraph_separation skip
68 68 \defskip medskip
69 69 \quotes_language english
70 70 \quotes_times 2
71 71 \papercolumns 1
72 72 \papersides 1
73 73 \paperpagestyle fancy
74 74
75 75 \layout Title
76 76
77 77 IPython
78 78 \newline
79 79
80 80 \size larger
81 81 An enhanced Interactive Python
82 82 \size large
83 83
84 84 \newline
85 85 User Manual, v.
86 86 __version__
87 87 \layout Author
88 88
89 89 Fernando P�rez
90 90 \layout Standard
91 91
92 92
93 93 \begin_inset ERT
94 94 status Collapsed
95 95
96 96 \layout Standard
97 97
98 98 \backslash
99 99 latex{
100 100 \end_inset
101 101
102 102
103 103 \begin_inset LatexCommand \tableofcontents{}
104 104
105 105 \end_inset
106 106
107 107
108 108 \begin_inset ERT
109 109 status Collapsed
110 110
111 111 \layout Standard
112 112 }
113 113 \end_inset
114 114
115 115
116 116 \layout Standard
117 117
118 118
119 119 \begin_inset ERT
120 120 status Open
121 121
122 122 \layout Standard
123 123
124 124 \backslash
125 125 html{
126 126 \backslash
127 127 bodytext{bgcolor=#ffffff}}
128 128 \end_inset
129 129
130 130
131 131 \layout Section
132 132 \pagebreak_top
133 133 Overview
134 134 \layout Standard
135 135
136 136 One of Python's most useful features is its interactive interpreter.
137 137 This system allows very fast testing of ideas without the overhead of creating
138 138 test files as is typical in most programming languages.
139 139 However, the interpreter supplied with the standard Python distribution
140 140 is somewhat limited for extended interactive use.
141 141 \layout Standard
142 142
143 143 IPython is a free software project (released under the BSD license) which
144 144 tries to:
145 145 \layout Enumerate
146 146
147 147 Provide an interactive shell superior to Python's default.
148 148 IPython has many features for object introspection, system shell access,
149 149 and its own special command system for adding functionality when working
150 150 interactively.
151 151 It tries to be a very efficient environment both for Python code development
152 152 and for exploration of problems using Python objects (in situations like
153 153 data analysis).
154 154 \layout Enumerate
155 155
156 156 Serve as an embeddable, ready to use interpreter for your own programs.
157 157 IPython can be started with a single call from inside another program,
158 158 providing access to the current namespace.
159 159 This can be very useful both for debugging purposes and for situations
160 160 where a blend of batch-processing and interactive exploration are needed.
161 161 \layout Enumerate
162 162
163 163 Offer a flexible framework which can be used as the base environment for
164 164 other systems with Python as the underlying language.
165 165 Specifically scientific environments like Mathematica, IDL and Matlab inspired
166 166 its design, but similar ideas can be useful in many fields.
167 167 \layout Subsection
168 168
169 169 Main features
170 170 \layout Itemize
171 171
172 172 Dynamic object introspection.
173 173 One can access docstrings, function definition prototypes, source code,
174 174 source files and other details of any object accessible to the interpreter
175 175 with a single keystroke (`
176 176 \family typewriter
177 177 ?
178 178 \family default
179 179 ').
180 180 \layout Itemize
181 181
182 182 Completion in the local namespace, by typing TAB at the prompt.
183 183 This works for keywords, methods, variables and files in the current directory.
184 184 This is supported via the readline library, and full access to configuring
185 185 readline's behavior is provided.
186 186 \layout Itemize
187 187
188 188 Numbered input/output prompts with command history (persistent across sessions
189 189 and tied to each profile), full searching in this history and caching of
190 190 all input and output.
191 191 \layout Itemize
192 192
193 193 User-extensible `magic' commands.
194 194 A set of commands prefixed with
195 195 \family typewriter
196 196 %
197 197 \family default
198 198 is available for controlling IPython itself and provides directory control,
199 199 namespace information and many aliases to common system shell commands.
200 200 \layout Itemize
201 201
202 202 Alias facility for defining your own system aliases.
203 203 \layout Itemize
204 204
205 205 Complete system shell access.
206 206 Lines starting with ! are passed directly to the system shell, and using
207 207 !! captures shell output into python variables for further use.
208 208 \layout Itemize
209 209
210 210 All calls to the system (via aliases or via !) have their standard output/error
211 211 automatically stored as strings, and also available as lists.
212 212 \layout Itemize
213 213
214 214 Background execution of Python commands in a separate thread.
215 215 IPython has an internal job manager called
216 216 \family typewriter
217 217 jobs
218 218 \family default
219 219 , and a conveninence backgrounding magic function called
220 220 \family typewriter
221 221 %bg
222 222 \family default
223 223 .
224 224 \layout Itemize
225 225
226 226 The ability to expand python variables when calling the system shell.
227 227 In a shell command, any python variable prefixed with
228 228 \family typewriter
229 229 $
230 230 \family default
231 231 is expanded.
232 232 A double
233 233 \family typewriter
234 234 $$
235 235 \family default
236 236 allows passing a literal
237 237 \family typewriter
238 238 $
239 239 \family default
240 240 to the shell (for access to shell and environment variables like
241 241 \family typewriter
242 242 $PATH
243 243 \family default
244 244 ).
245 245 \layout Itemize
246 246
247 247 Filesystem navigation, via a magic
248 248 \family typewriter
249 249 %cd
250 250 \family default
251 251 command, along with a persistent bookmark system (using
252 252 \family typewriter
253 253 %bookmark
254 254 \family default
255 255 ) for fast access to frequently visited directories.
256 256 \layout Itemize
257 257
258 258 Automatic indentation (optional) of code as you type (through the readline
259 259 library).
260 260 \layout Itemize
261 261
262 262 Macro system for quickly re-executing multiple lines of previous input with
263 263 a single name.
264 264 \layout Itemize
265 265
266 266 Session logging (you can then later use these logs as code in your programs).
267 267 \layout Itemize
268 268
269 269 Session restoring: logs can be replayed to restore a previous session to
270 270 the state where you left it.
271 271 \layout Itemize
272 272
273 273 Verbose and colored exception traceback printouts.
274 274 Easier to parse visually, and in verbose mode they produce a lot of useful
275 275 debugging information (basically a terminal version of the cgitb module).
276 276 \layout Itemize
277 277
278 278 Auto-parentheses: callable objects can be executed without parentheses:
279 279
280 280 \family typewriter
281 281 `sin 3'
282 282 \family default
283 283 is automatically converted to
284 284 \family typewriter
285 285 `sin(3)
286 286 \family default
287 287 '.
288 288 \layout Itemize
289 289
290 290 Auto-quoting: using `
291 291 \family typewriter
292 292 ,
293 293 \family default
294 294 ' or `
295 295 \family typewriter
296 296 ;
297 297 \family default
298 298 ' as the first character forces auto-quoting of the rest of the line:
299 299 \family typewriter
300 300 `,my_function a\SpecialChar ~
301 301 b'
302 302 \family default
303 303 becomes automatically
304 304 \family typewriter
305 305 `my_function("a","b")'
306 306 \family default
307 307 , while
308 308 \family typewriter
309 309 `;my_function a\SpecialChar ~
310 310 b'
311 311 \family default
312 312 becomes
313 313 \family typewriter
314 314 `my_function("a b")'
315 315 \family default
316 316 .
317 317 \layout Itemize
318 318
319 319 Extensible input syntax.
320 320 You can define filters that pre-process user input to simplify input in
321 321 special situations.
322 322 This allows for example pasting multi-line code fragments which start with
323 323
324 324 \family typewriter
325 325 `>>>'
326 326 \family default
327 327 or
328 328 \family typewriter
329 329 `...'
330 330 \family default
331 331 such as those from other python sessions or the standard Python documentation.
332 332 \layout Itemize
333 333
334 334 Flexible configuration system.
335 335 It uses a configuration file which allows permanent setting of all command-line
336 336 options, module loading, code and file execution.
337 337 The system allows recursive file inclusion, so you can have a base file
338 338 with defaults and layers which load other customizations for particular
339 339 projects.
340 340 \layout Itemize
341 341
342 342 Embeddable.
343 343 You can call IPython as a python shell inside your own python programs.
344 344 This can be used both for debugging code or for providing interactive abilities
345 345 to your programs with knowledge about the local namespaces (very useful
346 346 in debugging and data analysis situations).
347 347 \layout Itemize
348 348
349 349 Easy debugger access.
350 350 You can set IPython to call up an enhanced version of the Python debugger
351 351 (
352 352 \family typewriter
353 353 pdb
354 354 \family default
355 355 ) every time there is an uncaught exception.
356 356 This drops you inside the code which triggered the exception with all the
357 357 data live and it is possible to navigate the stack to rapidly isolate the
358 358 source of a bug.
359 359 The
360 360 \family typewriter
361 361 %run
362 362 \family default
363 363 magic command --with the
364 364 \family typewriter
365 365 -d
366 366 \family default
367 367 option-- can run any script under
368 368 \family typewriter
369 369 pdb
370 370 \family default
371 371 's control, automatically setting initial breakpoints for you.
372 372 This version of
373 373 \family typewriter
374 374 pdb
375 375 \family default
376 376 has IPython-specific improvements, including tab-completion and traceback
377 377 coloring support.
378 378 \layout Itemize
379 379
380 380 Profiler support.
381 381 You can run single statements (similar to
382 382 \family typewriter
383 383 profile.run()
384 384 \family default
385 385 ) or complete programs under the profiler's control.
386 386 While this is possible with the standard
387 387 \family typewriter
388 388 profile
389 389 \family default
390 390 module, IPython wraps this functionality with magic commands (see
391 391 \family typewriter
392 392 `%prun'
393 393 \family default
394 394 and
395 395 \family typewriter
396 396 `%run -p
397 397 \family default
398 398 ') convenient for rapid interactive work.
399 399 \layout Subsection
400 400
401 401 Portability and Python requirements
402 402 \layout Standard
403 403
404 404
405 405 \series bold
406 406 Python requirements:
407 407 \series default
408 408 IPython works with Python version 2.2 or newer.
409 409 It has been tested with Python 2.4 and no problems have been reported.
410 410 Support for Python 2.1 hasn't been recently tested, since I don't have access
411 411 to it on any of my systems.
412 412 But I suspect there may be some problems with Python 2.1, because some of
413 413 the newer code may use 2.2 features.
414 414 \layout Standard
415 415
416 416 IPython is developed under
417 417 \series bold
418 418 Linux
419 419 \series default
420 420 , but it should work in any reasonable Unix-type system (tested OK under
421 421 Solaris and the *BSD family, for which a port exists thanks to Dryice Liu).
422 422 \layout Standard
423 423
424 424
425 425 \series bold
426 426 Mac OS X
427 427 \series default
428 428 : it works, apparently without any problems (thanks to Jim Boyle at Lawrence
429 429 Livermore for the information).
430 430 Thanks to Andrea Riciputi, Fink support is available.
431 431 \layout Standard
432 432
433 433
434 434 \series bold
435 435 CygWin
436 436 \series default
437 437 : it works mostly OK, though some users have reported problems with prompt
438 438 coloring.
439 439 No satisfactory solution to this has been found so far, you may want to
440 440 disable colors permanently in the
441 441 \family typewriter
442 442 ipythonrc
443 443 \family default
444 444 configuration file if you experience problems.
445 445 If you have proper color support under cygwin, please post to the IPython
446 446 mailing list so this issue can be resolved for all users.
447 447 \layout Standard
448 448
449 449
450 450 \series bold
451 451 Windows
452 452 \series default
453 453 : it works well under Windows XP/2k, and I suspect NT should behave similarly.
454 454 Section\SpecialChar ~
455 455
456 456 \begin_inset LatexCommand \ref{sub:Under-Windows}
457 457
458 458 \end_inset
459 459
460 460 describes installation details for Windows, including some additional tools
461 461 needed on this platform.
462 462 \layout Standard
463 463
464 464 Windows 9x support is present, and has been reported to work fine (at least
465 465 on WinME).
466 466 \layout Standard
467 467
468 468 Please note, however, that I have very little access to and experience with
469 469 Windows development.
470 470 For this reason, Windows-specific bugs tend to linger far longer than I
471 471 would like, and often I just can't find a satisfactory solution.
472 472 If any Windows user wants to join in with development help, all hands are
473 473 always welcome.
474 474 \layout Subsection
475 475
476 476 Location
477 477 \layout Standard
478 478
479 479 IPython is generously hosted at
480 480 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
481 481
482 482 \end_inset
483 483
484 484 by the SciPy project.
485 485 This site offers downloads, subversion access, mailing lists and a bug
486 486 tracking system.
487 487 I am very grateful to Enthought (
488 488 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
489 489
490 490 \end_inset
491 491
492 492 ) and all of the SciPy team for their contribution.
493 493 \layout Section
494 494
495 495
496 496 \begin_inset LatexCommand \label{sec:install}
497 497
498 498 \end_inset
499 499
500 500 Installation
501 501 \layout Subsection
502 502
503 503 Instant instructions
504 504 \layout Standard
505 505
506 506 If you are of the impatient kind, under Linux/Unix simply untar/unzip the
507 507 download, then install with
508 508 \family typewriter
509 509 `python setup.py install'
510 510 \family default
511 511 .
512 512 Under Windows, double-click on the provided
513 513 \family typewriter
514 514 .exe
515 515 \family default
516 516 binary installer.
517 517 \layout Standard
518 518
519 519 Then, take a look at Sections
520 520 \begin_inset LatexCommand \ref{sec:good_config}
521 521
522 522 \end_inset
523 523
524 524 for configuring things optimally and
525 525 \begin_inset LatexCommand \ref{sec:quick_tips}
526 526
527 527 \end_inset
528 528
529 529 for quick tips on efficient use of IPython.
530 530 You can later refer to the rest of the manual for all the gory details.
531 531 \layout Standard
532 532
533 533 See the notes in sec.
534 534
535 535 \begin_inset LatexCommand \ref{sec:upgrade}
536 536
537 537 \end_inset
538 538
539 539 for upgrading IPython versions.
540 540 \layout Subsection
541 541
542 542 Detailed Unix instructions (Linux, Mac OS X, etc.)
543 543 \layout Standard
544 544
545 545 For RPM based systems, simply install the supplied package in the usual
546 546 manner.
547 547 If you download the tar archive, the process is:
548 548 \layout Enumerate
549 549
550 550 Unzip/untar the
551 551 \family typewriter
552 552 ipython-XXX.tar.gz
553 553 \family default
554 554 file wherever you want (
555 555 \family typewriter
556 556 XXX
557 557 \family default
558 558 is the version number).
559 559 It will make a directory called
560 560 \family typewriter
561 561 ipython-XXX.
562 562
563 563 \family default
564 564 Change into that directory where you will find the files
565 565 \family typewriter
566 566 README
567 567 \family default
568 568 and
569 569 \family typewriter
570 570 setup.py
571 571 \family default
572 572 .
573 573
574 574 \family typewriter
575 575 O
576 576 \family default
577 577 nce you've completed the installation, you can safely remove this directory.
578 578
579 579 \layout Enumerate
580 580
581 581 If you are installing over a previous installation of version 0.2.0 or earlier,
582 582 first remove your
583 583 \family typewriter
584 584 $HOME/.ipython
585 585 \family default
586 586 directory, since the configuration file format has changed somewhat (the
587 587 '=' were removed from all option specifications).
588 588 Or you can call ipython with the
589 589 \family typewriter
590 590 -upgrade
591 591 \family default
592 592 option and it will do this automatically for you.
593 593 \layout Enumerate
594 594
595 595 IPython uses distutils, so you can install it by simply typing at the system
596 596 prompt (don't type the
597 597 \family typewriter
598 598 $
599 599 \family default
600 600 )
601 601 \newline
602 602
603 603 \family typewriter
604 604 $ python setup.py install
605 605 \family default
606 606
607 607 \newline
608 608 Note that this assumes you have root access to your machine.
609 609 If you don't have root access or don't want IPython to go in the default
610 610 python directories, you'll need to use the
611 611 \begin_inset ERT
612 612 status Collapsed
613 613
614 614 \layout Standard
615 615
616 616 \backslash
617 617 verb|--home|
618 618 \end_inset
619 619
620 620 option (or
621 621 \begin_inset ERT
622 622 status Collapsed
623 623
624 624 \layout Standard
625 625
626 626 \backslash
627 627 verb|--prefix|
628 628 \end_inset
629 629
630 630 ).
631 631 For example:
632 632 \newline
633 633
634 634 \begin_inset ERT
635 635 status Collapsed
636 636
637 637 \layout Standard
638 638
639 639 \backslash
640 640 verb|$ python setup.py install --home $HOME/local|
641 641 \end_inset
642 642
643 643
644 644 \newline
645 645 will install IPython into
646 646 \family typewriter
647 647 $HOME/local
648 648 \family default
649 649 and its subdirectories (creating them if necessary).
650 650 \newline
651 651 You can type
652 652 \newline
653 653
654 654 \begin_inset ERT
655 655 status Collapsed
656 656
657 657 \layout Standard
658 658
659 659 \backslash
660 660 verb|$ python setup.py --help|
661 661 \end_inset
662 662
663 663
664 664 \newline
665 665 for more details.
666 666 \newline
667 667 Note that if you change the default location for
668 668 \begin_inset ERT
669 669 status Collapsed
670 670
671 671 \layout Standard
672 672
673 673 \backslash
674 674 verb|--home|
675 675 \end_inset
676 676
677 677 at installation, IPython may end up installed at a location which is not
678 678 part of your
679 679 \family typewriter
680 680 $PYTHONPATH
681 681 \family default
682 682 environment variable.
683 683 In this case, you'll need to configure this variable to include the actual
684 684 directory where the
685 685 \family typewriter
686 686 IPython/
687 687 \family default
688 688 directory ended (typically the value you give to
689 689 \begin_inset ERT
690 690 status Collapsed
691 691
692 692 \layout Standard
693 693
694 694 \backslash
695 695 verb|--home|
696 696 \end_inset
697 697
698 698 plus
699 699 \family typewriter
700 700 /lib/python
701 701 \family default
702 702 ).
703 703 \layout Subsubsection
704 704
705 705 Mac OSX information
706 706 \layout Standard
707 707
708 708 Under OSX, there is a choice you need to make.
709 709 Apple ships its own build of Python, which lives in the core OSX filesystem
710 710 hierarchy.
711 711 You can also manually install a separate Python, either purely by hand
712 712 (typically in
713 713 \family typewriter
714 714 /usr/local
715 715 \family default
716 716 ) or by using Fink, which puts everything under
717 717 \family typewriter
718 718 /sw
719 719 \family default
720 720 .
721 721 Which route to follow is a matter of personal preference, as I've seen
722 722 users who favor each of the approaches.
723 723 Here I will simply list the known installation issues under OSX, along
724 724 with their solutions.
725 725 \layout Standard
726 726
727 727 This page:
728 728 \begin_inset LatexCommand \htmlurl{http://geosci.uchicago.edu/~tobis/pylab.html}
729 729
730 730 \end_inset
731 731
732 732 contains information on this topic, with additional details on how to make
733 733 IPython and matplotlib play nicely under OSX.
734 734 \layout Subsubsection*
735 735
736 736 GUI problems
737 737 \layout Standard
738 738
739 739 The following instructions apply to an install of IPython under OSX from
740 740 unpacking the
741 741 \family typewriter
742 742 .tar.gz
743 743 \family default
744 744 distribution and installing it for the default Python interpreter shipped
745 745 by Apple.
746 746 If you are using a fink install, fink will take care of these details for
747 747 you, by installing IPython against fink's Python.
748 748 \layout Standard
749 749
750 750 IPython offers various forms of support for interacting with graphical applicati
751 751 ons from the command line, from simple Tk apps (which are in principle always
752 752 supported by Python) to interactive control of WX, Qt and GTK apps.
753 753 Under OSX, however, this requires that ipython is installed by calling
754 754 the special
755 755 \family typewriter
756 756 pythonw
757 757 \family default
758 758 script at installation time, which takes care of coordinating things with
759 759 Apple's graphical environment.
760 760 \layout Standard
761 761
762 762 So when installing under OSX, it is best to use the following command:
763 763 \family typewriter
764 764
765 765 \newline
766 766
767 767 \family default
768 768
769 769 \begin_inset ERT
770 770 status Collapsed
771 771
772 772 \layout Standard
773 773
774 774 \backslash
775 775 verb| $ sudo pythonw setup.py install --install-scripts=/usr/local/bin|
776 776 \end_inset
777 777
778 778
779 779 \newline
780 780 or
781 781 \newline
782 782
783 783 \begin_inset ERT
784 784 status Open
785 785
786 786 \layout Standard
787 787
788 788 \backslash
789 789 verb| $ sudo pythonw setup.py install --install-scripts=/usr/bin|
790 790 \end_inset
791 791
792 792
793 793 \newline
794 794 depending on where you like to keep hand-installed executables.
795 795 \layout Standard
796 796
797 797 The resulting script will have an appropriate shebang line (the first line
798 798 in the script whic begins with
799 799 \family typewriter
800 800 #!...
801 801 \family default
802 802 ) such that the ipython interpreter can interact with the OS X GUI.
803 803 If the installed version does not work and has a shebang line that points
804 804 to, for example, just
805 805 \family typewriter
806 806 /usr/bin/python
807 807 \family default
808 808 , then you might have a stale, cached version in your
809 809 \family typewriter
810 810 build/scripts-<python-version>
811 811 \family default
812 812 directory.
813 813 Delete that directory and rerun the
814 814 \family typewriter
815 815 setup.py
816 816 \family default
817 817 .
818 818
819 819 \layout Standard
820 820
821 821 It is also a good idea to use the special flag
822 822 \begin_inset ERT
823 823 status Collapsed
824 824
825 825 \layout Standard
826 826
827 827 \backslash
828 828 verb|--install-scripts|
829 829 \end_inset
830 830
831 831 as indicated above, to ensure that the ipython scripts end up in a location
832 832 which is part of your
833 833 \family typewriter
834 834 $PATH
835 835 \family default
836 836 .
837 837 Otherwise Apple's Python will put the scripts in an internal directory
838 838 not available by default at the command line (if you use
839 839 \family typewriter
840 840 /usr/local/bin
841 841 \family default
842 842 , you need to make sure this is in your
843 843 \family typewriter
844 844 $PATH
845 845 \family default
846 846 , which may not be true by default).
847 847 \layout Subsubsection*
848 848
849 849 Readline problems
850 850 \layout Standard
851 851
852 852 By default, the Python version shipped by Apple does
853 853 \emph on
854 854 not
855 855 \emph default
856 856 include the readline library, so central to IPython's behavior.
857 857 If you install IPython against Apple's Python, you will not have arrow
858 858 keys, tab completion, etc.
859 859 For Mac OSX 10.3 (Panther), you can find a prebuilt readline library here:
860 860 \newline
861 861
862 862 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/readline-5.0-py2.3-macosx10.3.zip}
863 863
864 864 \end_inset
865 865
866 866
867 867 \layout Standard
868 868
869 869 If you are using OSX 10.4 (Tiger), after installing this package you need
870 870 to either:
871 871 \layout Enumerate
872 872
873 873 move
874 874 \family typewriter
875 875 readline.so
876 876 \family default
877 877 from
878 878 \family typewriter
879 879 /Library/Python/2.3
880 880 \family default
881 881 to
882 882 \family typewriter
883 883 /Library/Python/2.3/site-packages
884 884 \family default
885 885 , or
886 886 \layout Enumerate
887 887
888 888 install
889 889 \begin_inset LatexCommand \htmlurl{http://pythonmac.org/packages/TigerPython23Compat.pkg.zip}
890 890
891 891 \end_inset
892 892
893 893
894 894 \layout Standard
895 895
896 896 Users installing against Fink's Python or a properly hand-built one should
897 897 not have this problem.
898 898 \layout Subsubsection*
899 899
900 900 DarwinPorts
901 901 \layout Standard
902 902
903 903 I report here a message from an OSX user, who suggests an alternative means
904 904 of using IPython under this operating system with good results.
905 905 Please let me know of any updates that may be useful for this section.
906 906 His message is reproduced verbatim below:
907 907 \layout Quote
908 908
909 909 From: Markus Banfi
910 910 \family typewriter
911 911 <markus.banfi-AT-mospheira.net>
912 912 \layout Quote
913 913
914 914 As a MacOS X (10.4.2) user I prefer to install software using DawinPorts instead
915 915 of Fink.
916 916 I had no problems installing ipython with DarwinPorts.
917 917 It's just:
918 918 \layout Quote
919 919
920 920
921 921 \family typewriter
922 922 sudo port install py-ipython
923 923 \layout Quote
924 924
925 925 It automatically resolved all dependencies (python24, readline, py-readline).
926 926 So far I did not encounter any problems with the DarwinPorts port of ipython.
927 927
928 928 \layout Subsection
929 929
930 930
931 931 \begin_inset LatexCommand \label{sub:Under-Windows}
932 932
933 933 \end_inset
934 934
935 935 Windows instructions
936 936 \layout Standard
937 937
938 938 Some of IPython's very useful features are:
939 939 \layout Itemize
940 940
941 941 Integrated readline support (Tab-based file, object and attribute completion,
942 942 input history across sessions, editable command line, etc.)
943 943 \layout Itemize
944 944
945 945 Coloring of prompts, code and tracebacks.
946 946 \layout Standard
947 947
948 948 These, by default, are only available under Unix-like operating systems.
949 949 However, thanks to Gary Bishop's work, Windows XP/2k users can also benefit
950 950 from them.
951 951 His readline library implements both GNU readline functionality and color
952 952 support, so that IPython under Windows XP/2k can be as friendly and powerful
953 953 as under Unix-like environments.
954 954 \layout Standard
955 955
956 956 The
957 957 \family typewriter
958 958 readline
959 959 \family default
960 960 extension needs two other libraries to work, so in all you need:
961 961 \layout Enumerate
962 962
963 963
964 964 \family typewriter
965 965 PyWin32
966 966 \family default
967 967 from
968 968 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/mhammond}
969 969
970 970 \end_inset
971 971
972 972 .
973 973 \layout Enumerate
974 974
975 975
976 976 \family typewriter
977 977 CTypes
978 978 \family default
979 979 from
980 980 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/theller/ctypes}
981 981
982 982 \end_inset
983 983
984 984 (you
985 985 \emph on
986 986 must
987 987 \emph default
988 988 use version 0.9.1 or newer).
989 989 \layout Enumerate
990 990
991 991
992 992 \family typewriter
993 993 Readline
994 994 \family default
995 995 for Windows from
996 996 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/uncpythontools}
997 997
998 998 \end_inset
999 999
1000 1000 .
1001 1001 \layout Standard
1002 1002
1003 1003
1004 1004 \series bold
1005 1005 Warning about a broken readline-like library:
1006 1006 \series default
1007 1007 several users have reported problems stemming from using the pseudo-readline
1008 1008 library at
1009 1009 \begin_inset LatexCommand \htmlurl{http://newcenturycomputers.net/projects/readline.html}
1010 1010
1011 1011 \end_inset
1012 1012
1013 1013 .
1014 1014 This is a broken library which, while called readline, only implements
1015 1015 an incomplete subset of the readline API.
1016 1016 Since it is still called readline, it fools IPython's detection mechanisms
1017 1017 and causes unpredictable crashes later.
1018 1018 If you wish to use IPython under Windows, you must NOT use this library,
1019 1019 which for all purposes is (at least as of version 1.6) terminally broken.
1020 1020 \layout Subsubsection
1021 1021
1022 1022 Installation procedure
1023 1023 \layout Standard
1024 1024
1025 1025 Once you have the above installed, from the IPython download directory grab
1026 1026 the
1027 1027 \family typewriter
1028 1028 ipython-XXX.win32.exe
1029 1029 \family default
1030 1030 file, where
1031 1031 \family typewriter
1032 1032 XXX
1033 1033 \family default
1034 1034 represents the version number.
1035 1035 This is a regular windows executable installer, which you can simply double-cli
1036 1036 ck to install.
1037 1037 It will add an entry for IPython to your Start Menu, as well as registering
1038 1038 IPython in the Windows list of applications, so you can later uninstall
1039 1039 it from the Control Panel.
1040 1040
1041 1041 \layout Standard
1042 1042
1043 1043 IPython tries to install the configuration information in a directory named
1044 1044
1045 1045 \family typewriter
1046 1046 .ipython
1047 1047 \family default
1048 1048 (
1049 1049 \family typewriter
1050 1050 _ipython
1051 1051 \family default
1052 1052 under Windows) located in your `home' directory.
1053 1053 IPython sets this directory by looking for a
1054 1054 \family typewriter
1055 1055 HOME
1056 1056 \family default
1057 1057 environment variable; if such a variable does not exist, it uses
1058 1058 \family typewriter
1059 1059 HOMEDRIVE
1060 1060 \backslash
1061 1061 HOMEPATH
1062 1062 \family default
1063 1063 (these are always defined by Windows).
1064 1064 This typically gives something like
1065 1065 \family typewriter
1066 1066 C:
1067 1067 \backslash
1068 1068 Documents and Settings
1069 1069 \backslash
1070 1070 YourUserName
1071 1071 \family default
1072 1072 , but your local details may vary.
1073 1073 In this directory you will find all the files that configure IPython's
1074 1074 defaults, and you can put there your profiles and extensions.
1075 1075 This directory is automatically added by IPython to
1076 1076 \family typewriter
1077 1077 sys.path
1078 1078 \family default
1079 1079 , so anything you place there can be found by
1080 1080 \family typewriter
1081 1081 import
1082 1082 \family default
1083 1083 statements.
1084 1084 \layout Paragraph
1085 1085
1086 1086 Upgrading
1087 1087 \layout Standard
1088 1088
1089 1089 For an IPython upgrade, you should first uninstall the previous version.
1090 1090 This will ensure that all files and directories (such as the documentation)
1091 1091 which carry embedded version strings in their names are properly removed.
1092 1092 \layout Paragraph
1093 1093
1094 1094 Manual installation under Win32
1095 1095 \layout Standard
1096 1096
1097 1097 In case the automatic installer does not work for some reason, you can download
1098 1098 the
1099 1099 \family typewriter
1100 1100 ipython-XXX.tar.gz
1101 1101 \family default
1102 1102 file, which contains the full IPython source distribution (the popular
1103 1103 WinZip can read
1104 1104 \family typewriter
1105 1105 .tar.gz
1106 1106 \family default
1107 1107 files).
1108 1108 After uncompressing the archive, you can install it at a command terminal
1109 1109 just like any other Python module, by using
1110 1110 \family typewriter
1111 1111 `python setup.py install'
1112 1112 \family default
1113 1113 .
1114 1114
1115 1115 \layout Standard
1116 1116
1117 1117 After the installation, run the supplied
1118 1118 \family typewriter
1119 1119 win32_manual_post_install.py
1120 1120 \family default
1121 1121 script, which creates the necessary Start Menu shortcuts for you.
1122 1122 \layout Subsection
1123 1123
1124 1124
1125 1125 \begin_inset LatexCommand \label{sec:upgrade}
1126 1126
1127 1127 \end_inset
1128 1128
1129 1129 Upgrading from a previous version
1130 1130 \layout Standard
1131 1131
1132 1132 If you are upgrading from a previous version of IPython, after doing the
1133 1133 routine installation described above, you should call IPython with the
1134 1134
1135 1135 \family typewriter
1136 1136 -upgrade
1137 1137 \family default
1138 1138 option the first time you run your new copy.
1139 1139 This will automatically update your configuration directory while preserving
1140 1140 copies of your old files.
1141 1141 You can then later merge back any personal customizations you may have
1142 1142 made into the new files.
1143 1143 It is a good idea to do this as there may be new options available in the
1144 1144 new configuration files which you will not have.
1145 1145 \layout Standard
1146 1146
1147 1147 Under Windows, if you don't know how to call python scripts with arguments
1148 1148 from a command line, simply delete the old config directory and IPython
1149 1149 will make a new one.
1150 1150 Win2k and WinXP users will find it in
1151 1151 \family typewriter
1152 1152 C:
1153 1153 \backslash
1154 1154 Documents and Settings
1155 1155 \backslash
1156 1156 YourUserName
1157 1157 \backslash
1158 1158 _ipython
1159 1159 \family default
1160 1160 , and Win 9x users under
1161 1161 \family typewriter
1162 1162 C:
1163 1163 \backslash
1164 1164 Program Files
1165 1165 \backslash
1166 1166 IPython
1167 1167 \backslash
1168 1168 _ipython.
1169 1169 \layout Section
1170 1170
1171 1171
1172 1172 \begin_inset LatexCommand \label{sec:good_config}
1173 1173
1174 1174 \end_inset
1175 1175
1176 1176
1177 1177 \begin_inset OptArg
1178 1178 collapsed true
1179 1179
1180 1180 \layout Standard
1181 1181
1182 1182 Initial configuration
1183 1183 \begin_inset ERT
1184 1184 status Collapsed
1185 1185
1186 1186 \layout Standard
1187 1187
1188 1188 \backslash
1189 1189 ldots
1190 1190 \end_inset
1191 1191
1192 1192
1193 1193 \end_inset
1194 1194
1195 1195 Initial configuration of your environment
1196 1196 \layout Standard
1197 1197
1198 1198 This section will help you set various things in your environment for your
1199 1199 IPython sessions to be as efficient as possible.
1200 1200 All of IPython's configuration information, along with several example
1201 1201 files, is stored in a directory named by default
1202 1202 \family typewriter
1203 1203 $HOME/.ipython
1204 1204 \family default
1205 1205 .
1206 1206 You can change this by defining the environment variable
1207 1207 \family typewriter
1208 1208 IPYTHONDIR
1209 1209 \family default
1210 1210 , or at runtime with the command line option
1211 1211 \family typewriter
1212 1212 -ipythondir
1213 1213 \family default
1214 1214 .
1215 1215 \layout Standard
1216 1216
1217 1217 If all goes well, the first time you run IPython it should automatically
1218 1218 create a user copy of the config directory for you, based on its builtin
1219 1219 defaults.
1220 1220 You can look at the files it creates to learn more about configuring the
1221 1221 system.
1222 1222 The main file you will modify to configure IPython's behavior is called
1223 1223
1224 1224 \family typewriter
1225 1225 ipythonrc
1226 1226 \family default
1227 1227 (with a
1228 1228 \family typewriter
1229 1229 .ini
1230 1230 \family default
1231 1231 extension under Windows), included for reference in Sec.
1232 1232
1233 1233 \begin_inset LatexCommand \ref{sec:ipytonrc-sample}
1234 1234
1235 1235 \end_inset
1236 1236
1237 1237 .
1238 1238 This file is very commented and has many variables you can change to suit
1239 1239 your taste, you can find more details in Sec.
1240 1240
1241 1241 \begin_inset LatexCommand \ref{sec:customization}
1242 1242
1243 1243 \end_inset
1244 1244
1245 1245 .
1246 1246 Here we discuss the basic things you will want to make sure things are
1247 1247 working properly from the beginning.
1248 1248 \layout Subsection
1249 1249
1250 1250
1251 1251 \begin_inset LatexCommand \label{sec:help-access}
1252 1252
1253 1253 \end_inset
1254 1254
1255 1255 Access to the Python help system
1256 1256 \layout Standard
1257 1257
1258 1258 This is true for Python in general (not just for IPython): you should have
1259 1259 an environment variable called
1260 1260 \family typewriter
1261 1261 PYTHONDOCS
1262 1262 \family default
1263 1263 pointing to the directory where your HTML Python documentation lives.
1264 1264 In my system it's
1265 1265 \family typewriter
1266 1266 /usr/share/doc/python-docs-2.3.4/html
1267 1267 \family default
1268 1268 , check your local details or ask your systems administrator.
1269 1269
1270 1270 \layout Standard
1271 1271
1272 1272 This is the directory which holds the HTML version of the Python manuals.
1273 1273 Unfortunately it seems that different Linux distributions package these
1274 1274 files differently, so you may have to look around a bit.
1275 1275 Below I show the contents of this directory on my system for reference:
1276 1276 \layout Standard
1277 1277
1278 1278
1279 1279 \family typewriter
1280 1280 [html]> ls
1281 1281 \newline
1282 1282 about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/
1283 1283 about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
1284 1284 \layout Standard
1285 1285
1286 1286 You should really make sure this variable is correctly set so that Python's
1287 1287 pydoc-based help system works.
1288 1288 It is a powerful and convenient system with full access to the Python manuals
1289 1289 and all modules accessible to you.
1290 1290 \layout Standard
1291 1291
1292 1292 Under Windows it seems that pydoc finds the documentation automatically,
1293 1293 so no extra setup appears necessary.
1294 1294 \layout Subsection
1295 1295
1296 1296 Editor
1297 1297 \layout Standard
1298 1298
1299 1299 The
1300 1300 \family typewriter
1301 1301 %edit
1302 1302 \family default
1303 1303 command (and its alias
1304 1304 \family typewriter
1305 1305 %ed
1306 1306 \family default
1307 1307 ) will invoke the editor set in your environment as
1308 1308 \family typewriter
1309 1309 EDITOR
1310 1310 \family default
1311 1311 .
1312 1312 If this variable is not set, it will default to
1313 1313 \family typewriter
1314 1314 vi
1315 1315 \family default
1316 1316 under Linux/Unix and to
1317 1317 \family typewriter
1318 1318 notepad
1319 1319 \family default
1320 1320 under Windows.
1321 1321 You may want to set this variable properly and to a lightweight editor
1322 1322 which doesn't take too long to start (that is, something other than a new
1323 1323 instance of
1324 1324 \family typewriter
1325 1325 Emacs
1326 1326 \family default
1327 1327 ).
1328 1328 This way you can edit multi-line code quickly and with the power of a real
1329 1329 editor right inside IPython.
1330 1330
1331 1331 \layout Standard
1332 1332
1333 1333 If you are a dedicated
1334 1334 \family typewriter
1335 1335 Emacs
1336 1336 \family default
1337 1337 user, you should set up the
1338 1338 \family typewriter
1339 1339 Emacs
1340 1340 \family default
1341 1341 server so that new requests are handled by the original process.
1342 1342 This means that almost no time is spent in handling the request (assuming
1343 1343 an
1344 1344 \family typewriter
1345 1345 Emacs
1346 1346 \family default
1347 1347 process is already running).
1348 1348 For this to work, you need to set your
1349 1349 \family typewriter
1350 1350 EDITOR
1351 1351 \family default
1352 1352 environment variable to
1353 1353 \family typewriter
1354 1354 'emacsclient'
1355 1355 \family default
1356 1356 .
1357 1357
1358 1358 \family typewriter
1359 1359
1360 1360 \family default
1361 1361 The code below, supplied by Francois Pinard, can then be used in your
1362 1362 \family typewriter
1363 1363 .emacs
1364 1364 \family default
1365 1365 file to enable the server:
1366 1366 \layout Standard
1367 1367
1368 1368
1369 1369 \family typewriter
1370 1370 (defvar server-buffer-clients)
1371 1371 \newline
1372 1372 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
1373 1373 \newline
1374 1374
1375 1375 \begin_inset ERT
1376 1376 status Collapsed
1377 1377
1378 1378 \layout Standard
1379 1379
1380 1380 \backslash
1381 1381 hspace*{0mm}
1382 1382 \end_inset
1383 1383
1384 1384 \SpecialChar ~
1385 1385 \SpecialChar ~
1386 1386 (server-start)
1387 1387 \newline
1388 1388
1389 1389 \begin_inset ERT
1390 1390 status Collapsed
1391 1391
1392 1392 \layout Standard
1393 1393
1394 1394 \backslash
1395 1395 hspace*{0mm}
1396 1396 \end_inset
1397 1397
1398 1398 \SpecialChar ~
1399 1399 \SpecialChar ~
1400 1400 (defun fp-kill-server-with-buffer-routine ()
1401 1401 \newline
1402 1402
1403 1403 \begin_inset ERT
1404 1404 status Collapsed
1405 1405
1406 1406 \layout Standard
1407 1407
1408 1408 \backslash
1409 1409 hspace*{0mm}
1410 1410 \end_inset
1411 1411
1412 1412 \SpecialChar ~
1413 1413 \SpecialChar ~
1414 1414 \SpecialChar ~
1415 1415 \SpecialChar ~
1416 1416 (and server-buffer-clients (server-done)))
1417 1417 \newline
1418 1418
1419 1419 \begin_inset ERT
1420 1420 status Collapsed
1421 1421
1422 1422 \layout Standard
1423 1423
1424 1424 \backslash
1425 1425 hspace*{0mm}
1426 1426 \end_inset
1427 1427
1428 1428 \SpecialChar ~
1429 1429 \SpecialChar ~
1430 1430 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
1431 1431 \layout Standard
1432 1432
1433 1433 You can also set the value of this editor via the commmand-line option '-
1434 1434 \family typewriter
1435 1435 editor'
1436 1436 \family default
1437 1437 or in your
1438 1438 \family typewriter
1439 1439 ipythonrc
1440 1440 \family default
1441 1441 file.
1442 1442 This is useful if you wish to use specifically for IPython an editor different
1443 1443 from your typical default (and for Windows users who tend to use fewer
1444 1444 environment variables).
1445 1445 \layout Subsection
1446 1446
1447 1447 Color
1448 1448 \layout Standard
1449 1449
1450 1450 The default IPython configuration has most bells and whistles turned on
1451 1451 (they're pretty safe).
1452 1452 But there's one that
1453 1453 \emph on
1454 1454 may
1455 1455 \emph default
1456 1456 cause problems on some systems: the use of color on screen for displaying
1457 1457 information.
1458 1458 This is very useful, since IPython can show prompts and exception tracebacks
1459 1459 with various colors, display syntax-highlighted source code, and in general
1460 1460 make it easier to visually parse information.
1461 1461 \layout Standard
1462 1462
1463 1463 The following terminals seem to handle the color sequences fine:
1464 1464 \layout Itemize
1465 1465
1466 1466 Linux main text console, KDE Konsole, Gnome Terminal, E-term, rxvt, xterm.
1467 1467 \layout Itemize
1468 1468
1469 1469 CDE terminal (tested under Solaris).
1470 1470 This one boldfaces light colors.
1471 1471 \layout Itemize
1472 1472
1473 1473 (X)Emacs buffers.
1474 1474 See sec.
1475 1475 \begin_inset LatexCommand \ref{sec:emacs}
1476 1476
1477 1477 \end_inset
1478 1478
1479 1479 for more details on using IPython with (X)Emacs.
1480 1480 \layout Itemize
1481 1481
1482 1482 A Windows (XP/2k) command prompt
1483 1483 \emph on
1484 1484 with Gary Bishop's support extensions
1485 1485 \emph default
1486 1486 .
1487 1487 Gary's extensions are discussed in Sec.\SpecialChar ~
1488 1488
1489 1489 \begin_inset LatexCommand \ref{sub:Under-Windows}
1490 1490
1491 1491 \end_inset
1492 1492
1493 1493 .
1494 1494 \layout Itemize
1495 1495
1496 1496 A Windows (XP/2k) CygWin shell.
1497 1497 Although some users have reported problems; it is not clear whether there
1498 1498 is an issue for everyone or only under specific configurations.
1499 1499 If you have full color support under cygwin, please post to the IPython
1500 1500 mailing list so this issue can be resolved for all users.
1501 1501 \layout Standard
1502 1502
1503 1503 These have shown problems:
1504 1504 \layout Itemize
1505 1505
1506 1506 Windows command prompt in WinXP/2k logged into a Linux machine via telnet
1507 1507 or ssh.
1508 1508 \layout Itemize
1509 1509
1510 1510 Windows native command prompt in WinXP/2k,
1511 1511 \emph on
1512 1512 without
1513 1513 \emph default
1514 1514 Gary Bishop's extensions.
1515 1515 Once Gary's readline library is installed, the normal WinXP/2k command
1516 1516 prompt works perfectly.
1517 1517 \layout Standard
1518 1518
1519 1519 Currently the following color schemes are available:
1520 1520 \layout Itemize
1521 1521
1522 1522
1523 1523 \family typewriter
1524 1524 NoColor
1525 1525 \family default
1526 1526 : uses no color escapes at all (all escapes are empty
1527 1527 \begin_inset Quotes eld
1528 1528 \end_inset
1529 1529
1530 1530
1531 1531 \begin_inset Quotes eld
1532 1532 \end_inset
1533 1533
1534 1534 strings).
1535 1535 This 'scheme' is thus fully safe to use in any terminal.
1536 1536 \layout Itemize
1537 1537
1538 1538
1539 1539 \family typewriter
1540 1540 Linux
1541 1541 \family default
1542 1542 : works well in Linux console type environments: dark background with light
1543 1543 fonts.
1544 1544 It uses bright colors for information, so it is difficult to read if you
1545 1545 have a light colored background.
1546 1546 \layout Itemize
1547 1547
1548 1548
1549 1549 \family typewriter
1550 1550 LightBG
1551 1551 \family default
1552 1552 : the basic colors are similar to those in the
1553 1553 \family typewriter
1554 1554 Linux
1555 1555 \family default
1556 1556 scheme but darker.
1557 1557 It is easy to read in terminals with light backgrounds.
1558 1558 \layout Standard
1559 1559
1560 1560 IPython uses colors for two main groups of things: prompts and tracebacks
1561 1561 which are directly printed to the terminal, and the object introspection
1562 1562 system which passes large sets of data through a pager.
1563 1563 \layout Subsubsection
1564 1564
1565 1565 Input/Output prompts and exception tracebacks
1566 1566 \layout Standard
1567 1567
1568 1568 You can test whether the colored prompts and tracebacks work on your system
1569 1569 interactively by typing
1570 1570 \family typewriter
1571 1571 '%colors Linux'
1572 1572 \family default
1573 1573 at the prompt (use '
1574 1574 \family typewriter
1575 1575 %colors LightBG'
1576 1576 \family default
1577 1577 if your terminal has a light background).
1578 1578 If the input prompt shows garbage like:
1579 1579 \newline
1580 1580
1581 1581 \family typewriter
1582 1582 [0;32mIn [[1;32m1[0;32m]: [0;00m
1583 1583 \family default
1584 1584
1585 1585 \newline
1586 1586 instead of (in color) something like:
1587 1587 \newline
1588 1588
1589 1589 \family typewriter
1590 1590 In [1]:
1591 1591 \family default
1592 1592
1593 1593 \newline
1594 1594 this means that your terminal doesn't properly handle color escape sequences.
1595 1595 You can go to a 'no color' mode by typing '
1596 1596 \family typewriter
1597 1597 %colors NoColor
1598 1598 \family default
1599 1599 '.
1600 1600
1601 1601 \layout Standard
1602 1602
1603 1603 You can try using a different terminal emulator program.
1604 1604 To permanently set your color preferences, edit the file
1605 1605 \family typewriter
1606 1606 $HOME/.ipython/ipythonrc
1607 1607 \family default
1608 1608 and set the
1609 1609 \family typewriter
1610 1610 colors
1611 1611 \family default
1612 1612 option to the desired value.
1613 1613 \layout Subsubsection
1614 1614
1615 1615 Object details (types, docstrings, source code, etc.)
1616 1616 \layout Standard
1617 1617
1618 1618 IPython has a set of special functions for studying the objects you are
1619 1619 working with, discussed in detail in Sec.
1620 1620
1621 1621 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1622 1622
1623 1623 \end_inset
1624 1624
1625 1625 .
1626 1626 But this system relies on passing information which is longer than your
1627 1627 screen through a data pager, such as the common Unix
1628 1628 \family typewriter
1629 1629 less
1630 1630 \family default
1631 1631 and
1632 1632 \family typewriter
1633 1633 more
1634 1634 \family default
1635 1635 programs.
1636 1636 In order to be able to see this information in color, your pager needs
1637 1637 to be properly configured.
1638 1638 I strongly recommend using
1639 1639 \family typewriter
1640 1640 less
1641 1641 \family default
1642 1642 instead of
1643 1643 \family typewriter
1644 1644 more
1645 1645 \family default
1646 1646 , as it seems that
1647 1647 \family typewriter
1648 1648 more
1649 1649 \family default
1650 1650 simply can not understand colored text correctly.
1651 1651 \layout Standard
1652 1652
1653 1653 In order to configure
1654 1654 \family typewriter
1655 1655 less
1656 1656 \family default
1657 1657 as your default pager, do the following:
1658 1658 \layout Enumerate
1659 1659
1660 1660 Set the environment
1661 1661 \family typewriter
1662 1662 PAGER
1663 1663 \family default
1664 1664 variable to
1665 1665 \family typewriter
1666 1666 less
1667 1667 \family default
1668 1668 .
1669 1669 \layout Enumerate
1670 1670
1671 1671 Set the environment
1672 1672 \family typewriter
1673 1673 LESS
1674 1674 \family default
1675 1675 variable to
1676 1676 \family typewriter
1677 1677 -r
1678 1678 \family default
1679 1679 (plus any other options you always want to pass to
1680 1680 \family typewriter
1681 1681 less
1682 1682 \family default
1683 1683 by default).
1684 1684 This tells
1685 1685 \family typewriter
1686 1686 less
1687 1687 \family default
1688 1688 to properly interpret control sequences, which is how color information
1689 1689 is given to your terminal.
1690 1690 \layout Standard
1691 1691
1692 1692 For the
1693 1693 \family typewriter
1694 1694 csh
1695 1695 \family default
1696 1696 or
1697 1697 \family typewriter
1698 1698 tcsh
1699 1699 \family default
1700 1700 shells, add to your
1701 1701 \family typewriter
1702 1702 ~/.cshrc
1703 1703 \family default
1704 1704 file the lines:
1705 1705 \layout Standard
1706 1706
1707 1707
1708 1708 \family typewriter
1709 1709 setenv PAGER less
1710 1710 \newline
1711 1711 setenv LESS -r
1712 1712 \layout Standard
1713 1713
1714 1714 There is similar syntax for other Unix shells, look at your system documentation
1715 1715 for details.
1716 1716 \layout Standard
1717 1717
1718 1718 If you are on a system which lacks proper data pagers (such as Windows),
1719 1719 IPython will use a very limited builtin pager.
1720 1720 \layout Subsection
1721 1721
1722 1722
1723 1723 \begin_inset LatexCommand \label{sec:emacs}
1724 1724
1725 1725 \end_inset
1726 1726
1727 1727 (X)Emacs configuration
1728 1728 \layout Standard
1729 1729
1730 1730 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, currently
1731 1731 (X)Emacs and IPython get along very well.
1732 1732
1733 1733 \layout Standard
1734 1734
1735 1735
1736 1736 \series bold
1737 1737 Important note:
1738 1738 \series default
1739 1739 You will need to use a recent enough version of
1740 1740 \family typewriter
1741 1741 python-mode.el
1742 1742 \family default
1743 1743 , along with the file
1744 1744 \family typewriter
1745 1745 ipython.el
1746 1746 \family default
1747 1747 .
1748 1748 You can check that the version you have of
1749 1749 \family typewriter
1750 1750 python-mode.el
1751 1751 \family default
1752 1752 is new enough by either looking at the revision number in the file itself,
1753 1753 or asking for it in (X)Emacs via
1754 1754 \family typewriter
1755 1755 M-x py-version
1756 1756 \family default
1757 1757 .
1758 1758 Versions 4.68 and newer contain the necessary fixes for proper IPython support.
1759 1759 \layout Standard
1760 1760
1761 1761 The file
1762 1762 \family typewriter
1763 1763 ipython.el
1764 1764 \family default
1765 1765 is included with the IPython distribution, in the documentation directory
1766 1766 (where this manual resides in PDF and HTML formats).
1767 1767 \layout Standard
1768 1768
1769 1769 Once you put these files in your Emacs path, all you need in your
1770 1770 \family typewriter
1771 1771 .emacs
1772 1772 \family default
1773 1773 file is:
1774 1774 \layout Standard
1775 1775
1776 1776
1777 1777 \family typewriter
1778 1778 (require 'ipython)
1779 1779 \layout Standard
1780 1780
1781 1781 This should give you full support for executing code snippets via IPython,
1782 1782 opening IPython as your Python shell via
1783 1783 \family typewriter
1784 1784 C-c\SpecialChar ~
1785 1785 !
1786 1786 \family default
1787 1787 , etc.
1788 1788
1789 1789 \layout Subsubsection*
1790 1790
1791 1791 Notes
1792 1792 \layout Itemize
1793 1793
1794 1794 There is one caveat you should be aware of: you must start the IPython shell
1795 1795
1796 1796 \emph on
1797 1797 before
1798 1798 \emph default
1799 1799 attempting to execute any code regions via
1800 1800 \family typewriter
1801 1801 C-c\SpecialChar ~
1802 1802 |
1803 1803 \family default
1804 1804 .
1805 1805 Simply type
1806 1806 \family typewriter
1807 1807 C-c\SpecialChar ~
1808 1808 !
1809 1809 \family default
1810 1810 to start IPython before passing any code regions to the interpreter, and
1811 1811 you shouldn't experience any problems.
1812 1812 \newline
1813 1813 This is due to a bug in Python itself, which has been fixed for Python 2.3,
1814 1814 but exists as of Python 2.2.2 (reported as SF bug [ 737947 ]).
1815 1815 \layout Itemize
1816 1816
1817 1817 The (X)Emacs support is maintained by Alexander Schmolck, so all comments/reques
1818 1818 ts should be directed to him through the IPython mailing lists.
1819 1819
1820 1820 \layout Itemize
1821 1821
1822 1822 This code is still somewhat experimental so it's a bit rough around the
1823 1823 edges (although in practice, it works quite well).
1824 1824 \layout Itemize
1825 1825
1826 1826 Be aware that if you customize
1827 1827 \family typewriter
1828 1828 py-python-command
1829 1829 \family default
1830 1830 previously, this value will override what
1831 1831 \family typewriter
1832 1832 ipython.el
1833 1833 \family default
1834 1834 does (because loading the customization variables comes later).
1835 1835 \layout Section
1836 1836
1837 1837
1838 1838 \begin_inset LatexCommand \label{sec:quick_tips}
1839 1839
1840 1840 \end_inset
1841 1841
1842 1842 Quick tips
1843 1843 \layout Standard
1844 1844
1845 1845 IPython can be used as an improved replacement for the Python prompt, and
1846 1846 for that you don't really need to read any more of this manual.
1847 1847 But in this section we'll try to summarize a few tips on how to make the
1848 1848 most effective use of it for everyday Python development, highlighting
1849 1849 things you might miss in the rest of the manual (which is getting long).
1850 1850 We'll give references to parts in the manual which provide more detail
1851 1851 when appropriate.
1852 1852 \layout Standard
1853 1853
1854 1854 The following article by Jeremy Jones provides an introductory tutorial
1855 1855 about IPython:
1856 1856 \newline
1857 1857
1858 1858 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html}
1859 1859
1860 1860 \end_inset
1861 1861
1862 1862
1863 1863 \layout Itemize
1864 1864
1865 1865 The TAB key.
1866 1866 TAB-completion, especially for attributes, is a convenient way to explore
1867 1867 the structure of any object you're dealing with.
1868 1868 Simply type
1869 1869 \family typewriter
1870 1870 object_name.<TAB>
1871 1871 \family default
1872 1872 and a list of the object's attributes will be printed (see sec.
1873 1873
1874 1874 \begin_inset LatexCommand \ref{sec:readline}
1875 1875
1876 1876 \end_inset
1877 1877
1878 1878 for more).
1879 1879 Tab completion also works on file and directory names, which combined with
1880 1880 IPython's alias system allows you to do from within IPython many of the
1881 1881 things you normally would need the system shell for.
1882 1882
1883 1883 \layout Itemize
1884 1884
1885 1885 Explore your objects.
1886 1886 Typing
1887 1887 \family typewriter
1888 1888 object_name?
1889 1889 \family default
1890 1890 will print all sorts of details about any object, including docstrings,
1891 1891 function definition lines (for call arguments) and constructor details
1892 1892 for classes.
1893 1893 The magic commands
1894 1894 \family typewriter
1895 1895 %pdoc
1896 1896 \family default
1897 1897 ,
1898 1898 \family typewriter
1899 1899 %pdef
1900 1900 \family default
1901 1901 ,
1902 1902 \family typewriter
1903 1903 %psource
1904 1904 \family default
1905 1905 and
1906 1906 \family typewriter
1907 1907 %pfile
1908 1908 \family default
1909 1909 will respectively print the docstring, function definition line, full source
1910 1910 code and the complete file for any object (when they can be found).
1911 1911 If automagic is on (it is by default), you don't need to type the '
1912 1912 \family typewriter
1913 1913 %
1914 1914 \family default
1915 1915 ' explicitly.
1916 1916 See sec.
1917 1917
1918 1918 \begin_inset LatexCommand \ref{sec:dyn-object-info}
1919 1919
1920 1920 \end_inset
1921 1921
1922 1922 for more.
1923 1923 \layout Itemize
1924 1924
1925 1925 The
1926 1926 \family typewriter
1927 1927 %run
1928 1928 \family default
1929 1929 magic command allows you to run any python script and load all of its data
1930 1930 directly into the interactive namespace.
1931 1931 Since the file is re-read from disk each time, changes you make to it are
1932 1932 reflected immediately (in contrast to the behavior of
1933 1933 \family typewriter
1934 1934 import
1935 1935 \family default
1936 1936 ).
1937 1937 I rarely use
1938 1938 \family typewriter
1939 1939 import
1940 1940 \family default
1941 1941 for code I am testing, relying on
1942 1942 \family typewriter
1943 1943 %run
1944 1944 \family default
1945 1945 instead.
1946 1946 See sec.
1947 1947
1948 1948 \begin_inset LatexCommand \ref{sec:magic}
1949 1949
1950 1950 \end_inset
1951 1951
1952 1952 for more on this and other magic commands, or type the name of any magic
1953 1953 command and ? to get details on it.
1954 1954 See also sec.
1955 1955
1956 1956 \begin_inset LatexCommand \ref{sec:dreload}
1957 1957
1958 1958 \end_inset
1959 1959
1960 1960 for a recursive reload command.
1961 1961 \newline
1962 1962
1963 1963 \family typewriter
1964 1964 %run
1965 1965 \family default
1966 1966 also has special flags for timing the execution of your scripts (
1967 1967 \family typewriter
1968 1968 -t
1969 1969 \family default
1970 1970 ) and for executing them under the control of either Python's
1971 1971 \family typewriter
1972 1972 pdb
1973 1973 \family default
1974 1974 debugger (
1975 1975 \family typewriter
1976 1976 -d
1977 1977 \family default
1978 1978 ) or profiler (
1979 1979 \family typewriter
1980 1980 -p
1981 1981 \family default
1982 1982 ).
1983 1983 With all of these,
1984 1984 \family typewriter
1985 1985 %run
1986 1986 \family default
1987 1987 can be used as the main tool for efficient interactive development of code
1988 1988 which you write in your editor of choice.
1989 1989 \layout Itemize
1990 1990
1991 1991 Use the Python debugger,
1992 1992 \family typewriter
1993 1993 pdb
1994 1994 \family default
1995 1995
1996 1996 \begin_inset Foot
1997 1997 collapsed true
1998 1998
1999 1999 \layout Standard
2000 2000
2001 2001 Thanks to Christian Hart and Matthew Arnison for the suggestions leading
2002 2002 to IPython's improved debugger and profiler support.
2003 2003 \end_inset
2004 2004
2005 2005 .
2006 2006 The
2007 2007 \family typewriter
2008 2008 %pdb
2009 2009 \family default
2010 2010 command allows you to toggle on and off the automatic invocation of an
2011 2011 IPython-enhanced
2012 2012 \family typewriter
2013 2013 pdb
2014 2014 \family default
2015 2015 debugger (with coloring, tab completion and more) at any uncaught exception.
2016 2016 The advantage of this is that
2017 2017 \family typewriter
2018 2018 pdb
2019 2019 \family default
2020 2020 starts
2021 2021 \emph on
2022 2022 inside
2023 2023 \emph default
2024 2024 the function where the exception occurred, with all data still available.
2025 2025 You can print variables, see code, execute statements and even walk up
2026 2026 and down the call stack to track down the true source of the problem (which
2027 2027 often is many layers in the stack above where the exception gets triggered).
2028 2028 \newline
2029 2029 Running programs with
2030 2030 \family typewriter
2031 2031 %run
2032 2032 \family default
2033 2033 and pdb active can be an efficient to develop and debug code, in many cases
2034 2034 eliminating the need for
2035 2035 \family typewriter
2036 2036 print
2037 2037 \family default
2038 2038 statements or external debugging tools.
2039 2039 I often simply put a
2040 2040 \family typewriter
2041 2041 1/0
2042 2042 \family default
2043 2043 in a place where I want to take a look so that pdb gets called, quickly
2044 2044 view whatever variables I need to or test various pieces of code and then
2045 2045 remove the
2046 2046 \family typewriter
2047 2047 1/0
2048 2048 \family default
2049 2049 .
2050 2050 \newline
2051 2051 Note also that `
2052 2052 \family typewriter
2053 2053 %run -d
2054 2054 \family default
2055 2055 ' activates
2056 2056 \family typewriter
2057 2057 pdb
2058 2058 \family default
2059 2059 and automatically sets initial breakpoints for you to step through your
2060 2060 code, watch variables, etc.
2061 2061 See Sec.\SpecialChar ~
2062 2062
2063 2063 \begin_inset LatexCommand \ref{sec:cache_output}
2064 2064
2065 2065 \end_inset
2066 2066
2067 2067 for details.
2068 2068 \layout Itemize
2069 2069
2070 2070 Use the output cache.
2071 2071 All output results are automatically stored in a global dictionary named
2072 2072
2073 2073 \family typewriter
2074 2074 Out
2075 2075 \family default
2076 2076 and variables named
2077 2077 \family typewriter
2078 2078 _1
2079 2079 \family default
2080 2080 ,
2081 2081 \family typewriter
2082 2082 _2
2083 2083 \family default
2084 2084 , etc.
2085 2085 alias them.
2086 2086 For example, the result of input line 4 is available either as
2087 2087 \family typewriter
2088 2088 Out[4]
2089 2089 \family default
2090 2090 or as
2091 2091 \family typewriter
2092 2092 _4
2093 2093 \family default
2094 2094 .
2095 2095 Additionally, three variables named
2096 2096 \family typewriter
2097 2097 _
2098 2098 \family default
2099 2099 ,
2100 2100 \family typewriter
2101 2101 __
2102 2102 \family default
2103 2103 and
2104 2104 \family typewriter
2105 2105 ___
2106 2106 \family default
2107 2107 are always kept updated with the for the last three results.
2108 2108 This allows you to recall any previous result and further use it for new
2109 2109 calculations.
2110 2110 See Sec.\SpecialChar ~
2111 2111
2112 2112 \begin_inset LatexCommand \ref{sec:cache_output}
2113 2113
2114 2114 \end_inset
2115 2115
2116 2116 for more.
2117 2117 \layout Itemize
2118 2118
2119 2119 Put a '
2120 2120 \family typewriter
2121 2121 ;
2122 2122 \family default
2123 2123 ' at the end of a line to supress the printing of output.
2124 2124 This is useful when doing calculations which generate long output you are
2125 2125 not interested in seeing.
2126 2126 The
2127 2127 \family typewriter
2128 2128 _*
2129 2129 \family default
2130 2130 variables and the
2131 2131 \family typewriter
2132 2132 Out[]
2133 2133 \family default
2134 2134 list do get updated with the contents of the output, even if it is not
2135 2135 printed.
2136 2136 You can thus still access the generated results this way for further processing.
2137 2137 \layout Itemize
2138 2138
2139 2139 A similar system exists for caching input.
2140 2140 All input is stored in a global list called
2141 2141 \family typewriter
2142 2142 In
2143 2143 \family default
2144 2144 , so you can re-execute lines 22 through 28 plus line 34 by typing
2145 2145 \family typewriter
2146 2146 'exec In[22:29]+In[34]'
2147 2147 \family default
2148 2148 (using Python slicing notation).
2149 2149 If you need to execute the same set of lines often, you can assign them
2150 2150 to a macro with the
2151 2151 \family typewriter
2152 2152 %macro
2153 2153 \family default
2154 2154
2155 2155 \family typewriter
2156 2156 function.
2157 2157
2158 2158 \family default
2159 2159 See sec.
2160 2160
2161 2161 \begin_inset LatexCommand \ref{sec:cache_input}
2162 2162
2163 2163 \end_inset
2164 2164
2165 2165 for more.
2166 2166 \layout Itemize
2167 2167
2168 2168 Use your input history.
2169 2169 The
2170 2170 \family typewriter
2171 2171 %hist
2172 2172 \family default
2173 2173 command can show you all previous input, without line numbers if desired
2174 2174 (option
2175 2175 \family typewriter
2176 2176 -n
2177 2177 \family default
2178 2178 ) so you can directly copy and paste code either back in IPython or in a
2179 2179 text editor.
2180 2180 You can also save all your history by turning on logging via
2181 2181 \family typewriter
2182 2182 %logstart
2183 2183 \family default
2184 2184 ; these logs can later be either reloaded as IPython sessions or used as
2185 2185 code for your programs.
2186 2186 \layout Itemize
2187 2187
2188 2188 Define your own macros with
2189 2189 \family typewriter
2190 2190 %macro
2191 2191 \family default
2192 2192 .
2193 2193 This can be useful for automating sequences of expressions when working
2194 2194 interactively.
2195 2195 \layout Itemize
2196 2196
2197 2197 Define your own system aliases.
2198 2198 Even though IPython gives you access to your system shell via the
2199 2199 \family typewriter
2200 2200 !
2201 2201 \family default
2202 2202 prefix, it is convenient to have aliases to the system commands you use
2203 2203 most often.
2204 2204 This allows you to work seamlessly from inside IPython with the same commands
2205 2205 you are used to in your system shell.
2206 2206 \newline
2207 2207 IPython comes with some pre-defined aliases and a complete system for changing
2208 2208 directories, both via a stack (see
2209 2209 \family typewriter
2210 2210 %pushd
2211 2211 \family default
2212 2212 ,
2213 2213 \family typewriter
2214 2214 %popd
2215 2215 \family default
2216 2216 and
2217 2217 \family typewriter
2218 2218 %ds
2219 2219 \family default
2220 2220 ) and via direct
2221 2221 \family typewriter
2222 2222 %cd
2223 2223 \family default
2224 2224 .
2225 2225 The latter keeps a history of visited directories and allows you to go
2226 2226 to any previously visited one.
2227 2227 \layout Itemize
2228 2228
2229 2229 Use Python to manipulate the results of system commands.
2230 2230 The `
2231 2231 \family typewriter
2232 2232 !!
2233 2233 \family default
2234 2234 ' special syntax, and the
2235 2235 \family typewriter
2236 2236 %sc
2237 2237 \family default
2238 2238 and
2239 2239 \family typewriter
2240 2240 %sx
2241 2241 \family default
2242 2242 magic commands allow you to capture system output into Python variables.
2243 2243 \layout Itemize
2244 2244
2245 2245 Expand python variables when calling the shell (either via
2246 2246 \family typewriter
2247 2247 `!'
2248 2248 \family default
2249 2249 and
2250 2250 \family typewriter
2251 2251 `!!'
2252 2252 \family default
2253 2253 or via aliases) by prepending a
2254 2254 \family typewriter
2255 2255 $
2256 2256 \family default
2257 2257 in front of them.
2258 2258 You can also expand complete python expressions.
2259 2259 See sec.\SpecialChar ~
2260 2260
2261 2261 \begin_inset LatexCommand \ref{sub:System-shell-access}
2262 2262
2263 2263 \end_inset
2264 2264
2265 2265 for more.
2266 2266 \layout Itemize
2267 2267
2268 2268 Use profiles to maintain different configurations (modules to load, function
2269 2269 definitions, option settings) for particular tasks.
2270 2270 You can then have customized versions of IPython for specific purposes.
2271 2271 See sec.\SpecialChar ~
2272 2272
2273 2273 \begin_inset LatexCommand \ref{sec:profiles}
2274 2274
2275 2275 \end_inset
2276 2276
2277 2277 for more.
2278 2278 \layout Itemize
2279 2279
2280 2280 Embed IPython in your programs.
2281 2281 A few lines of code are enough to load a complete IPython inside your own
2282 2282 programs, giving you the ability to work with your data interactively after
2283 2283 automatic processing has been completed.
2284 2284 See sec.\SpecialChar ~
2285 2285
2286 2286 \begin_inset LatexCommand \ref{sec:embed}
2287 2287
2288 2288 \end_inset
2289 2289
2290 2290 for more.
2291 2291 \layout Itemize
2292 2292
2293 2293 Use the Python profiler.
2294 2294 When dealing with performance issues, the
2295 2295 \family typewriter
2296 2296 %run
2297 2297 \family default
2298 2298 command with a
2299 2299 \family typewriter
2300 2300 -p
2301 2301 \family default
2302 2302 option allows you to run complete programs under the control of the Python
2303 2303 profiler.
2304 2304 The
2305 2305 \family typewriter
2306 2306 %prun
2307 2307 \family default
2308 2308 command does a similar job for single Python expressions (like function
2309 2309 calls).
2310 2310 \layout Itemize
2311 2311
2312 2312 Use
2313 2313 \family typewriter
2314 2314 %edit
2315 2315 \family default
2316 2316 to have almost multiline editing.
2317 2317 While IPython doesn't support true multiline editing, this command allows
2318 2318 you to call an editor on the spot, and IPython will execute the code you
2319 2319 type in there as if it were typed interactively.
2320 2320 \layout Itemize
2321 2321
2322 2322 Use the IPython.demo.Demo class to load any Python script as an interactive
2323 2323 demo.
2324 2324 With a minimal amount of simple markup, you can control the execution of
2325 2325 the script, stopping as needed.
2326 2326 See sec.\SpecialChar ~
2327 2327
2328 2328 \begin_inset LatexCommand \ref{sec:interactive-demos}
2329 2329
2330 2330 \end_inset
2331 2331
2332 2332 for more.
2333 2333 \layout Standard
2334 2334
2335 2335
2336 2336 \series bold
2337 2337 Effective logging:
2338 2338 \series default
2339 2339 a very useful suggestion sent in by Robert Kern follows
2340 2340 \layout Standard
2341 2341
2342 2342 I recently happened on a nifty way to keep tidy per-project log files.
2343 2343 I made a profile for my project (which is called "parkfield").
2344 2344 \layout LyX-Code
2345 2345
2346 2346 include ipythonrc
2347 2347 \layout LyX-Code
2348 2348
2349 2349 logfile '' # cancel earlier logfile invocation
2350 2350 \layout LyX-Code
2351 2351
2352 2352 execute import time
2353 2353 \layout LyX-Code
2354 2354
2355 2355 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
2356 2356 \layout LyX-Code
2357 2357
2358 2358 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
2359 2359 \layout Standard
2360 2360
2361 2361 I also added a shell alias for convenience:
2362 2362 \layout LyX-Code
2363 2363
2364 2364 alias parkfield="ipython -pylab -profile parkfield"
2365 2365 \layout Standard
2366 2366
2367 2367 Now I have a nice little directory with everything I ever type in, organized
2368 2368 by project and date.
2369 2369 \layout Standard
2370 2370
2371 2371
2372 2372 \series bold
2373 2373 Contribute your own:
2374 2374 \series default
2375 2375 If you have your own favorite tip on using IPython efficiently for a certain
2376 2376 task (especially things which can't be done in the normal Python interpreter),
2377 2377 don't hesitate to send it!
2378 2378 \layout Section
2379 2379
2380 2380 Command-line use
2381 2381 \layout Standard
2382 2382
2383 2383 You start IPython with the command:
2384 2384 \layout Standard
2385 2385
2386 2386
2387 2387 \family typewriter
2388 2388 $ ipython [options] files
2389 2389 \layout Standard
2390 2390
2391 2391 If invoked with no options, it executes all the files listed in sequence
2392 2392 and drops you into the interpreter while still acknowledging any options
2393 2393 you may have set in your ipythonrc file.
2394 2394 This behavior is different from standard Python, which when called as
2395 2395 \family typewriter
2396 2396 python -i
2397 2397 \family default
2398 2398 will only execute one file and ignore your configuration setup.
2399 2399 \layout Standard
2400 2400
2401 2401 Please note that some of the configuration options are not available at
2402 2402 the command line, simply because they are not practical here.
2403 2403 Look into your ipythonrc configuration file for details on those.
2404 2404 This file typically installed in the
2405 2405 \family typewriter
2406 2406 $HOME/.ipython
2407 2407 \family default
2408 2408 directory.
2409 2409 For Windows users,
2410 2410 \family typewriter
2411 2411 $HOME
2412 2412 \family default
2413 2413 resolves to
2414 2414 \family typewriter
2415 2415 C:
2416 2416 \backslash
2417 2417
2418 2418 \backslash
2419 2419 Documents and Settings
2420 2420 \backslash
2421 2421
2422 2422 \backslash
2423 2423 YourUserName
2424 2424 \family default
2425 2425 in most instances.
2426 2426 In the rest of this text, we will refer to this directory as
2427 2427 \family typewriter
2428 2428 IPYTHONDIR
2429 2429 \family default
2430 2430 .
2431 2431 \layout Subsection
2432 2432
2433 2433
2434 2434 \begin_inset LatexCommand \label{sec:threading-opts}
2435 2435
2436 2436 \end_inset
2437 2437
2438 2438 Special Threading Options
2439 2439 \layout Standard
2440 2440
2441 2441 The following special options are ONLY valid at the beginning of the command
2442 2442 line, and not later.
2443 2443 This is because they control the initial- ization of ipython itself, before
2444 2444 the normal option-handling mechanism is active.
2445 2445 \layout List
2446 2446 \labelwidthstring 00.00.0000
2447 2447
2448 2448
2449 2449 \family typewriter
2450 2450 \series bold
2451 2451 -gthread,\SpecialChar ~
2452 2452 -qthread,\SpecialChar ~
2453 2453 -wthread,\SpecialChar ~
2454 2454 -pylab:
2455 2455 \family default
2456 2456 \series default
2457 2457 Only
2458 2458 \emph on
2459 2459 one
2460 2460 \emph default
2461 2461 of these can be given, and it can only be given as the first option passed
2462 2462 to IPython (it will have no effect in any other position).
2463 2463 They provide threading support for the GTK Qt and WXPython toolkits, and
2464 2464 for the matplotlib library.
2465 2465 \layout List
2466 2466 \labelwidthstring 00.00.0000
2467 2467
2468 2468 \SpecialChar ~
2469 2469 With any of the first three options, IPython starts running a separate
2470 2470 thread for the graphical toolkit's operation, so that you can open and
2471 2471 control graphical elements from within an IPython command line, without
2472 2472 blocking.
2473 2473 All three provide essentially the same functionality, respectively for
2474 2474 GTK, QT and WXWidgets (via their Python interfaces).
2475 2475 \layout List
2476 2476 \labelwidthstring 00.00.0000
2477 2477
2478 2478 \SpecialChar ~
2479 2479 If
2480 2480 \family typewriter
2481 2481 -pylab
2482 2482 \family default
2483 2483 is given, IPython loads special support for the mat plotlib library (
2484 2484 \begin_inset LatexCommand \htmlurl{http://matplotlib.sourceforge.net}
2485 2485
2486 2486 \end_inset
2487 2487
2488 2488 ), allowing interactive usage of any of its backends as defined in the user's
2489 2489
2490 2490 \family typewriter
2491 2491 ~/.matplotlib/matplotlibrc
2492 2492 \family default
2493 2493 file.
2494 2494 It automatically activates GTK, Qt or WX threading for IPyhton if the choice
2495 2495 of matplotlib backend requires it.
2496 2496 It also modifies the
2497 2497 \family typewriter
2498 2498 %run
2499 2499 \family default
2500 2500 command to correctly execute (without blocking) any matplotlib-based script
2501 2501 which calls
2502 2502 \family typewriter
2503 2503 show()
2504 2504 \family default
2505 2505 at the end.
2506 2506
2507 2507 \layout List
2508 2508 \labelwidthstring 00.00.0000
2509 2509
2510 2510
2511 2511 \family typewriter
2512 2512 \series bold
2513 2513 -tk
2514 2514 \family default
2515 2515 \series default
2516 2516 The
2517 2517 \family typewriter
2518 2518 -g/q/wthread
2519 2519 \family default
2520 2520 options, and
2521 2521 \family typewriter
2522 2522 -pylab
2523 2523 \family default
2524 2524 (if matplotlib is configured to use GTK, Qt or WX), will normally block
2525 2525 Tk graphical interfaces.
2526 2526 This means that when either GTK, Qt or WX threading is active, any attempt
2527 2527 to open a Tk GUI will result in a dead window, and possibly cause the Python
2528 2528 interpreter to crash.
2529 2529 An extra option,
2530 2530 \family typewriter
2531 2531 -tk
2532 2532 \family default
2533 2533 , is available to address this issue.
2534 2534 It can
2535 2535 \emph on
2536 2536 only
2537 2537 \emph default
2538 2538 be given as a
2539 2539 \emph on
2540 2540 second
2541 2541 \emph default
2542 2542 option after any of the above (
2543 2543 \family typewriter
2544 2544 -gthread
2545 2545 \family default
2546 2546 ,
2547 2547 \family typewriter
2548 2548 -wthread
2549 2549 \family default
2550 2550 or
2551 2551 \family typewriter
2552 2552 -pylab
2553 2553 \family default
2554 2554 ).
2555 2555 \layout List
2556 2556 \labelwidthstring 00.00.0000
2557 2557
2558 2558 \SpecialChar ~
2559 2559 If
2560 2560 \family typewriter
2561 2561 -tk
2562 2562 \family default
2563 2563 is given, IPython will try to coordinate Tk threading with GTK, Qt or WX.
2564 2564 This is however potentially unreliable, and you will have to test on your
2565 2565 platform and Python configuration to determine whether it works for you.
2566 2566 Debian users have reported success, apparently due to the fact that Debian
2567 2567 builds all of Tcl, Tk, Tkinter and Python with pthreads support.
2568 2568 Under other Linux environments (such as Fedora Core 2/3), this option has
2569 2569 caused random crashes and lockups of the Python interpreter.
2570 2570 Under other operating systems (Mac OSX and Windows), you'll need to try
2571 2571 it to find out, since currently no user reports are available.
2572 2572 \layout List
2573 2573 \labelwidthstring 00.00.0000
2574 2574
2575 2575 \SpecialChar ~
2576 2576 There is unfortunately no way for IPython to determine at run time whether
2577 2577
2578 2578 \family typewriter
2579 2579 -tk
2580 2580 \family default
2581 2581 will work reliably or not, so you will need to do some experiments before
2582 2582 relying on it for regular work.
2583 2583
2584 2584 \layout Subsection
2585 2585
2586 2586
2587 2587 \begin_inset LatexCommand \label{sec:cmd-line-opts}
2588 2588
2589 2589 \end_inset
2590 2590
2591 2591 Regular Options
2592 2592 \layout Standard
2593 2593
2594 2594 After the above threading options have been given, regular options can follow
2595 2595 in any order.
2596 2596 All options can be abbreviated to their shortest non-ambiguous form and
2597 2597 are case-sensitive.
2598 2598 One or two dashes can be used.
2599 2599 Some options have an alternate short form, indicated after a
2600 2600 \family typewriter
2601 2601 |
2602 2602 \family default
2603 2603 .
2604 2604 \layout Standard
2605 2605
2606 2606 Most options can also be set from your ipythonrc configuration file.
2607 2607 See the provided example for more details on what the options do.
2608 2608 Options given at the command line override the values set in the ipythonrc
2609 2609 file.
2610 2610 \layout Standard
2611 2611
2612 2612 All options with a
2613 2613 \family typewriter
2614 2614 [no]
2615 2615 \family default
2616 2616 prepended can be specified in negated form (
2617 2617 \family typewriter
2618 2618 -nooption
2619 2619 \family default
2620 2620 instead of
2621 2621 \family typewriter
2622 2622 -option
2623 2623 \family default
2624 2624 ) to turn the feature off.
2625 2625 \layout List
2626 2626 \labelwidthstring 00.00.0000
2627 2627
2628 2628
2629 2629 \family typewriter
2630 2630 \series bold
2631 2631 -help
2632 2632 \family default
2633 2633 \series default
2634 2634 : print a help message and exit.
2635 2635 \layout List
2636 2636 \labelwidthstring 00.00.0000
2637 2637
2638 2638
2639 2639 \family typewriter
2640 2640 \series bold
2641 2641 -pylab:
2642 2642 \family default
2643 2643 \series default
2644 2644 this can
2645 2645 \emph on
2646 2646 only
2647 2647 \emph default
2648 2648 be given as the
2649 2649 \emph on
2650 2650 first
2651 2651 \emph default
2652 2652 option passed to IPython (it will have no effect in any other position).
2653 2653 It adds special support for the matplotlib library (
2654 2654 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
2655 2655
2656 2656 \end_inset
2657 2657
2658 2658 ), allowing interactive usage of any of its backends as defined in the user's
2659 2659
2660 2660 \family typewriter
2661 2661 .matplotlibrc
2662 2662 \family default
2663 2663 file.
2664 2664 It automatically activates GTK or WX threading for IPyhton if the choice
2665 2665 of matplotlib backend requires it.
2666 2666 It also modifies the
2667 2667 \family typewriter
2668 2668 %run
2669 2669 \family default
2670 2670 command to correctly execute (without blocking) any matplotlib-based script
2671 2671 which calls
2672 2672 \family typewriter
2673 2673 show()
2674 2674 \family default
2675 2675 at the end.
2676 2676 See Sec.\SpecialChar ~
2677 2677
2678 2678 \begin_inset LatexCommand \ref{sec:matplotlib-support}
2679 2679
2680 2680 \end_inset
2681 2681
2682 2682 for more details.
2683 2683 \layout List
2684 2684 \labelwidthstring 00.00.0000
2685 2685
2686 2686
2687 2687 \family typewriter
2688 2688 \series bold
2689 2689 -[no]autocall:
2690 2690 \family default
2691 2691 \series default
2692 2692 Make IPython automatically call any callable object even if you didn't
2693 2693 type explicit parentheses.
2694 2694 For example, `str 43' becomes `str(43)' automatically.
2695 2695 \layout List
2696 2696 \labelwidthstring 00.00.0000
2697 2697
2698 2698
2699 2699 \family typewriter
2700 2700 \series bold
2701 2701 -[no]autoindent:
2702 2702 \family default
2703 2703 \series default
2704 2704 Turn automatic indentation on/off.
2705 2705 \layout List
2706 2706 \labelwidthstring 00.00.0000
2707 2707
2708 2708
2709 2709 \family typewriter
2710 2710 \series bold
2711 2711 -[no]automagic
2712 2712 \series default
2713 2713 :
2714 2714 \family default
2715 2715 make magic commands automatic (without needing their first character to
2716 2716 be
2717 2717 \family typewriter
2718 2718 %
2719 2719 \family default
2720 2720 ).
2721 2721 Type
2722 2722 \family typewriter
2723 2723 %magic
2724 2724 \family default
2725 2725 at the IPython prompt for more information.
2726 2726 \layout List
2727 2727 \labelwidthstring 00.00.0000
2728 2728
2729 2729
2730 2730 \family typewriter
2731 2731 \series bold
2732 2732 -[no]autoedit_syntax:
2733 2733 \family default
2734 2734 \series default
2735 2735 When a syntax error occurs after editing a file, automatically open the
2736 2736 file to the trouble causing line for convenient fixing.
2737 2737
2738 2738 \layout List
2739 2739 \labelwidthstring 00.00.0000
2740 2740
2741 2741
2742 2742 \family typewriter
2743 2743 \series bold
2744 2744 -[no]banner
2745 2745 \series default
2746 2746 :
2747 2747 \family default
2748 2748 Print the initial information banner (default on).
2749 2749 \layout List
2750 2750 \labelwidthstring 00.00.0000
2751 2751
2752 2752
2753 2753 \family typewriter
2754 2754 \series bold
2755 2755 -c\SpecialChar ~
2756 2756 <command>:
2757 2757 \family default
2758 2758 \series default
2759 2759 execute the given command string, and set sys.argv to
2760 2760 \family typewriter
2761 2761 ['c']
2762 2762 \family default
2763 2763 .
2764 2764 This is similar to the
2765 2765 \family typewriter
2766 2766 -c
2767 2767 \family default
2768 2768 option in the normal Python interpreter.
2769 2769
2770 2770 \layout List
2771 2771 \labelwidthstring 00.00.0000
2772 2772
2773 2773
2774 2774 \family typewriter
2775 2775 \series bold
2776 2776 -cache_size|cs\SpecialChar ~
2777 2777 <n>
2778 2778 \series default
2779 2779 :
2780 2780 \family default
2781 2781 size of the output cache (maximum number of entries to hold in memory).
2782 2782 The default is 1000, you can change it permanently in your config file.
2783 2783 Setting it to 0 completely disables the caching system, and the minimum
2784 2784 value accepted is 20 (if you provide a value less than 20, it is reset
2785 2785 to 0 and a warning is issued) This limit is defined because otherwise you'll
2786 2786 spend more time re-flushing a too small cache than working.
2787 2787 \layout List
2788 2788 \labelwidthstring 00.00.0000
2789 2789
2790 2790
2791 2791 \family typewriter
2792 2792 \series bold
2793 2793 -classic|cl
2794 2794 \series default
2795 2795 :
2796 2796 \family default
2797 2797 Gives IPython a similar feel to the classic Python prompt.
2798 2798 \layout List
2799 2799 \labelwidthstring 00.00.0000
2800 2800
2801 2801
2802 2802 \family typewriter
2803 2803 \series bold
2804 2804 -colors\SpecialChar ~
2805 2805 <scheme>:
2806 2806 \family default
2807 2807 \series default
2808 2808 Color scheme for prompts and exception reporting.
2809 2809 Currently implemented: NoColor, Linux and LightBG.
2810 2810 \layout List
2811 2811 \labelwidthstring 00.00.0000
2812 2812
2813 2813
2814 2814 \family typewriter
2815 2815 \series bold
2816 2816 -[no]color_info:
2817 2817 \family default
2818 2818 \series default
2819 2819 IPython can display information about objects via a set of functions, and
2820 2820 optionally can use colors for this, syntax highlighting source code and
2821 2821 various other elements.
2822 2822 However, because this information is passed through a pager (like 'less')
2823 2823 and many pagers get confused with color codes, this option is off by default.
2824 2824 You can test it and turn it on permanently in your ipythonrc file if it
2825 2825 works for you.
2826 2826 As a reference, the 'less' pager supplied with Mandrake 8.2 works ok, but
2827 2827 that in RedHat 7.2 doesn't.
2828 2828 \layout List
2829 2829 \labelwidthstring 00.00.0000
2830 2830
2831 2831 \SpecialChar ~
2832 2832 Test it and turn it on permanently if it works with your system.
2833 2833 The magic function
2834 2834 \family typewriter
2835 2835 %color_info
2836 2836 \family default
2837 2837 allows you to toggle this interactively for testing.
2838 2838 \layout List
2839 2839 \labelwidthstring 00.00.0000
2840 2840
2841 2841
2842 2842 \family typewriter
2843 2843 \series bold
2844 2844 -[no]debug
2845 2845 \family default
2846 2846 \series default
2847 2847 : Show information about the loading process.
2848 2848 Very useful to pin down problems with your configuration files or to get
2849 2849 details about session restores.
2850 2850 \layout List
2851 2851 \labelwidthstring 00.00.0000
2852 2852
2853 2853
2854 2854 \family typewriter
2855 2855 \series bold
2856 2856 -[no]deep_reload
2857 2857 \series default
2858 2858 :
2859 2859 \family default
2860 2860 IPython can use the
2861 2861 \family typewriter
2862 2862 deep_reload
2863 2863 \family default
2864 2864 module which reloads changes in modules recursively (it replaces the
2865 2865 \family typewriter
2866 2866 reload()
2867 2867 \family default
2868 2868 function, so you don't need to change anything to use it).
2869 2869
2870 2870 \family typewriter
2871 2871 deep_reload()
2872 2872 \family default
2873 2873 forces a full reload of modules whose code may have changed, which the
2874 2874 default
2875 2875 \family typewriter
2876 2876 reload()
2877 2877 \family default
2878 2878 function does not.
2879 2879 \layout List
2880 2880 \labelwidthstring 00.00.0000
2881 2881
2882 2882 \SpecialChar ~
2883 2883 When deep_reload is off, IPython will use the normal
2884 2884 \family typewriter
2885 2885 reload()
2886 2886 \family default
2887 2887 , but deep_reload will still be available as
2888 2888 \family typewriter
2889 2889 dreload()
2890 2890 \family default
2891 2891 .
2892 2892 This feature is off by default [which means that you have both normal
2893 2893 \family typewriter
2894 2894 reload()
2895 2895 \family default
2896 2896 and
2897 2897 \family typewriter
2898 2898 dreload()
2899 2899 \family default
2900 2900 ].
2901 2901 \layout List
2902 2902 \labelwidthstring 00.00.0000
2903 2903
2904 2904
2905 2905 \family typewriter
2906 2906 \series bold
2907 2907 -editor\SpecialChar ~
2908 2908 <name>
2909 2909 \family default
2910 2910 \series default
2911 2911 : Which editor to use with the
2912 2912 \family typewriter
2913 2913 %edit
2914 2914 \family default
2915 2915 command.
2916 2916 By default, IPython will honor your
2917 2917 \family typewriter
2918 2918 EDITOR
2919 2919 \family default
2920 2920 environment variable (if not set, vi is the Unix default and notepad the
2921 2921 Windows one).
2922 2922 Since this editor is invoked on the fly by IPython and is meant for editing
2923 2923 small code snippets, you may want to use a small, lightweight editor here
2924 2924 (in case your default
2925 2925 \family typewriter
2926 2926 EDITOR
2927 2927 \family default
2928 2928 is something like Emacs).
2929 2929 \layout List
2930 2930 \labelwidthstring 00.00.0000
2931 2931
2932 2932
2933 2933 \family typewriter
2934 2934 \series bold
2935 2935 -ipythondir\SpecialChar ~
2936 2936 <name>
2937 2937 \series default
2938 2938 :
2939 2939 \family default
2940 2940 name of your IPython configuration directory
2941 2941 \family typewriter
2942 2942 IPYTHONDIR
2943 2943 \family default
2944 2944 .
2945 2945 This can also be specified through the environment variable
2946 2946 \family typewriter
2947 2947 IPYTHONDIR
2948 2948 \family default
2949 2949 .
2950 2950 \layout List
2951 2951 \labelwidthstring 00.00.0000
2952 2952
2953 2953
2954 2954 \family typewriter
2955 2955 \series bold
2956 2956 -log|l
2957 2957 \family default
2958 2958 \series default
2959 2959 : generate a log file of all input.
2960 Defaults to
2960 The file is named
2961 2961 \family typewriter
2962 $IPYTHONDIR/log
2962 ipython_log.py
2963 2963 \family default
2964 .
2964 in your current directory (which prevents logs from multiple IPython sessions
2965 from trampling each other).
2965 2966 You can use this to later restore a session by loading your logfile as
2966 2967 a file to be executed with option
2967 2968 \family typewriter
2968 2969 -logplay
2969 2970 \family default
2970 2971 (see below).
2971 2972 \layout List
2972 2973 \labelwidthstring 00.00.0000
2973 2974
2974 2975
2975 2976 \family typewriter
2976 2977 \series bold
2977 2978 -logfile|lf\SpecialChar ~
2978 2979 <name>
2979 2980 \series default
2980 2981 :
2981 2982 \family default
2982 2983 specify the name of your logfile.
2983 2984 \layout List
2984 2985 \labelwidthstring 00.00.0000
2985 2986
2986 2987
2987 2988 \family typewriter
2988 2989 \series bold
2989 2990 -logplay|lp\SpecialChar ~
2990 2991 <name>
2991 2992 \series default
2992 2993 :
2993 2994 \family default
2994 2995 you can replay a previous log.
2995 2996 For restoring a session as close as possible to the state you left it in,
2996 2997 use this option (don't just run the logfile).
2997 2998 With
2998 2999 \family typewriter
2999 3000 -logplay
3000 3001 \family default
3001 3002 , IPython will try to reconstruct the previous working environment in full,
3002 3003 not just execute the commands in the logfile.
3003 3004 \layout List
3004 3005 \labelwidthstring 00.00.0000
3005 3006
3006 3007 \SpecialChar ~
3007 3008 When a session is restored, logging is automatically turned on again with
3008 3009 the name of the logfile it was invoked with (it is read from the log header).
3009 3010 So once you've turned logging on for a session, you can quit IPython and
3010 3011 reload it as many times as you want and it will continue to log its history
3011 3012 and restore from the beginning every time.
3012 3013 \layout List
3013 3014 \labelwidthstring 00.00.0000
3014 3015
3015 3016 \SpecialChar ~
3016 3017 Caveats: there are limitations in this option.
3017 3018 The history variables
3018 3019 \family typewriter
3019 3020 _i*
3020 3021 \family default
3021 3022 ,
3022 3023 \family typewriter
3023 3024 _*
3024 3025 \family default
3025 3026 and
3026 3027 \family typewriter
3027 3028 _dh
3028 3029 \family default
3029 3030 don't get restored properly.
3030 3031 In the future we will try to implement full session saving by writing and
3031 3032 retrieving a 'snapshot' of the memory state of IPython.
3032 3033 But our first attempts failed because of inherent limitations of Python's
3033 3034 Pickle module, so this may have to wait.
3034 3035 \layout List
3035 3036 \labelwidthstring 00.00.0000
3036 3037
3037 3038
3038 3039 \family typewriter
3039 3040 \series bold
3040 3041 -[no]messages
3041 3042 \series default
3042 3043 :
3043 3044 \family default
3044 3045 Print messages which IPython collects about its startup process (default
3045 3046 on).
3046 3047 \layout List
3047 3048 \labelwidthstring 00.00.0000
3048 3049
3049 3050
3050 3051 \family typewriter
3051 3052 \series bold
3052 3053 -[no]pdb
3053 3054 \family default
3054 3055 \series default
3055 3056 : Automatically call the pdb debugger after every uncaught exception.
3056 3057 If you are used to debugging using pdb, this puts you automatically inside
3057 3058 of it after any call (either in IPython or in code called by it) which
3058 3059 triggers an exception which goes uncaught.
3059 3060 \layout List
3060 3061 \labelwidthstring 00.00.0000
3061 3062
3062 3063
3063 3064 \family typewriter
3064 3065 \series bold
3065 3066 -[no]pprint
3066 3067 \series default
3067 3068 :
3068 3069 \family default
3069 3070 ipython can optionally use the pprint (pretty printer) module for displaying
3070 3071 results.
3071 3072 pprint tends to give a nicer display of nested data structures.
3072 3073 If you like it, you can turn it on permanently in your config file (default
3073 3074 off).
3074 3075 \layout List
3075 3076 \labelwidthstring 00.00.0000
3076 3077
3077 3078
3078 3079 \family typewriter
3079 3080 \series bold
3080 3081 -profile|p <name>
3081 3082 \series default
3082 3083 :
3083 3084 \family default
3084 3085 assume that your config file is
3085 3086 \family typewriter
3086 3087 ipythonrc-<name>
3087 3088 \family default
3088 3089 (looks in current dir first, then in
3089 3090 \family typewriter
3090 3091 IPYTHONDIR
3091 3092 \family default
3092 3093 ).
3093 3094 This is a quick way to keep and load multiple config files for different
3094 3095 tasks, especially if you use the include option of config files.
3095 3096 You can keep a basic
3096 3097 \family typewriter
3097 3098 IPYTHONDIR/ipythonrc
3098 3099 \family default
3099 3100 file and then have other 'profiles' which include this one and load extra
3100 3101 things for particular tasks.
3101 3102 For example:
3102 3103 \layout List
3103 3104 \labelwidthstring 00.00.0000
3104 3105
3105 3106
3106 3107 \family typewriter
3107 3108 \SpecialChar ~
3108 3109
3109 3110 \family default
3110 3111 1.
3111 3112
3112 3113 \family typewriter
3113 3114 $HOME/.ipython/ipythonrc
3114 3115 \family default
3115 3116 : load basic things you always want.
3116 3117 \layout List
3117 3118 \labelwidthstring 00.00.0000
3118 3119
3119 3120
3120 3121 \family typewriter
3121 3122 \SpecialChar ~
3122 3123
3123 3124 \family default
3124 3125 2.
3125 3126
3126 3127 \family typewriter
3127 3128 $HOME/.ipython/ipythonrc-math
3128 3129 \family default
3129 3130 : load (1) and basic math-related modules.
3130 3131
3131 3132 \layout List
3132 3133 \labelwidthstring 00.00.0000
3133 3134
3134 3135
3135 3136 \family typewriter
3136 3137 \SpecialChar ~
3137 3138
3138 3139 \family default
3139 3140 3.
3140 3141
3141 3142 \family typewriter
3142 3143 $HOME/.ipython/ipythonrc-numeric
3143 3144 \family default
3144 3145 : load (1) and Numeric and plotting modules.
3145 3146 \layout List
3146 3147 \labelwidthstring 00.00.0000
3147 3148
3148 3149 \SpecialChar ~
3149 3150 Since it is possible to create an endless loop by having circular file
3150 3151 inclusions, IPython will stop if it reaches 15 recursive inclusions.
3151 3152 \layout List
3152 3153 \labelwidthstring 00.00.0000
3153 3154
3154 3155
3155 3156 \family typewriter
3156 3157 \series bold
3157 3158 -prompt_in1|pi1\SpecialChar ~
3158 3159 <string>:
3159 3160 \family default
3160 3161 \series default
3161 3162 Specify the string used for input prompts.
3162 3163 Note that if you are using numbered prompts, the number is represented
3163 3164 with a '
3164 3165 \backslash
3165 3166 #' in the string.
3166 3167 Don't forget to quote strings with spaces embedded in them.
3167 3168 Default: '
3168 3169 \family typewriter
3169 3170 In\SpecialChar ~
3170 3171 [
3171 3172 \backslash
3172 3173 #]:
3173 3174 \family default
3174 3175 '.
3175 3176 Sec.\SpecialChar ~
3176 3177
3177 3178 \begin_inset LatexCommand \ref{sec:prompts}
3178 3179
3179 3180 \end_inset
3180 3181
3181 3182 discusses in detail all the available escapes to customize your prompts.
3182 3183 \layout List
3183 3184 \labelwidthstring 00.00.0000
3184 3185
3185 3186
3186 3187 \family typewriter
3187 3188 \series bold
3188 3189 -prompt_in2|pi2\SpecialChar ~
3189 3190 <string>:
3190 3191 \family default
3191 3192 \series default
3192 3193 Similar to the previous option, but used for the continuation prompts.
3193 3194 The special sequence '
3194 3195 \family typewriter
3195 3196
3196 3197 \backslash
3197 3198 D
3198 3199 \family default
3199 3200 ' is similar to '
3200 3201 \family typewriter
3201 3202
3202 3203 \backslash
3203 3204 #
3204 3205 \family default
3205 3206 ', but with all digits replaced dots (so you can have your continuation
3206 3207 prompt aligned with your input prompt).
3207 3208 Default: '
3208 3209 \family typewriter
3209 3210 \SpecialChar ~
3210 3211 \SpecialChar ~
3211 3212 \SpecialChar ~
3212 3213 .
3213 3214 \backslash
3214 3215 D.:
3215 3216 \family default
3216 3217 ' (note three spaces at the start for alignment with '
3217 3218 \family typewriter
3218 3219 In\SpecialChar ~
3219 3220 [
3220 3221 \backslash
3221 3222 #]
3222 3223 \family default
3223 3224 ').
3224 3225 \layout List
3225 3226 \labelwidthstring 00.00.0000
3226 3227
3227 3228
3228 3229 \family typewriter
3229 3230 \series bold
3230 3231 -prompt_out|po\SpecialChar ~
3231 3232 <string>:
3232 3233 \family default
3233 3234 \series default
3234 3235 String used for output prompts, also uses numbers like
3235 3236 \family typewriter
3236 3237 prompt_in1
3237 3238 \family default
3238 3239 .
3239 3240 Default: '
3240 3241 \family typewriter
3241 3242 Out[
3242 3243 \backslash
3243 3244 #]:
3244 3245 \family default
3245 3246 '
3246 3247 \layout List
3247 3248 \labelwidthstring 00.00.0000
3248 3249
3249 3250
3250 3251 \family typewriter
3251 3252 \series bold
3252 3253 -quick
3253 3254 \family default
3254 3255 \series default
3255 3256 : start in bare bones mode (no config file loaded).
3256 3257 \layout List
3257 3258 \labelwidthstring 00.00.0000
3258 3259
3259 3260
3260 3261 \family typewriter
3261 3262 \series bold
3262 3263 -rcfile\SpecialChar ~
3263 3264 <name>
3264 3265 \series default
3265 3266 :
3266 3267 \family default
3267 3268 name of your IPython resource configuration file.
3268 3269 Normally IPython loads ipythonrc (from current directory) or
3269 3270 \family typewriter
3270 3271 IPYTHONDIR/ipythonrc
3271 3272 \family default
3272 3273 .
3273 3274 \layout List
3274 3275 \labelwidthstring 00.00.0000
3275 3276
3276 3277 \SpecialChar ~
3277 3278 If the loading of your config file fails, IPython starts with a bare bones
3278 3279 configuration (no modules loaded at all).
3279 3280 \layout List
3280 3281 \labelwidthstring 00.00.0000
3281 3282
3282 3283
3283 3284 \family typewriter
3284 3285 \series bold
3285 3286 -[no]readline
3286 3287 \family default
3287 3288 \series default
3288 3289 : use the readline library, which is needed to support name completion and
3289 3290 command history, among other things.
3290 3291 It is enabled by default, but may cause problems for users of X/Emacs in
3291 3292 Python comint or shell buffers.
3292 3293 \layout List
3293 3294 \labelwidthstring 00.00.0000
3294 3295
3295 3296 \SpecialChar ~
3296 3297 Note that X/Emacs 'eterm' buffers (opened with
3297 3298 \family typewriter
3298 3299 M-x\SpecialChar ~
3299 3300 term
3300 3301 \family default
3301 3302 ) support IPython's readline and syntax coloring fine, only 'emacs' (
3302 3303 \family typewriter
3303 3304 M-x\SpecialChar ~
3304 3305 shell
3305 3306 \family default
3306 3307 and
3307 3308 \family typewriter
3308 3309 C-c\SpecialChar ~
3309 3310 !
3310 3311 \family default
3311 3312 ) buffers do not.
3312 3313 \layout List
3313 3314 \labelwidthstring 00.00.0000
3314 3315
3315 3316
3316 3317 \family typewriter
3317 3318 \series bold
3318 3319 -screen_length|sl\SpecialChar ~
3319 3320 <n>
3320 3321 \series default
3321 3322 :
3322 3323 \family default
3323 3324 number of lines of your screen.
3324 3325 This is used to control printing of very long strings.
3325 3326 Strings longer than this number of lines will be sent through a pager instead
3326 3327 of directly printed.
3327 3328 \layout List
3328 3329 \labelwidthstring 00.00.0000
3329 3330
3330 3331 \SpecialChar ~
3331 3332 The default value for this is 0, which means IPython will auto-detect your
3332 3333 screen size every time it needs to print certain potentially long strings
3333 3334 (this doesn't change the behavior of the 'print' keyword, it's only triggered
3334 3335 internally).
3335 3336 If for some reason this isn't working well (it needs curses support), specify
3336 3337 it yourself.
3337 3338 Otherwise don't change the default.
3338 3339 \layout List
3339 3340 \labelwidthstring 00.00.0000
3340 3341
3341 3342
3342 3343 \family typewriter
3343 3344 \series bold
3344 3345 -separate_in|si\SpecialChar ~
3345 3346 <string>
3346 3347 \series default
3347 3348 :
3348 3349 \family default
3349 3350 separator before input prompts.
3350 3351 Default: '
3351 3352 \family typewriter
3352 3353
3353 3354 \backslash
3354 3355 n
3355 3356 \family default
3356 3357 '
3357 3358 \layout List
3358 3359 \labelwidthstring 00.00.0000
3359 3360
3360 3361
3361 3362 \family typewriter
3362 3363 \series bold
3363 3364 -separate_out|so\SpecialChar ~
3364 3365 <string>
3365 3366 \family default
3366 3367 \series default
3367 3368 : separator before output prompts.
3368 3369 Default: nothing.
3369 3370 \layout List
3370 3371 \labelwidthstring 00.00.0000
3371 3372
3372 3373
3373 3374 \family typewriter
3374 3375 \series bold
3375 3376 -separate_out2|so2\SpecialChar ~
3376 3377 <string>
3377 3378 \series default
3378 3379 :
3379 3380 \family default
3380 3381 separator after output prompts.
3381 3382 Default: nothing.
3382 3383 \layout List
3383 3384 \labelwidthstring 00.00.0000
3384 3385
3385 3386 \SpecialChar ~
3386 3387 For these three options, use the value 0 to specify no separator.
3387 3388 \layout List
3388 3389 \labelwidthstring 00.00.0000
3389 3390
3390 3391
3391 3392 \family typewriter
3392 3393 \series bold
3393 3394 -nosep
3394 3395 \series default
3395 3396 :
3396 3397 \family default
3397 3398 shorthand for
3398 3399 \family typewriter
3399 3400 '-SeparateIn 0 -SeparateOut 0 -SeparateOut2 0'
3400 3401 \family default
3401 3402 .
3402 3403 Simply removes all input/output separators.
3403 3404 \layout List
3404 3405 \labelwidthstring 00.00.0000
3405 3406
3406 3407
3407 3408 \family typewriter
3408 3409 \series bold
3409 3410 -upgrade
3410 3411 \family default
3411 3412 \series default
3412 3413 : allows you to upgrade your
3413 3414 \family typewriter
3414 3415 IPYTHONDIR
3415 3416 \family default
3416 3417 configuration when you install a new version of IPython.
3417 3418 Since new versions may include new command line options or example files,
3418 3419 this copies updated ipythonrc-type files.
3419 3420 However, it backs up (with a
3420 3421 \family typewriter
3421 3422 .old
3422 3423 \family default
3423 3424 extension) all files which it overwrites so that you can merge back any
3424 3425 customizations you might have in your personal files.
3425 3426 \layout List
3426 3427 \labelwidthstring 00.00.0000
3427 3428
3428 3429
3429 3430 \family typewriter
3430 3431 \series bold
3431 3432 -Version
3432 3433 \series default
3433 3434 :
3434 3435 \family default
3435 3436 print version information and exit.
3436 3437 \layout List
3437 3438 \labelwidthstring 00.00.0000
3438 3439
3439 3440
3440 3441 \family typewriter
3441 3442 \series bold
3442 3443 -xmode <modename>
3443 3444 \series default
3444 3445 :
3445 3446 \family default
3446 3447 Mode for exception reporting.
3447 3448 \layout List
3448 3449 \labelwidthstring 00.00.0000
3449 3450
3450 3451 \SpecialChar ~
3451 3452 Valid modes: Plain, Context and Verbose.
3452 3453 \layout List
3453 3454 \labelwidthstring 00.00.0000
3454 3455
3455 3456 \SpecialChar ~
3456 3457 Plain: similar to python's normal traceback printing.
3457 3458 \layout List
3458 3459 \labelwidthstring 00.00.0000
3459 3460
3460 3461 \SpecialChar ~
3461 3462 Context: prints 5 lines of context source code around each line in the
3462 3463 traceback.
3463 3464 \layout List
3464 3465 \labelwidthstring 00.00.0000
3465 3466
3466 3467 \SpecialChar ~
3467 3468 Verbose: similar to Context, but additionally prints the variables currently
3468 3469 visible where the exception happened (shortening their strings if too long).
3469 3470 This can potentially be very slow, if you happen to have a huge data structure
3470 3471 whose string representation is complex to compute.
3471 3472 Your computer may appear to freeze for a while with cpu usage at 100%.
3472 3473 If this occurs, you can cancel the traceback with Ctrl-C (maybe hitting
3473 3474 it more than once).
3474 3475 \layout Section
3475 3476
3476 3477 Interactive use
3477 3478 \layout Standard
3478 3479
3479 3480
3480 3481 \series bold
3481 3482 Warning
3482 3483 \series default
3483 3484 : IPython relies on the existence of a global variable called
3484 3485 \family typewriter
3485 3486 __IP
3486 3487 \family default
3487 3488 which controls the shell itself.
3488 3489 If you redefine
3489 3490 \family typewriter
3490 3491 __IP
3491 3492 \family default
3492 3493 to anything, bizarre behavior will quickly occur.
3493 3494 \layout Standard
3494 3495
3495 3496 Other than the above warning, IPython is meant to work as a drop-in replacement
3496 3497 for the standard interactive interpreter.
3497 3498 As such, any code which is valid python should execute normally under IPython
3498 3499 (cases where this is not true should be reported as bugs).
3499 3500 It does, however, offer many features which are not available at a standard
3500 3501 python prompt.
3501 3502 What follows is a list of these.
3502 3503 \layout Subsection
3503 3504
3504 3505 Caution for Windows users
3505 3506 \layout Standard
3506 3507
3507 3508 Windows, unfortunately, uses the `
3508 3509 \family typewriter
3509 3510
3510 3511 \backslash
3511 3512
3512 3513 \family default
3513 3514 ' character as a path separator.
3514 3515 This is a terrible choice, because `
3515 3516 \family typewriter
3516 3517
3517 3518 \backslash
3518 3519
3519 3520 \family default
3520 3521 ' also represents the escape character in most modern programming languages,
3521 3522 including Python.
3522 3523 For this reason, issuing many of the commands discussed below (especially
3523 3524 magics which affect the filesystem) with `
3524 3525 \family typewriter
3525 3526
3526 3527 \backslash
3527 3528
3528 3529 \family default
3529 3530 ' in them will cause strange errors.
3530 3531 \layout Standard
3531 3532
3532 3533 A partial solution is to use instead the `
3533 3534 \family typewriter
3534 3535 /
3535 3536 \family default
3536 3537 ' character as a path separator, which Windows recognizes in
3537 3538 \emph on
3538 3539 most
3539 3540 \emph default
3540 3541 situations.
3541 3542 However, in Windows commands `
3542 3543 \family typewriter
3543 3544 /
3544 3545 \family default
3545 3546 ' flags options, so you can not use it for the root directory.
3546 3547 This means that paths beginning at the root must be typed in a contrived
3547 3548 manner like:
3548 3549 \newline
3549 3550
3550 3551 \family typewriter
3551 3552 %copy
3552 3553 \backslash
3553 3554 opt/foo/bar.txt
3554 3555 \backslash
3555 3556 tmp
3556 3557 \layout Standard
3557 3558
3558 3559 There is no sensible thing IPython can do to truly work around this flaw
3559 3560 in Windows
3560 3561 \begin_inset Foot
3561 3562 collapsed true
3562 3563
3563 3564 \layout Standard
3564 3565
3565 3566 If anyone comes up with a
3566 3567 \emph on
3567 3568 clean
3568 3569 \emph default
3569 3570 solution which works consistently and does not negatively impact other
3570 3571 platforms at all, I'll gladly accept a patch.
3571 3572 \end_inset
3572 3573
3573 3574 .
3574 3575 \layout Subsection
3575 3576
3576 3577
3577 3578 \begin_inset LatexCommand \label{sec:magic}
3578 3579
3579 3580 \end_inset
3580 3581
3581 3582 Magic command system
3582 3583 \layout Standard
3583 3584
3584 3585 IPython will treat any line whose first character is a
3585 3586 \family typewriter
3586 3587 %
3587 3588 \family default
3588 3589 as a special call to a 'magic' function.
3589 3590 These allow you to control the behavior of IPython itself, plus a lot of
3590 3591 system-type features.
3591 3592 They are all prefixed with a
3592 3593 \family typewriter
3593 3594 %
3594 3595 \family default
3595 3596 character, but parameters are given without parentheses or quotes.
3596 3597 \layout Standard
3597 3598
3598 3599 Example: typing
3599 3600 \family typewriter
3600 3601 '%cd mydir'
3601 3602 \family default
3602 3603 (without the quotes) changes you working directory to
3603 3604 \family typewriter
3604 3605 'mydir'
3605 3606 \family default
3606 3607 , if it exists.
3607 3608 \layout Standard
3608 3609
3609 3610 If you have 'automagic' enabled (in your
3610 3611 \family typewriter
3611 3612 ipythonrc
3612 3613 \family default
3613 3614 file, via the command line option
3614 3615 \family typewriter
3615 3616 -automagic
3616 3617 \family default
3617 3618 or with the
3618 3619 \family typewriter
3619 3620 %automagic
3620 3621 \family default
3621 3622 function), you don't need to type in the
3622 3623 \family typewriter
3623 3624 %
3624 3625 \family default
3625 3626 explicitly.
3626 3627 IPython will scan its internal list of magic functions and call one if
3627 3628 it exists.
3628 3629 With automagic on you can then just type '
3629 3630 \family typewriter
3630 3631 cd mydir
3631 3632 \family default
3632 3633 ' to go to directory '
3633 3634 \family typewriter
3634 3635 mydir
3635 3636 \family default
3636 3637 '.
3637 3638 The automagic system has the lowest possible precedence in name searches,
3638 3639 so defining an identifier with the same name as an existing magic function
3639 3640 will shadow it for automagic use.
3640 3641 You can still access the shadowed magic function by explicitly using the
3641 3642
3642 3643 \family typewriter
3643 3644 %
3644 3645 \family default
3645 3646 character at the beginning of the line.
3646 3647 \layout Standard
3647 3648
3648 3649 An example (with automagic on) should clarify all this:
3649 3650 \layout LyX-Code
3650 3651
3651 3652 In [1]: cd ipython # %cd is called by automagic
3652 3653 \layout LyX-Code
3653 3654
3654 3655 /home/fperez/ipython
3655 3656 \layout LyX-Code
3656 3657
3657 3658 In [2]: cd=1 # now cd is just a variable
3658 3659 \layout LyX-Code
3659 3660
3660 3661 In [3]: cd ..
3661 3662 # and doesn't work as a function anymore
3662 3663 \layout LyX-Code
3663 3664
3664 3665 ------------------------------------------------------------
3665 3666 \layout LyX-Code
3666 3667
3667 3668 File "<console>", line 1
3668 3669 \layout LyX-Code
3669 3670
3670 3671 cd ..
3671 3672 \layout LyX-Code
3672 3673
3673 3674 ^
3674 3675 \layout LyX-Code
3675 3676
3676 3677 SyntaxError: invalid syntax
3677 3678 \layout LyX-Code
3678 3679
3679 3680 \layout LyX-Code
3680 3681
3681 3682 In [4]: %cd ..
3682 3683 # but %cd always works
3683 3684 \layout LyX-Code
3684 3685
3685 3686 /home/fperez
3686 3687 \layout LyX-Code
3687 3688
3688 3689 In [5]: del cd # if you remove the cd variable
3689 3690 \layout LyX-Code
3690 3691
3691 3692 In [6]: cd ipython # automagic can work again
3692 3693 \layout LyX-Code
3693 3694
3694 3695 /home/fperez/ipython
3695 3696 \layout Standard
3696 3697
3697 3698 You can define your own magic functions to extend the system.
3698 3699 The following is a snippet of code which shows how to do it.
3699 3700 It is provided as file
3700 3701 \family typewriter
3701 3702 example-magic.py
3702 3703 \family default
3703 3704 in the examples directory:
3704 3705 \layout Standard
3705 3706
3706 3707
3707 3708 \begin_inset ERT
3708 3709 status Open
3709 3710
3710 3711 \layout Standard
3711 3712
3712 3713 \backslash
3713 3714 codelist{examples/example-magic.py}
3714 3715 \end_inset
3715 3716
3716 3717
3717 3718 \layout Standard
3718 3719
3719 3720 You can also define your own aliased names for magic functions.
3720 3721 In your
3721 3722 \family typewriter
3722 3723 ipythonrc
3723 3724 \family default
3724 3725 file, placing a line like:
3725 3726 \layout Standard
3726 3727
3727 3728
3728 3729 \family typewriter
3729 3730 execute __IP.magic_cl = __IP.magic_clear
3730 3731 \layout Standard
3731 3732
3732 3733 will define
3733 3734 \family typewriter
3734 3735 %cl
3735 3736 \family default
3736 3737 as a new name for
3737 3738 \family typewriter
3738 3739 %clear
3739 3740 \family default
3740 3741 .
3741 3742 \layout Standard
3742 3743
3743 3744 Type
3744 3745 \family typewriter
3745 3746 %magic
3746 3747 \family default
3747 3748 for more information, including a list of all available magic functions
3748 3749 at any time and their docstrings.
3749 3750 You can also type
3750 3751 \family typewriter
3751 3752 %magic_function_name?
3752 3753 \family default
3753 3754 (see sec.
3754 3755
3755 3756 \begin_inset LatexCommand \ref{sec:dyn-object-info}
3756 3757
3757 3758 \end_inset
3758 3759
3759 3760 for information on the
3760 3761 \family typewriter
3761 3762 '?'
3762 3763 \family default
3763 3764 system) to get information about any particular magic function you are
3764 3765 interested in.
3765 3766 \layout Subsubsection
3766 3767
3767 3768 Magic commands
3768 3769 \layout Standard
3769 3770
3770 3771 The rest of this section is automatically generated for each release from
3771 3772 the docstrings in the IPython code.
3772 3773 Therefore the formatting is somewhat minimal, but this method has the advantage
3773 3774 of having information always in sync with the code.
3774 3775 \layout Standard
3775 3776
3776 3777 A list of all the magic commands available in IPython's
3777 3778 \emph on
3778 3779 default
3779 3780 \emph default
3780 3781 installation follows.
3781 3782 This is similar to what you'll see by simply typing
3782 3783 \family typewriter
3783 3784 %magic
3784 3785 \family default
3785 3786 at the prompt, but that will also give you information about magic commands
3786 3787 you may have added as part of your personal customizations.
3787 3788 \layout Standard
3788 3789
3789 3790
3790 3791 \begin_inset Include \input{magic.tex}
3791 3792 preview false
3792 3793
3793 3794 \end_inset
3794 3795
3795 3796
3796 3797 \layout Subsection
3797 3798
3798 3799 Access to the standard Python help
3799 3800 \layout Standard
3800 3801
3801 3802 As of Python 2.1, a help system is available with access to object docstrings
3802 3803 and the Python manuals.
3803 3804 Simply type
3804 3805 \family typewriter
3805 3806 'help'
3806 3807 \family default
3807 3808 (no quotes) to access it.
3808 3809 You can also type
3809 3810 \family typewriter
3810 3811 help(object)
3811 3812 \family default
3812 3813 to obtain information about a given object, and
3813 3814 \family typewriter
3814 3815 help('keyword')
3815 3816 \family default
3816 3817 for information on a keyword.
3817 3818 As noted in sec.
3818 3819
3819 3820 \begin_inset LatexCommand \ref{sec:help-access}
3820 3821
3821 3822 \end_inset
3822 3823
3823 3824 , you need to properly configure your environment variable
3824 3825 \family typewriter
3825 3826 PYTHONDOCS
3826 3827 \family default
3827 3828 for this feature to work correctly.
3828 3829 \layout Subsection
3829 3830
3830 3831
3831 3832 \begin_inset LatexCommand \label{sec:dyn-object-info}
3832 3833
3833 3834 \end_inset
3834 3835
3835 3836 Dynamic object information
3836 3837 \layout Standard
3837 3838
3838 3839 Typing
3839 3840 \family typewriter
3840 3841 ?word
3841 3842 \family default
3842 3843 or
3843 3844 \family typewriter
3844 3845 word?
3845 3846 \family default
3846 3847 prints detailed information about an object.
3847 3848 If certain strings in the object are too long (docstrings, code, etc.) they
3848 3849 get snipped in the center for brevity.
3849 3850 This system gives access variable types and values, full source code for
3850 3851 any object (if available), function prototypes and other useful information.
3851 3852 \layout Standard
3852 3853
3853 3854 Typing
3854 3855 \family typewriter
3855 3856 ??word
3856 3857 \family default
3857 3858 or
3858 3859 \family typewriter
3859 3860 word??
3860 3861 \family default
3861 3862 gives access to the full information without snipping long strings.
3862 3863 Long strings are sent to the screen through the
3863 3864 \family typewriter
3864 3865 less
3865 3866 \family default
3866 3867 pager if longer than the screen and printed otherwise.
3867 3868 On systems lacking the
3868 3869 \family typewriter
3869 3870 less
3870 3871 \family default
3871 3872 command, IPython uses a very basic internal pager.
3872 3873 \layout Standard
3873 3874
3874 3875 The following magic functions are particularly useful for gathering information
3875 3876 about your working environment.
3876 3877 You can get more details by typing
3877 3878 \family typewriter
3878 3879 %magic
3879 3880 \family default
3880 3881 or querying them individually (use
3881 3882 \family typewriter
3882 3883 %function_name?
3883 3884 \family default
3884 3885 with or without the
3885 3886 \family typewriter
3886 3887 %
3887 3888 \family default
3888 3889 ), this is just a summary:
3889 3890 \layout List
3890 3891 \labelwidthstring 00.00.0000
3891 3892
3892 3893
3893 3894 \family typewriter
3894 3895 \series bold
3895 3896 %pdoc\SpecialChar ~
3896 3897 <object>
3897 3898 \family default
3898 3899 \series default
3899 3900 : Print (or run through a pager if too long) the docstring for an object.
3900 3901 If the given object is a class, it will print both the class and the constructo
3901 3902 r docstrings.
3902 3903 \layout List
3903 3904 \labelwidthstring 00.00.0000
3904 3905
3905 3906
3906 3907 \family typewriter
3907 3908 \series bold
3908 3909 %pdef\SpecialChar ~
3909 3910 <object>
3910 3911 \family default
3911 3912 \series default
3912 3913 : Print the definition header for any callable object.
3913 3914 If the object is a class, print the constructor information.
3914 3915 \layout List
3915 3916 \labelwidthstring 00.00.0000
3916 3917
3917 3918
3918 3919 \family typewriter
3919 3920 \series bold
3920 3921 %psource\SpecialChar ~
3921 3922 <object>
3922 3923 \family default
3923 3924 \series default
3924 3925 : Print (or run through a pager if too long) the source code for an object.
3925 3926 \layout List
3926 3927 \labelwidthstring 00.00.0000
3927 3928
3928 3929
3929 3930 \family typewriter
3930 3931 \series bold
3931 3932 %pfile\SpecialChar ~
3932 3933 <object>
3933 3934 \family default
3934 3935 \series default
3935 3936 : Show the entire source file where an object was defined via a pager, opening
3936 3937 it at the line where the object definition begins.
3937 3938 \layout List
3938 3939 \labelwidthstring 00.00.0000
3939 3940
3940 3941
3941 3942 \family typewriter
3942 3943 \series bold
3943 3944 %who/%whos
3944 3945 \family default
3945 3946 \series default
3946 3947 : These functions give information about identifiers you have defined interactiv
3947 3948 ely (not things you loaded or defined in your configuration files).
3948 3949
3949 3950 \family typewriter
3950 3951 %who
3951 3952 \family default
3952 3953 just prints a list of identifiers and
3953 3954 \family typewriter
3954 3955 %whos
3955 3956 \family default
3956 3957 prints a table with some basic details about each identifier.
3957 3958 \layout Standard
3958 3959
3959 3960 Note that the dynamic object information functions (
3960 3961 \family typewriter
3961 3962 ?/??, %pdoc, %pfile, %pdef, %psource
3962 3963 \family default
3963 3964 ) give you access to documentation even on things which are not really defined
3964 3965 as separate identifiers.
3965 3966 Try for example typing
3966 3967 \family typewriter
3967 3968 {}.get?
3968 3969 \family default
3969 3970 or after doing
3970 3971 \family typewriter
3971 3972 import os
3972 3973 \family default
3973 3974 , type
3974 3975 \family typewriter
3975 3976 os.path.abspath??
3976 3977 \family default
3977 3978 .
3978 3979 \layout Subsection
3979 3980
3980 3981
3981 3982 \begin_inset LatexCommand \label{sec:readline}
3982 3983
3983 3984 \end_inset
3984 3985
3985 3986 Readline-based features
3986 3987 \layout Standard
3987 3988
3988 3989 These features require the GNU readline library, so they won't work if your
3989 3990 Python installation lacks readline support.
3990 3991 We will first describe the default behavior IPython uses, and then how
3991 3992 to change it to suit your preferences.
3992 3993 \layout Subsubsection
3993 3994
3994 3995 Command line completion
3995 3996 \layout Standard
3996 3997
3997 3998 At any time, hitting TAB will complete any available python commands or
3998 3999 variable names, and show you a list of the possible completions if there's
3999 4000 no unambiguous one.
4000 4001 It will also complete filenames in the current directory if no python names
4001 4002 match what you've typed so far.
4002 4003 \layout Subsubsection
4003 4004
4004 4005 Search command history
4005 4006 \layout Standard
4006 4007
4007 4008 IPython provides two ways for searching through previous input and thus
4008 4009 reduce the need for repetitive typing:
4009 4010 \layout Enumerate
4010 4011
4011 4012 Start typing, and then use
4012 4013 \family typewriter
4013 4014 Ctrl-p
4014 4015 \family default
4015 4016 (previous,up) and
4016 4017 \family typewriter
4017 4018 Ctrl-n
4018 4019 \family default
4019 4020 (next,down) to search through only the history items that match what you've
4020 4021 typed so far.
4021 4022 If you use
4022 4023 \family typewriter
4023 4024 Ctrl-p/Ctrl-n
4024 4025 \family default
4025 4026 at a blank prompt, they just behave like normal arrow keys.
4026 4027 \layout Enumerate
4027 4028
4028 4029 Hit
4029 4030 \family typewriter
4030 4031 Ctrl-r
4031 4032 \family default
4032 4033 : opens a search prompt.
4033 4034 Begin typing and the system searches your history for lines that contain
4034 4035 what you've typed so far, completing as much as it can.
4035 4036 \layout Subsubsection
4036 4037
4037 4038 Persistent command history across sessions
4038 4039 \layout Standard
4039 4040
4040 4041 IPython will save your input history when it leaves and reload it next time
4041 4042 you restart it.
4042 4043 By default, the history file is named
4043 4044 \family typewriter
4044 4045 $IPYTHONDIR/history
4045 4046 \family default
4046 4047 , but if you've loaded a named profile, '
4047 4048 \family typewriter
4048 4049 -PROFILE_NAME
4049 4050 \family default
4050 4051 ' is appended to the name.
4051 4052 This allows you to keep separate histories related to various tasks: commands
4052 4053 related to numerical work will not be clobbered by a system shell history,
4053 4054 for example.
4054 4055 \layout Subsubsection
4055 4056
4056 4057 Autoindent
4057 4058 \layout Standard
4058 4059
4059 4060 IPython can recognize lines ending in ':' and indent the next line, while
4060 4061 also un-indenting automatically after 'raise' or 'return'.
4061 4062
4062 4063 \layout Standard
4063 4064
4064 4065 This feature uses the readline library, so it will honor your
4065 4066 \family typewriter
4066 4067 ~/.inputrc
4067 4068 \family default
4068 4069 configuration (or whatever file your
4069 4070 \family typewriter
4070 4071 INPUTRC
4071 4072 \family default
4072 4073 variable points to).
4073 4074 Adding the following lines to your
4074 4075 \family typewriter
4075 4076 .inputrc
4076 4077 \family default
4077 4078 file can make indenting/unindenting more convenient (
4078 4079 \family typewriter
4079 4080 M-i
4080 4081 \family default
4081 4082 indents,
4082 4083 \family typewriter
4083 4084 M-u
4084 4085 \family default
4085 4086 unindents):
4086 4087 \layout Standard
4087 4088
4088 4089
4089 4090 \family typewriter
4090 4091 $if Python
4091 4092 \newline
4092 4093 "
4093 4094 \backslash
4094 4095 M-i": "\SpecialChar ~
4095 4096 \SpecialChar ~
4096 4097 \SpecialChar ~
4097 4098 \SpecialChar ~
4098 4099 "
4099 4100 \newline
4100 4101 "
4101 4102 \backslash
4102 4103 M-u": "
4103 4104 \backslash
4104 4105 d
4105 4106 \backslash
4106 4107 d
4107 4108 \backslash
4108 4109 d
4109 4110 \backslash
4110 4111 d"
4111 4112 \newline
4112 4113 $endif
4113 4114 \layout Standard
4114 4115
4115 4116 Note that there are 4 spaces between the quote marks after
4116 4117 \family typewriter
4117 4118 "M-i"
4118 4119 \family default
4119 4120 above.
4120 4121 \layout Standard
4121 4122
4122 4123
4123 4124 \series bold
4124 4125 Warning:
4125 4126 \series default
4126 4127 this feature is ON by default, but it can cause problems with the pasting
4127 4128 of multi-line indented code (the pasted code gets re-indented on each line).
4128 4129 A magic function
4129 4130 \family typewriter
4130 4131 %autoindent
4131 4132 \family default
4132 4133 allows you to toggle it on/off at runtime.
4133 4134 You can also disable it permanently on in your
4134 4135 \family typewriter
4135 4136 ipythonrc
4136 4137 \family default
4137 4138 file (set
4138 4139 \family typewriter
4139 4140 autoindent 0
4140 4141 \family default
4141 4142 ).
4142 4143 \layout Subsubsection
4143 4144
4144 4145 Customizing readline behavior
4145 4146 \layout Standard
4146 4147
4147 4148 All these features are based on the GNU readline library, which has an extremely
4148 4149 customizable interface.
4149 4150 Normally, readline is configured via a file which defines the behavior
4150 4151 of the library; the details of the syntax for this can be found in the
4151 4152 readline documentation available with your system or on the Internet.
4152 4153 IPython doesn't read this file (if it exists) directly, but it does support
4153 4154 passing to readline valid options via a simple interface.
4154 4155 In brief, you can customize readline by setting the following options in
4155 4156 your
4156 4157 \family typewriter
4157 4158 ipythonrc
4158 4159 \family default
4159 4160 configuration file (note that these options can
4160 4161 \emph on
4161 4162 not
4162 4163 \emph default
4163 4164 be specified at the command line):
4164 4165 \layout List
4165 4166 \labelwidthstring 00.00.0000
4166 4167
4167 4168
4168 4169 \family typewriter
4169 4170 \series bold
4170 4171 readline_parse_and_bind:
4171 4172 \family default
4172 4173 \series default
4173 4174 this option can appear as many times as you want, each time defining a
4174 4175 string to be executed via a
4175 4176 \family typewriter
4176 4177 readline.parse_and_bind()
4177 4178 \family default
4178 4179 command.
4179 4180 The syntax for valid commands of this kind can be found by reading the
4180 4181 documentation for the GNU readline library, as these commands are of the
4181 4182 kind which readline accepts in its configuration file.
4182 4183 \layout List
4183 4184 \labelwidthstring 00.00.0000
4184 4185
4185 4186
4186 4187 \family typewriter
4187 4188 \series bold
4188 4189 readline_remove_delims:
4189 4190 \family default
4190 4191 \series default
4191 4192 a string of characters to be removed from the default word-delimiters list
4192 4193 used by readline, so that completions may be performed on strings which
4193 4194 contain them.
4194 4195 Do not change the default value unless you know what you're doing.
4195 4196 \layout List
4196 4197 \labelwidthstring 00.00.0000
4197 4198
4198 4199
4199 4200 \family typewriter
4200 4201 \series bold
4201 4202 readline_omit__names
4202 4203 \family default
4203 4204 \series default
4204 4205 : when tab-completion is enabled, hitting
4205 4206 \family typewriter
4206 4207 <tab>
4207 4208 \family default
4208 4209 after a '
4209 4210 \family typewriter
4210 4211 .
4211 4212 \family default
4212 4213 ' in a name will complete all attributes of an object, including all the
4213 4214 special methods whose names include double underscores (like
4214 4215 \family typewriter
4215 4216 __getitem__
4216 4217 \family default
4217 4218 or
4218 4219 \family typewriter
4219 4220 __class__
4220 4221 \family default
4221 4222 ).
4222 4223 If you'd rather not see these names by default, you can set this option
4223 4224 to 1.
4224 4225 Note that even when this option is set, you can still see those names by
4225 4226 explicitly typing a
4226 4227 \family typewriter
4227 4228 _
4228 4229 \family default
4229 4230 after the period and hitting
4230 4231 \family typewriter
4231 4232 <tab>
4232 4233 \family default
4233 4234 : '
4234 4235 \family typewriter
4235 4236 name._<tab>
4236 4237 \family default
4237 4238 ' will always complete attribute names starting with '
4238 4239 \family typewriter
4239 4240 _
4240 4241 \family default
4241 4242 '.
4242 4243 \layout List
4243 4244 \labelwidthstring 00.00.0000
4244 4245
4245 4246 \SpecialChar ~
4246 4247 This option is off by default so that new users see all attributes of any
4247 4248 objects they are dealing with.
4248 4249 \layout Standard
4249 4250
4250 4251 You will find the default values along with a corresponding detailed explanation
4251 4252 in your
4252 4253 \family typewriter
4253 4254 ipythonrc
4254 4255 \family default
4255 4256 file.
4256 4257 \layout Subsection
4257 4258
4258 4259 Session logging and restoring
4259 4260 \layout Standard
4260 4261
4261 4262 You can log all input from a session either by starting IPython with the
4262 4263 command line switches
4263 4264 \family typewriter
4264 4265 -log
4265 4266 \family default
4266 4267 or
4267 4268 \family typewriter
4268 4269 -logfile
4269 4270 \family default
4270 4271 (see sec.
4271 4272
4272 4273 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
4273 4274
4274 4275 \end_inset
4275 4276
4276 4277 )or by activating the logging at any moment with the magic function
4277 4278 \family typewriter
4278 4279 %logstart
4279 4280 \family default
4280 4281 .
4281 4282
4282 4283 \layout Standard
4283 4284
4284 4285 Log files can later be reloaded with the
4285 4286 \family typewriter
4286 4287 -logplay
4287 4288 \family default
4288 4289 option and IPython will attempt to 'replay' the log by executing all the
4289 4290 lines in it, thus restoring the state of a previous session.
4290 4291 This feature is not quite perfect, but can still be useful in many cases.
4291 4292 \layout Standard
4292 4293
4293 4294 The log files can also be used as a way to have a permanent record of any
4294 4295 code you wrote while experimenting.
4295 4296 Log files are regular text files which you can later open in your favorite
4296 4297 text editor to extract code or to 'clean them up' before using them to
4297 4298 replay a session.
4298 4299 \layout Standard
4299 4300
4300 4301 The
4301 4302 \family typewriter
4302 4303 %logstart
4303 4304 \family default
4304 4305 function for activating logging in mid-session is used as follows:
4305 4306 \layout Standard
4306 4307
4307 4308
4308 4309 \family typewriter
4309 4310 %logstart [log_name [log_mode]]
4310 4311 \layout Standard
4311 4312
4312 4313 If no name is given, it defaults to a file named
4313 4314 \family typewriter
4314 4315 'log'
4315 4316 \family default
4316 4317 in your IPYTHONDIR directory, in
4317 4318 \family typewriter
4318 4319 'rotate'
4319 4320 \family default
4320 4321 mode (see below).
4321 4322 \layout Standard
4322 4323
4323 4324 '
4324 4325 \family typewriter
4325 4326 %logstart name
4326 4327 \family default
4327 4328 ' saves to file
4328 4329 \family typewriter
4329 4330 'name'
4330 4331 \family default
4331 4332 in
4332 4333 \family typewriter
4333 4334 'backup'
4334 4335 \family default
4335 4336 mode.
4336 4337 It saves your history up to that point and then continues logging.
4337 4338 \layout Standard
4338 4339
4339 4340
4340 4341 \family typewriter
4341 4342 %logstart
4342 4343 \family default
4343 4344 takes a second optional parameter: logging mode.
4344 4345 This can be one of (note that the modes are given unquoted):
4345 4346 \layout List
4346 4347 \labelwidthstring 00.00.0000
4347 4348
4348 4349
4349 4350 \family typewriter
4350 4351 over
4351 4352 \family default
4352 4353 : overwrite existing
4353 4354 \family typewriter
4354 4355 log_name
4355 4356 \family default
4356 4357 .
4357 4358 \layout List
4358 4359 \labelwidthstring 00.00.0000
4359 4360
4360 4361
4361 4362 \family typewriter
4362 4363 backup
4363 4364 \family default
4364 4365 : rename (if exists) to
4365 4366 \family typewriter
4366 4367 log_name~
4367 4368 \family default
4368 4369 and start
4369 4370 \family typewriter
4370 4371 log_name
4371 4372 \family default
4372 4373 .
4373 4374 \layout List
4374 4375 \labelwidthstring 00.00.0000
4375 4376
4376 4377
4377 4378 \family typewriter
4378 4379 append
4379 4380 \family default
4380 4381 : well, that says it.
4381 4382 \layout List
4382 4383 \labelwidthstring 00.00.0000
4383 4384
4384 4385
4385 4386 \family typewriter
4386 4387 rotate
4387 4388 \family default
4388 4389 : create rotating logs
4389 4390 \family typewriter
4390 4391 log_name
4391 4392 \family default
4392 4393 .
4393 4394 \family typewriter
4394 4395 1~
4395 4396 \family default
4396 4397 ,
4397 4398 \family typewriter
4398 4399 log_name.2~
4399 4400 \family default
4400 4401 , etc.
4401 4402 \layout Standard
4402 4403
4403 4404 The
4404 4405 \family typewriter
4405 4406 %logoff
4406 4407 \family default
4407 4408 and
4408 4409 \family typewriter
4409 4410 %logon
4410 4411 \family default
4411 4412 functions allow you to temporarily stop and resume logging to a file which
4412 4413 had previously been started with
4413 4414 \family typewriter
4414 4415 %logstart
4415 4416 \family default
4416 4417 .
4417 4418 They will fail (with an explanation) if you try to use them before logging
4418 4419 has been started.
4419 4420 \layout Subsection
4420 4421
4421 4422
4422 4423 \begin_inset LatexCommand \label{sub:System-shell-access}
4423 4424
4424 4425 \end_inset
4425 4426
4426 4427 System shell access
4427 4428 \layout Standard
4428 4429
4429 4430 Any input line beginning with a
4430 4431 \family typewriter
4431 4432 !
4432 4433 \family default
4433 4434 character is passed verbatim (minus the
4434 4435 \family typewriter
4435 4436 !
4436 4437 \family default
4437 4438 , of course) to the underlying operating system.
4438 4439 For example, typing
4439 4440 \family typewriter
4440 4441 !ls
4441 4442 \family default
4442 4443 will run
4443 4444 \family typewriter
4444 4445 'ls'
4445 4446 \family default
4446 4447 in the current directory.
4447 4448 \layout Subsubsection
4448 4449
4449 4450 Manual capture of command output
4450 4451 \layout Standard
4451 4452
4452 4453 If the input line begins with
4453 4454 \emph on
4454 4455 two
4455 4456 \emph default
4456 4457 exclamation marks,
4457 4458 \family typewriter
4458 4459 !!
4459 4460 \family default
4460 4461 , the command is executed but its output is captured and returned as a python
4461 4462 list, split on newlines.
4462 4463 Any output sent by the subprocess to standard error is printed separately,
4463 4464 so that the resulting list only captures standard output.
4464 4465 The
4465 4466 \family typewriter
4466 4467 !!
4467 4468 \family default
4468 4469 syntax is a shorthand for the
4469 4470 \family typewriter
4470 4471 %sx
4471 4472 \family default
4472 4473 magic command.
4473 4474 \layout Standard
4474 4475
4475 4476 Finally, the
4476 4477 \family typewriter
4477 4478 %sc
4478 4479 \family default
4479 4480 magic (short for `shell capture') is similar to
4480 4481 \family typewriter
4481 4482 %sx
4482 4483 \family default
4483 4484 , but allowing more fine-grained control of the capture details, and storing
4484 4485 the result directly into a named variable.
4485 4486 \layout Standard
4486 4487
4487 4488 See Sec.\SpecialChar ~
4488 4489
4489 4490 \begin_inset LatexCommand \ref{sec:magic}
4490 4491
4491 4492 \end_inset
4492 4493
4493 4494 for details on the magics
4494 4495 \family typewriter
4495 4496 %sc
4496 4497 \family default
4497 4498 and
4498 4499 \family typewriter
4499 4500 %sx
4500 4501 \family default
4501 4502 , or use IPython's own help (
4502 4503 \family typewriter
4503 4504 sc?
4504 4505 \family default
4505 4506 and
4506 4507 \family typewriter
4507 4508 sx?
4508 4509 \family default
4509 4510 ) for further details.
4510 4511 \layout Standard
4511 4512
4512 4513 IPython also allows you to expand the value of python variables when making
4513 4514 system calls.
4514 4515 Any python variable or expression which you prepend with
4515 4516 \family typewriter
4516 4517 $
4517 4518 \family default
4518 4519 will get expanded before the system call is made.
4519 4520
4520 4521 \layout Standard
4521 4522
4522 4523
4523 4524 \family typewriter
4524 4525 In [1]: pyvar='Hello world'
4525 4526 \newline
4526 4527 In [2]: !echo "A python variable: $pyvar"
4527 4528 \newline
4528 4529 A python variable: Hello world
4529 4530 \layout Standard
4530 4531
4531 4532 If you want the shell to actually see a literal
4532 4533 \family typewriter
4533 4534 $
4534 4535 \family default
4535 4536 , you need to type it twice:
4536 4537 \layout Standard
4537 4538
4538 4539
4539 4540 \family typewriter
4540 4541 In [3]: !echo "A system variable: $$HOME"
4541 4542 \newline
4542 4543 A system variable: /home/fperez
4543 4544 \layout Standard
4544 4545
4545 4546 You can pass arbitrary expressions, though you'll need to delimit them with
4546 4547
4547 4548 \family typewriter
4548 4549 {}
4549 4550 \family default
4550 4551 if there is ambiguity as to the extent of the expression:
4551 4552 \layout Standard
4552 4553
4553 4554
4554 4555 \family typewriter
4555 4556 In [5]: x=10
4556 4557 \newline
4557 4558 In [6]: y=20
4558 4559 \newline
4559 4560 In [13]: !echo $x+y
4560 4561 \newline
4561 4562 10+y
4562 4563 \newline
4563 4564 In [7]: !echo ${x+y}
4564 4565 \newline
4565 4566 30
4566 4567 \layout Standard
4567 4568
4568 4569 Even object attributes can be expanded:
4569 4570 \layout Standard
4570 4571
4571 4572
4572 4573 \family typewriter
4573 4574 In [12]: !echo $sys.argv
4574 4575 \newline
4575 4576 [/home/fperez/usr/bin/ipython]
4576 4577 \layout Subsection
4577 4578
4578 4579 System command aliases
4579 4580 \layout Standard
4580 4581
4581 4582 The
4582 4583 \family typewriter
4583 4584 %alias
4584 4585 \family default
4585 4586 magic function and the
4586 4587 \family typewriter
4587 4588 alias
4588 4589 \family default
4589 4590 option in the
4590 4591 \family typewriter
4591 4592 ipythonrc
4592 4593 \family default
4593 4594 configuration file allow you to define magic functions which are in fact
4594 4595 system shell commands.
4595 4596 These aliases can have parameters.
4596 4597
4597 4598 \layout Standard
4598 4599
4599 4600 '
4600 4601 \family typewriter
4601 4602 %alias alias_name cmd
4602 4603 \family default
4603 4604 ' defines '
4604 4605 \family typewriter
4605 4606 alias_name
4606 4607 \family default
4607 4608 ' as an alias for '
4608 4609 \family typewriter
4609 4610 cmd
4610 4611 \family default
4611 4612 '
4612 4613 \layout Standard
4613 4614
4614 4615 Then, typing '
4615 4616 \family typewriter
4616 4617 %alias_name params
4617 4618 \family default
4618 4619 ' will execute the system command '
4619 4620 \family typewriter
4620 4621 cmd params
4621 4622 \family default
4622 4623 ' (from your underlying operating system).
4623 4624
4624 4625 \layout Standard
4625 4626
4626 4627 You can also define aliases with parameters using
4627 4628 \family typewriter
4628 4629 %s
4629 4630 \family default
4630 4631 specifiers (one per parameter).
4631 4632 The following example defines the
4632 4633 \family typewriter
4633 4634 %parts
4634 4635 \family default
4635 4636 function as an alias to the command '
4636 4637 \family typewriter
4637 4638 echo first %s second %s
4638 4639 \family default
4639 4640 ' where each
4640 4641 \family typewriter
4641 4642 %s
4642 4643 \family default
4643 4644 will be replaced by a positional parameter to the call to
4644 4645 \family typewriter
4645 4646 %parts:
4646 4647 \layout Standard
4647 4648
4648 4649
4649 4650 \family typewriter
4650 4651 In [1]: alias parts echo first %s second %s
4651 4652 \newline
4652 4653 In [2]: %parts A B
4653 4654 \newline
4654 4655 first A second B
4655 4656 \newline
4656 4657 In [3]: %parts A
4657 4658 \newline
4658 4659 Incorrect number of arguments: 2 expected.
4659 4660
4660 4661 \newline
4661 4662 parts is an alias to: 'echo first %s second %s'
4662 4663 \layout Standard
4663 4664
4664 4665 If called with no parameters,
4665 4666 \family typewriter
4666 4667 %alias
4667 4668 \family default
4668 4669 prints the table of currently defined aliases.
4669 4670 \layout Standard
4670 4671
4671 4672 The
4672 4673 \family typewriter
4673 4674 %rehash/rehashx
4674 4675 \family default
4675 4676 magics allow you to load your entire
4676 4677 \family typewriter
4677 4678 $PATH
4678 4679 \family default
4679 4680 as ipython aliases.
4680 4681 See their respective docstrings (or sec.\SpecialChar ~
4681 4682
4682 4683 \begin_inset LatexCommand \ref{sec:magic}
4683 4684
4684 4685 \end_inset
4685 4686
4686 4687 for further details).
4687 4688 \layout Subsection
4688 4689
4689 4690
4690 4691 \begin_inset LatexCommand \label{sec:dreload}
4691 4692
4692 4693 \end_inset
4693 4694
4694 4695 Recursive reload
4695 4696 \layout Standard
4696 4697
4697 4698 The
4698 4699 \family typewriter
4699 4700 %dreload
4700 4701 \family default
4701 4702 command does a recursive reload of a module: changes made to the module
4702 4703 since you imported will actually be available without having to exit.
4703 4704 \layout Subsection
4704 4705
4705 4706 Verbose and colored exception traceback printouts
4706 4707 \layout Standard
4707 4708
4708 4709 IPython provides the option to see very detailed exception tracebacks, which
4709 4710 can be especially useful when debugging large programs.
4710 4711 You can run any Python file with the
4711 4712 \family typewriter
4712 4713 %run
4713 4714 \family default
4714 4715 function to benefit from these detailed tracebacks.
4715 4716 Furthermore, both normal and verbose tracebacks can be colored (if your
4716 4717 terminal supports it) which makes them much easier to parse visually.
4717 4718 \layout Standard
4718 4719
4719 4720 See the magic
4720 4721 \family typewriter
4721 4722 xmode
4722 4723 \family default
4723 4724 and
4724 4725 \family typewriter
4725 4726 colors
4726 4727 \family default
4727 4728 functions for details (just type
4728 4729 \family typewriter
4729 4730 %magic
4730 4731 \family default
4731 4732 ).
4732 4733 \layout Standard
4733 4734
4734 4735 These features are basically a terminal version of Ka-Ping Yee's
4735 4736 \family typewriter
4736 4737 cgitb
4737 4738 \family default
4738 4739 module, now part of the standard Python library.
4739 4740 \layout Subsection
4740 4741
4741 4742
4742 4743 \begin_inset LatexCommand \label{sec:cache_input}
4743 4744
4744 4745 \end_inset
4745 4746
4746 4747 Input caching system
4747 4748 \layout Standard
4748 4749
4749 4750 IPython offers numbered prompts (In/Out) with input and output caching.
4750 4751 All input is saved and can be retrieved as variables (besides the usual
4751 4752 arrow key recall).
4752 4753 \layout Standard
4753 4754
4754 4755 The following GLOBAL variables always exist (so don't overwrite them!):
4755 4756
4756 4757 \family typewriter
4757 4758 _i
4758 4759 \family default
4759 4760 : stores previous input.
4760 4761
4761 4762 \family typewriter
4762 4763 _ii
4763 4764 \family default
4764 4765 : next previous.
4765 4766
4766 4767 \family typewriter
4767 4768 _iii
4768 4769 \family default
4769 4770 : next-next previous.
4770 4771
4771 4772 \family typewriter
4772 4773 _ih
4773 4774 \family default
4774 4775 : a list of all input
4775 4776 \family typewriter
4776 4777 _ih[n]
4777 4778 \family default
4778 4779 is the input from line
4779 4780 \family typewriter
4780 4781 n
4781 4782 \family default
4782 4783 and this list is aliased to the global variable
4783 4784 \family typewriter
4784 4785 In
4785 4786 \family default
4786 4787 .
4787 4788 If you overwrite
4788 4789 \family typewriter
4789 4790 In
4790 4791 \family default
4791 4792 with a variable of your own, you can remake the assignment to the internal
4792 4793 list with a simple
4793 4794 \family typewriter
4794 4795 'In=_ih'
4795 4796 \family default
4796 4797 .
4797 4798 \layout Standard
4798 4799
4799 4800 Additionally, global variables named
4800 4801 \family typewriter
4801 4802 _i<n>
4802 4803 \family default
4803 4804 are dynamically created (
4804 4805 \family typewriter
4805 4806 <n>
4806 4807 \family default
4807 4808 being the prompt counter), such that
4808 4809 \newline
4809 4810
4810 4811 \family typewriter
4811 4812 _i<n> == _ih[<n>] == In[<n>].
4812 4813 \layout Standard
4813 4814
4814 4815 For example, what you typed at prompt 14 is available as
4815 4816 \family typewriter
4816 4817 _i14,
4817 4818 \family default
4818 4819
4819 4820 \family typewriter
4820 4821 _ih[14]
4821 4822 \family default
4822 4823 and
4823 4824 \family typewriter
4824 4825 In[14]
4825 4826 \family default
4826 4827 .
4827 4828 \layout Standard
4828 4829
4829 4830 This allows you to easily cut and paste multi line interactive prompts by
4830 4831 printing them out: they print like a clean string, without prompt characters.
4831 4832 You can also manipulate them like regular variables (they are strings),
4832 4833 modify or exec them (typing
4833 4834 \family typewriter
4834 4835 'exec _i9'
4835 4836 \family default
4836 4837 will re-execute the contents of input prompt 9, '
4837 4838 \family typewriter
4838 4839 exec In[9:14]+In[18]
4839 4840 \family default
4840 4841 ' will re-execute lines 9 through 13 and line 18).
4841 4842 \layout Standard
4842 4843
4843 4844 You can also re-execute multiple lines of input easily by using the magic
4844 4845
4845 4846 \family typewriter
4846 4847 %macro
4847 4848 \family default
4848 4849 function (which automates the process and allows re-execution without having
4849 4850 to type '
4850 4851 \family typewriter
4851 4852 exec
4852 4853 \family default
4853 4854 ' every time).
4854 4855 The macro system also allows you to re-execute previous lines which include
4855 4856 magic function calls (which require special processing).
4856 4857 Type
4857 4858 \family typewriter
4858 4859 %macro?
4859 4860 \family default
4860 4861 or see sec.
4861 4862
4862 4863 \begin_inset LatexCommand \ref{sec:magic}
4863 4864
4864 4865 \end_inset
4865 4866
4866 4867 for more details on the macro system.
4867 4868 \layout Standard
4868 4869
4869 4870 A history function
4870 4871 \family typewriter
4871 4872 %hist
4872 4873 \family default
4873 4874 allows you to see any part of your input history by printing a range of
4874 4875 the
4875 4876 \family typewriter
4876 4877 _i
4877 4878 \family default
4878 4879 variables.
4879 4880 \layout Subsection
4880 4881
4881 4882
4882 4883 \begin_inset LatexCommand \label{sec:cache_output}
4883 4884
4884 4885 \end_inset
4885 4886
4886 4887 Output caching system
4887 4888 \layout Standard
4888 4889
4889 4890 For output that is returned from actions, a system similar to the input
4890 4891 cache exists but using
4891 4892 \family typewriter
4892 4893 _
4893 4894 \family default
4894 4895 instead of
4895 4896 \family typewriter
4896 4897 _i
4897 4898 \family default
4898 4899 .
4899 4900 Only actions that produce a result (NOT assignments, for example) are cached.
4900 4901 If you are familiar with Mathematica, IPython's
4901 4902 \family typewriter
4902 4903 _
4903 4904 \family default
4904 4905 variables behave exactly like Mathematica's
4905 4906 \family typewriter
4906 4907 %
4907 4908 \family default
4908 4909 variables.
4909 4910 \layout Standard
4910 4911
4911 4912 The following GLOBAL variables always exist (so don't overwrite them!):
4912 4913
4913 4914 \layout List
4914 4915 \labelwidthstring 00.00.0000
4915 4916
4916 4917
4917 4918 \family typewriter
4918 4919 \series bold
4919 4920 _
4920 4921 \family default
4921 4922 \series default
4922 4923 (a
4923 4924 \emph on
4924 4925 single
4925 4926 \emph default
4926 4927 underscore) : stores previous output, like Python's default interpreter.
4927 4928 \layout List
4928 4929 \labelwidthstring 00.00.0000
4929 4930
4930 4931
4931 4932 \family typewriter
4932 4933 \series bold
4933 4934 __
4934 4935 \family default
4935 4936 \series default
4936 4937 (two underscores): next previous.
4937 4938 \layout List
4938 4939 \labelwidthstring 00.00.0000
4939 4940
4940 4941
4941 4942 \family typewriter
4942 4943 \series bold
4943 4944 ___
4944 4945 \family default
4945 4946 \series default
4946 4947 (three underscores): next-next previous.
4947 4948 \layout Standard
4948 4949
4949 4950 Additionally, global variables named
4950 4951 \family typewriter
4951 4952 _<n>
4952 4953 \family default
4953 4954 are dynamically created (
4954 4955 \family typewriter
4955 4956 <n>
4956 4957 \family default
4957 4958 being the prompt counter), such that the result of output
4958 4959 \family typewriter
4959 4960 <n>
4960 4961 \family default
4961 4962 is always available as
4962 4963 \family typewriter
4963 4964 _<n>
4964 4965 \family default
4965 4966 (don't use the angle brackets, just the number, e.g.
4966 4967
4967 4968 \family typewriter
4968 4969 _21
4969 4970 \family default
4970 4971 ).
4971 4972 \layout Standard
4972 4973
4973 4974 These global variables are all stored in a global dictionary (not a list,
4974 4975 since it only has entries for lines which returned a result) available
4975 4976 under the names
4976 4977 \family typewriter
4977 4978 _oh
4978 4979 \family default
4979 4980 and
4980 4981 \family typewriter
4981 4982 Out
4982 4983 \family default
4983 4984 (similar to
4984 4985 \family typewriter
4985 4986 _ih
4986 4987 \family default
4987 4988 and
4988 4989 \family typewriter
4989 4990 In
4990 4991 \family default
4991 4992 ).
4992 4993 So the output from line 12 can be obtained as
4993 4994 \family typewriter
4994 4995 _12
4995 4996 \family default
4996 4997 ,
4997 4998 \family typewriter
4998 4999 Out[12]
4999 5000 \family default
5000 5001 or
5001 5002 \family typewriter
5002 5003 _oh[12]
5003 5004 \family default
5004 5005 .
5005 5006 If you accidentally overwrite the
5006 5007 \family typewriter
5007 5008 Out
5008 5009 \family default
5009 5010 variable you can recover it by typing
5010 5011 \family typewriter
5011 5012 'Out=_oh
5012 5013 \family default
5013 5014 ' at the prompt.
5014 5015 \layout Standard
5015 5016
5016 5017 This system obviously can potentially put heavy memory demands on your system,
5017 5018 since it prevents Python's garbage collector from removing any previously
5018 5019 computed results.
5019 5020 You can control how many results are kept in memory with the option (at
5020 5021 the command line or in your
5021 5022 \family typewriter
5022 5023 ipythonrc
5023 5024 \family default
5024 5025 file)
5025 5026 \family typewriter
5026 5027 cache_size
5027 5028 \family default
5028 5029 .
5029 5030 If you set it to 0, the whole system is completely disabled and the prompts
5030 5031 revert to the classic
5031 5032 \family typewriter
5032 5033 '>>>'
5033 5034 \family default
5034 5035 of normal Python.
5035 5036 \layout Subsection
5036 5037
5037 5038 Directory history
5038 5039 \layout Standard
5039 5040
5040 5041 Your history of visited directories is kept in the global list
5041 5042 \family typewriter
5042 5043 _dh
5043 5044 \family default
5044 5045 , and the magic
5045 5046 \family typewriter
5046 5047 %cd
5047 5048 \family default
5048 5049 command can be used to go to any entry in that list.
5049 5050 The
5050 5051 \family typewriter
5051 5052 %dhist
5052 5053 \family default
5053 5054 command allows you to view this history.
5054 5055 \layout Subsection
5055 5056
5056 5057 Automatic parentheses and quotes
5057 5058 \layout Standard
5058 5059
5059 5060 These features were adapted from Nathan Gray's LazyPython.
5060 5061 They are meant to allow less typing for common situations.
5061 5062 \layout Subsubsection
5062 5063
5063 5064 Automatic parentheses
5064 5065 \layout Standard
5065 5066
5066 5067 Callable objects (i.e.
5067 5068 functions, methods, etc) can be invoked like this (notice the commas between
5068 5069 the arguments):
5069 5070 \layout Standard
5070 5071
5071 5072
5072 5073 \family typewriter
5073 5074 >>> callable_ob arg1, arg2, arg3
5074 5075 \layout Standard
5075 5076
5076 5077 and the input will be translated to this:
5077 5078 \layout Standard
5078 5079
5079 5080
5080 5081 \family typewriter
5081 5082 --> callable_ob(arg1, arg2, arg3)
5082 5083 \layout Standard
5083 5084
5084 5085 You can force automatic parentheses by using '/' as the first character
5085 5086 of a line.
5086 5087 For example:
5087 5088 \layout Standard
5088 5089
5089 5090
5090 5091 \family typewriter
5091 5092 >>> /globals # becomes 'globals()'
5092 5093 \layout Standard
5093 5094
5094 5095 Note that the '/' MUST be the first character on the line! This won't work:
5095 5096
5096 5097 \layout Standard
5097 5098
5098 5099
5099 5100 \family typewriter
5100 5101 >>> print /globals # syntax error
5101 5102 \layout Standard
5102 5103
5103 5104 In most cases the automatic algorithm should work, so you should rarely
5104 5105 need to explicitly invoke /.
5105 5106 One notable exception is if you are trying to call a function with a list
5106 5107 of tuples as arguments (the parenthesis will confuse IPython):
5107 5108 \layout Standard
5108 5109
5109 5110
5110 5111 \family typewriter
5111 5112 In [1]: zip (1,2,3),(4,5,6) # won't work
5112 5113 \layout Standard
5113 5114
5114 5115 but this will work:
5115 5116 \layout Standard
5116 5117
5117 5118
5118 5119 \family typewriter
5119 5120 In [2]: /zip (1,2,3),(4,5,6)
5120 5121 \newline
5121 5122 ------> zip ((1,2,3),(4,5,6))
5122 5123 \newline
5123 5124 Out[2]= [(1, 4), (2, 5), (3, 6)]
5124 5125 \layout Standard
5125 5126
5126 5127 IPython tells you that it has altered your command line by displaying the
5127 5128 new command line preceded by
5128 5129 \family typewriter
5129 5130 -->
5130 5131 \family default
5131 5132 .
5132 5133 e.g.:
5133 5134 \layout Standard
5134 5135
5135 5136
5136 5137 \family typewriter
5137 5138 In [18]: callable list
5138 5139 \newline
5139 5140 -------> callable (list)
5140 5141 \layout Subsubsection
5141 5142
5142 5143 Automatic quoting
5143 5144 \layout Standard
5144 5145
5145 5146 You can force automatic quoting of a function's arguments by using
5146 5147 \family typewriter
5147 5148 `,'
5148 5149 \family default
5149 5150 or
5150 5151 \family typewriter
5151 5152 `;'
5152 5153 \family default
5153 5154 as the first character of a line.
5154 5155 For example:
5155 5156 \layout Standard
5156 5157
5157 5158
5158 5159 \family typewriter
5159 5160 >>> ,my_function /home/me # becomes my_function("/home/me")
5160 5161 \layout Standard
5161 5162
5162 5163 If you use
5163 5164 \family typewriter
5164 5165 `;'
5165 5166 \family default
5166 5167 instead, the whole argument is quoted as a single string (while
5167 5168 \family typewriter
5168 5169 `,'
5169 5170 \family default
5170 5171 splits on whitespace):
5171 5172 \layout Standard
5172 5173
5173 5174
5174 5175 \family typewriter
5175 5176 >>> ,my_function a b c # becomes my_function("a","b","c")
5176 5177 \layout Standard
5177 5178
5178 5179
5179 5180 \family typewriter
5180 5181 >>> ;my_function a b c # becomes my_function("a b c")
5181 5182 \layout Standard
5182 5183
5183 5184 Note that the `
5184 5185 \family typewriter
5185 5186 ,
5186 5187 \family default
5187 5188 ' or `
5188 5189 \family typewriter
5189 5190 ;
5190 5191 \family default
5191 5192 ' MUST be the first character on the line! This won't work:
5192 5193 \layout Standard
5193 5194
5194 5195
5195 5196 \family typewriter
5196 5197 >>> x = ,my_function /home/me # syntax error
5197 5198 \layout Section
5198 5199
5199 5200
5200 5201 \begin_inset LatexCommand \label{sec:customization}
5201 5202
5202 5203 \end_inset
5203 5204
5204 5205 Customization
5205 5206 \layout Standard
5206 5207
5207 5208 As we've already mentioned, IPython reads a configuration file which can
5208 5209 be specified at the command line (
5209 5210 \family typewriter
5210 5211 -rcfile
5211 5212 \family default
5212 5213 ) or which by default is assumed to be called
5213 5214 \family typewriter
5214 5215 ipythonrc
5215 5216 \family default
5216 5217 .
5217 5218 Such a file is looked for in the current directory where IPython is started
5218 5219 and then in your
5219 5220 \family typewriter
5220 5221 IPYTHONDIR
5221 5222 \family default
5222 5223 , which allows you to have local configuration files for specific projects.
5223 5224 In this section we will call these types of configuration files simply
5224 5225 rcfiles (short for resource configuration file).
5225 5226 \layout Standard
5226 5227
5227 5228 The syntax of an rcfile is one of key-value pairs separated by whitespace,
5228 5229 one per line.
5229 5230 Lines beginning with a
5230 5231 \family typewriter
5231 5232 #
5232 5233 \family default
5233 5234 are ignored as comments, but comments can
5234 5235 \series bold
5235 5236 not
5236 5237 \series default
5237 5238 be put on lines with data (the parser is fairly primitive).
5238 5239 Note that these are not python files, and this is deliberate, because it
5239 5240 allows us to do some things which would be quite tricky to implement if
5240 5241 they were normal python files.
5241 5242 \layout Standard
5242 5243
5243 5244 First, an rcfile can contain permanent default values for almost all command
5244 5245 line options (except things like
5245 5246 \family typewriter
5246 5247 -help
5247 5248 \family default
5248 5249 or
5249 5250 \family typewriter
5250 5251 -Version
5251 5252 \family default
5252 5253 ).
5253 5254 Sec\SpecialChar ~
5254 5255
5255 5256 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5256 5257
5257 5258 \end_inset
5258 5259
5259 5260 contains a description of all command-line options.
5260 5261 However, values you explicitly specify at the command line override the
5261 5262 values defined in the rcfile.
5262 5263 \layout Standard
5263 5264
5264 5265 Besides command line option values, the rcfile can specify values for certain
5265 5266 extra special options which are not available at the command line.
5266 5267 These options are briefly described below.
5267 5268
5268 5269 \layout Standard
5269 5270
5270 5271 Each of these options may appear as many times as you need it in the file.
5271 5272 \layout List
5272 5273 \labelwidthstring 00.00.0000
5273 5274
5274 5275
5275 5276 \family typewriter
5276 5277 \series bold
5277 5278 include\SpecialChar ~
5278 5279 <file1>\SpecialChar ~
5279 5280 <file2>\SpecialChar ~
5280 5281 ...
5281 5282 \family default
5282 5283 \series default
5283 5284 : you can name
5284 5285 \emph on
5285 5286 other
5286 5287 \emph default
5287 5288 rcfiles you want to recursively load up to 15 levels (don't use the
5288 5289 \family typewriter
5289 5290 <>
5290 5291 \family default
5291 5292 brackets in your names!).
5292 5293 This feature allows you to define a 'base' rcfile with general options
5293 5294 and special-purpose files which can be loaded only when needed with particular
5294 5295 configuration options.
5295 5296 To make this more convenient, IPython accepts the
5296 5297 \family typewriter
5297 5298 -profile <name>
5298 5299 \family default
5299 5300 option (abbreviates to
5300 5301 \family typewriter
5301 5302 -p <name
5302 5303 \family default
5303 5304 >)
5304 5305 \family typewriter
5305 5306 which
5306 5307 \family default
5307 5308 tells it to look for an rcfile named
5308 5309 \family typewriter
5309 5310 ipythonrc-<name>
5310 5311 \family default
5311 5312 .
5312 5313
5313 5314 \layout List
5314 5315 \labelwidthstring 00.00.0000
5315 5316
5316 5317
5317 5318 \family typewriter
5318 5319 \series bold
5319 5320 import_mod\SpecialChar ~
5320 5321 <mod1>\SpecialChar ~
5321 5322 <mod2>\SpecialChar ~
5322 5323 ...
5323 5324 \family default
5324 5325 \series default
5325 5326 : import modules with '
5326 5327 \family typewriter
5327 5328 import
5328 5329 \family default
5329 5330
5330 5331 \family typewriter
5331 5332 <mod1>,<mod2>,...
5332 5333 \family default
5333 5334 '
5334 5335 \layout List
5335 5336 \labelwidthstring 00.00.0000
5336 5337
5337 5338
5338 5339 \family typewriter
5339 5340 \series bold
5340 5341 import_some\SpecialChar ~
5341 5342 <mod>\SpecialChar ~
5342 5343 <f1>\SpecialChar ~
5343 5344 <f2>\SpecialChar ~
5344 5345 ...
5345 5346 \family default
5346 5347 \series default
5347 5348 : import functions with '
5348 5349 \family typewriter
5349 5350 from <mod> import
5350 5351 \family default
5351 5352
5352 5353 \family typewriter
5353 5354 <f1>,<f2>,...
5354 5355 \family default
5355 5356 '
5356 5357 \layout List
5357 5358 \labelwidthstring 00.00.0000
5358 5359
5359 5360
5360 5361 \family typewriter
5361 5362 \series bold
5362 5363 import_all\SpecialChar ~
5363 5364 <mod1>\SpecialChar ~
5364 5365 <mod2>\SpecialChar ~
5365 5366 ...
5366 5367 \family default
5367 5368 \series default
5368 5369 : for each module listed import functions with '
5369 5370 \family typewriter
5370 5371 from <mod> import *
5371 5372 \family default
5372 5373 '
5373 5374 \layout List
5374 5375 \labelwidthstring 00.00.0000
5375 5376
5376 5377
5377 5378 \family typewriter
5378 5379 \series bold
5379 5380 execute\SpecialChar ~
5380 5381 <python\SpecialChar ~
5381 5382 code>
5382 5383 \family default
5383 5384 \series default
5384 5385 : give any single-line python code to be executed.
5385 5386 \layout List
5386 5387 \labelwidthstring 00.00.0000
5387 5388
5388 5389
5389 5390 \family typewriter
5390 5391 \series bold
5391 5392 execfile\SpecialChar ~
5392 5393 <filename>
5393 5394 \family default
5394 5395 \series default
5395 5396 : execute the python file given with an '
5396 5397 \family typewriter
5397 5398 execfile(filename)
5398 5399 \family default
5399 5400 ' command.
5400 5401 Username expansion is performed on the given names.
5401 5402 So if you need any amount of extra fancy customization that won't fit in
5402 5403 any of the above 'canned' options, you can just put it in a separate python
5403 5404 file and execute it.
5404 5405 \layout List
5405 5406 \labelwidthstring 00.00.0000
5406 5407
5407 5408
5408 5409 \family typewriter
5409 5410 \series bold
5410 5411 alias\SpecialChar ~
5411 5412 <alias_def>
5412 5413 \family default
5413 5414 \series default
5414 5415 : this is equivalent to calling '
5415 5416 \family typewriter
5416 5417 %alias\SpecialChar ~
5417 5418 <alias_def>
5418 5419 \family default
5419 5420 ' at the IPython command line.
5420 5421 This way, from within IPython you can do common system tasks without having
5421 5422 to exit it or use the
5422 5423 \family typewriter
5423 5424 !
5424 5425 \family default
5425 5426 escape.
5426 5427 IPython isn't meant to be a shell replacement, but it is often very useful
5427 5428 to be able to do things with files while testing code.
5428 5429 This gives you the flexibility to have within IPython any aliases you may
5429 5430 be used to under your normal system shell.
5430 5431 \layout Subsection
5431 5432
5432 5433
5433 5434 \begin_inset LatexCommand \label{sec:ipytonrc-sample}
5434 5435
5435 5436 \end_inset
5436 5437
5437 5438 Sample
5438 5439 \family typewriter
5439 5440 ipythonrc
5440 5441 \family default
5441 5442 file
5442 5443 \layout Standard
5443 5444
5444 5445 The default rcfile, called
5445 5446 \family typewriter
5446 5447 ipythonrc
5447 5448 \family default
5448 5449 and supplied in your
5449 5450 \family typewriter
5450 5451 IPYTHONDIR
5451 5452 \family default
5452 5453 directory contains lots of comments on all of these options.
5453 5454 We reproduce it here for reference:
5454 5455 \layout Standard
5455 5456
5456 5457
5457 5458 \begin_inset ERT
5458 5459 status Open
5459 5460
5460 5461 \layout Standard
5461 5462
5462 5463 \backslash
5463 5464 codelist{../IPython/UserConfig/ipythonrc}
5464 5465 \end_inset
5465 5466
5466 5467
5467 5468 \layout Subsection
5468 5469
5469 5470
5470 5471 \begin_inset LatexCommand \label{sec:prompts}
5471 5472
5472 5473 \end_inset
5473 5474
5474 5475 Fine-tuning your prompt
5475 5476 \layout Standard
5476 5477
5477 5478 IPython's prompts can be customized using a syntax similar to that of the
5478 5479
5479 5480 \family typewriter
5480 5481 bash
5481 5482 \family default
5482 5483 shell.
5483 5484 Many of
5484 5485 \family typewriter
5485 5486 bash
5486 5487 \family default
5487 5488 's escapes are supported, as well as a few additional ones.
5488 5489 We list them below:
5489 5490 \layout Description
5490 5491
5491 5492
5492 5493 \backslash
5493 5494 # the prompt/history count number
5494 5495 \layout Description
5495 5496
5496 5497
5497 5498 \backslash
5498 5499 D the prompt/history count, with the actual digits replaced by dots.
5499 5500 Used mainly in continuation prompts (prompt_in2)
5500 5501 \layout Description
5501 5502
5502 5503
5503 5504 \backslash
5504 5505 w the current working directory
5505 5506 \layout Description
5506 5507
5507 5508
5508 5509 \backslash
5509 5510 W the basename of current working directory
5510 5511 \layout Description
5511 5512
5512 5513
5513 5514 \backslash
5514 5515 X
5515 5516 \emph on
5516 5517 n
5517 5518 \emph default
5518 5519 where
5519 5520 \begin_inset Formula $n=0\ldots5.$
5520 5521 \end_inset
5521 5522
5522 5523 The current working directory, with
5523 5524 \family typewriter
5524 5525 $HOME
5525 5526 \family default
5526 5527 replaced by
5527 5528 \family typewriter
5528 5529 ~
5529 5530 \family default
5530 5531 , and filtered out to contain only
5531 5532 \begin_inset Formula $n$
5532 5533 \end_inset
5533 5534
5534 5535 path elements
5535 5536 \layout Description
5536 5537
5537 5538
5538 5539 \backslash
5539 5540 Y
5540 5541 \emph on
5541 5542 n
5542 5543 \emph default
5543 5544 Similar to
5544 5545 \backslash
5545 5546 X
5546 5547 \emph on
5547 5548 n
5548 5549 \emph default
5549 5550 , but with the
5550 5551 \begin_inset Formula $n+1$
5551 5552 \end_inset
5552 5553
5553 5554 element included if it is
5554 5555 \family typewriter
5555 5556 ~
5556 5557 \family default
5557 5558 (this is similar to the behavior of the %c
5558 5559 \emph on
5559 5560 n
5560 5561 \emph default
5561 5562 escapes in
5562 5563 \family typewriter
5563 5564 tcsh
5564 5565 \family default
5565 5566 )
5566 5567 \layout Description
5567 5568
5568 5569
5569 5570 \backslash
5570 5571 u the username of the current user
5571 5572 \layout Description
5572 5573
5573 5574
5574 5575 \backslash
5575 5576 $ if the effective UID is 0, a #, otherwise a $
5576 5577 \layout Description
5577 5578
5578 5579
5579 5580 \backslash
5580 5581 h the hostname up to the first `.'
5581 5582 \layout Description
5582 5583
5583 5584
5584 5585 \backslash
5585 5586 H the hostname
5586 5587 \layout Description
5587 5588
5588 5589
5589 5590 \backslash
5590 5591 n a newline
5591 5592 \layout Description
5592 5593
5593 5594
5594 5595 \backslash
5595 5596 r a carriage return
5596 5597 \layout Description
5597 5598
5598 5599
5599 5600 \backslash
5600 5601 v IPython version string
5601 5602 \layout Standard
5602 5603
5603 5604 In addition to these, ANSI color escapes can be insterted into the prompts,
5604 5605 as
5605 5606 \family typewriter
5606 5607
5607 5608 \backslash
5608 5609 C_
5609 5610 \emph on
5610 5611 ColorName
5611 5612 \family default
5612 5613 \emph default
5613 5614 .
5614 5615 The list of valid color names is: Black, Blue, Brown, Cyan, DarkGray, Green,
5615 5616 LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, NoColor,
5616 5617 Normal, Purple, Red, White, Yellow.
5617 5618 \layout Standard
5618 5619
5619 5620 Finally, IPython supports the evaluation of arbitrary expressions in your
5620 5621 prompt string.
5621 5622 The prompt strings are evaluated through the syntax of PEP 215, but basically
5622 5623 you can use
5623 5624 \family typewriter
5624 5625 $x.y
5625 5626 \family default
5626 5627 to expand the value of
5627 5628 \family typewriter
5628 5629 x.y
5629 5630 \family default
5630 5631 , and for more complicated expressions you can use braces:
5631 5632 \family typewriter
5632 5633 ${foo()+x}
5633 5634 \family default
5634 5635 will call function
5635 5636 \family typewriter
5636 5637 foo
5637 5638 \family default
5638 5639 and add to it the value of
5639 5640 \family typewriter
5640 5641 x
5641 5642 \family default
5642 5643 , before putting the result into your prompt.
5643 5644 For example, using
5644 5645 \newline
5645 5646
5646 5647 \family typewriter
5647 5648 prompt_in1 '${commands.getoutput("uptime")}
5648 5649 \backslash
5649 5650 nIn [
5650 5651 \backslash
5651 5652 #]: '
5652 5653 \newline
5653 5654
5654 5655 \family default
5655 5656 will print the result of the uptime command on each prompt (assuming the
5656 5657
5657 5658 \family typewriter
5658 5659 commands
5659 5660 \family default
5660 5661 module has been imported in your
5661 5662 \family typewriter
5662 5663 ipythonrc
5663 5664 \family default
5664 5665 file).
5665 5666 \layout Subsubsection
5666 5667
5667 5668 Prompt examples
5668 5669 \layout Standard
5669 5670
5670 5671 The following options in an ipythonrc file will give you IPython's default
5671 5672 prompts:
5672 5673 \layout Standard
5673 5674
5674 5675
5675 5676 \family typewriter
5676 5677 prompt_in1 'In [
5677 5678 \backslash
5678 5679 #]:'
5679 5680 \newline
5680 5681 prompt_in2 '\SpecialChar ~
5681 5682 \SpecialChar ~
5682 5683 \SpecialChar ~
5683 5684 .
5684 5685 \backslash
5685 5686 D.:'
5686 5687 \newline
5687 5688 prompt_out 'Out[
5688 5689 \backslash
5689 5690 #]:'
5690 5691 \layout Standard
5691 5692
5692 5693 which look like this:
5693 5694 \layout Standard
5694 5695
5695 5696
5696 5697 \family typewriter
5697 5698 In [1]: 1+2
5698 5699 \newline
5699 5700 Out[1]: 3
5700 5701 \layout Standard
5701 5702
5702 5703
5703 5704 \family typewriter
5704 5705 In [2]: for i in (1,2,3):
5705 5706 \newline
5706 5707
5707 5708 \begin_inset ERT
5708 5709 status Collapsed
5709 5710
5710 5711 \layout Standard
5711 5712
5712 5713 \backslash
5713 5714 hspace*{0mm}
5714 5715 \end_inset
5715 5716
5716 5717 \SpecialChar ~
5717 5718 \SpecialChar ~
5718 5719 \SpecialChar ~
5719 5720 ...: \SpecialChar ~
5720 5721 \SpecialChar ~
5721 5722 \SpecialChar ~
5722 5723 \SpecialChar ~
5723 5724 print i,
5724 5725 \newline
5725 5726
5726 5727 \begin_inset ERT
5727 5728 status Collapsed
5728 5729
5729 5730 \layout Standard
5730 5731
5731 5732 \backslash
5732 5733 hspace*{0mm}
5733 5734 \end_inset
5734 5735
5735 5736 \SpecialChar ~
5736 5737 \SpecialChar ~
5737 5738 \SpecialChar ~
5738 5739 ...:
5739 5740 \newline
5740 5741 1 2 3
5741 5742 \layout Standard
5742 5743
5743 5744 These will give you a very colorful prompt with path information:
5744 5745 \layout Standard
5745 5746
5746 5747
5747 5748 \family typewriter
5748 5749 #prompt_in1 '
5749 5750 \backslash
5750 5751 C_Red
5751 5752 \backslash
5752 5753 u
5753 5754 \backslash
5754 5755 C_Blue[
5755 5756 \backslash
5756 5757 C_Cyan
5757 5758 \backslash
5758 5759 Y1
5759 5760 \backslash
5760 5761 C_Blue]
5761 5762 \backslash
5762 5763 C_LightGreen
5763 5764 \backslash
5764 5765 #>'
5765 5766 \newline
5766 5767 prompt_in2 ' ..
5767 5768 \backslash
5768 5769 D>'
5769 5770 \newline
5770 5771 prompt_out '<
5771 5772 \backslash
5772 5773 #>'
5773 5774 \layout Standard
5774 5775
5775 5776 which look like this:
5776 5777 \layout Standard
5777 5778
5778 5779
5779 5780 \family typewriter
5780 5781 \color red
5781 5782 fperez
5782 5783 \color blue
5783 5784 [
5784 5785 \color cyan
5785 5786 ~/ipython
5786 5787 \color blue
5787 5788 ]
5788 5789 \color green
5789 5790 1>
5790 5791 \color default
5791 5792 1+2
5792 5793 \newline
5793 5794
5794 5795 \begin_inset ERT
5795 5796 status Collapsed
5796 5797
5797 5798 \layout Standard
5798 5799
5799 5800 \backslash
5800 5801 hspace*{0mm}
5801 5802 \end_inset
5802 5803
5803 5804 \SpecialChar ~
5804 5805 \SpecialChar ~
5805 5806 \SpecialChar ~
5806 5807 \SpecialChar ~
5807 5808 \SpecialChar ~
5808 5809 \SpecialChar ~
5809 5810 \SpecialChar ~
5810 5811 \SpecialChar ~
5811 5812 \SpecialChar ~
5812 5813 \SpecialChar ~
5813 5814 \SpecialChar ~
5814 5815 \SpecialChar ~
5815 5816 \SpecialChar ~
5816 5817 \SpecialChar ~
5817 5818 \SpecialChar ~
5818 5819 \SpecialChar ~
5819 5820
5820 5821 \color red
5821 5822 <1>
5822 5823 \color default
5823 5824 3
5824 5825 \newline
5825 5826
5826 5827 \color red
5827 5828 fperez
5828 5829 \color blue
5829 5830 [
5830 5831 \color cyan
5831 5832 ~/ipython
5832 5833 \color blue
5833 5834 ]
5834 5835 \color green
5835 5836 2>
5836 5837 \color default
5837 5838 for i in (1,2,3):
5838 5839 \newline
5839 5840
5840 5841 \begin_inset ERT
5841 5842 status Collapsed
5842 5843
5843 5844 \layout Standard
5844 5845
5845 5846 \backslash
5846 5847 hspace*{0mm}
5847 5848 \end_inset
5848 5849
5849 5850 \SpecialChar ~
5850 5851 \SpecialChar ~
5851 5852 \SpecialChar ~
5852 5853 \SpecialChar ~
5853 5854 \SpecialChar ~
5854 5855 \SpecialChar ~
5855 5856 \SpecialChar ~
5856 5857 \SpecialChar ~
5857 5858 \SpecialChar ~
5858 5859 \SpecialChar ~
5859 5860 \SpecialChar ~
5860 5861 \SpecialChar ~
5861 5862 \SpecialChar ~
5862 5863 \SpecialChar ~
5863 5864 \SpecialChar ~
5864 5865
5865 5866 \color green
5866 5867 ...>
5867 5868 \color default
5868 5869 \SpecialChar ~
5869 5870 \SpecialChar ~
5870 5871 \SpecialChar ~
5871 5872 \SpecialChar ~
5872 5873 print i,
5873 5874 \newline
5874 5875
5875 5876 \begin_inset ERT
5876 5877 status Collapsed
5877 5878
5878 5879 \layout Standard
5879 5880
5880 5881 \backslash
5881 5882 hspace*{0mm}
5882 5883 \end_inset
5883 5884
5884 5885 \SpecialChar ~
5885 5886 \SpecialChar ~
5886 5887 \SpecialChar ~
5887 5888 \SpecialChar ~
5888 5889 \SpecialChar ~
5889 5890 \SpecialChar ~
5890 5891 \SpecialChar ~
5891 5892 \SpecialChar ~
5892 5893 \SpecialChar ~
5893 5894 \SpecialChar ~
5894 5895 \SpecialChar ~
5895 5896 \SpecialChar ~
5896 5897 \SpecialChar ~
5897 5898 \SpecialChar ~
5898 5899 \SpecialChar ~
5899 5900
5900 5901 \color green
5901 5902 ...>
5902 5903 \color default
5903 5904
5904 5905 \newline
5905 5906 1 2 3
5906 5907 \layout Standard
5907 5908
5908 5909 The following shows the usage of dynamic expression evaluation:
5909 5910 \layout Subsection
5910 5911
5911 5912
5912 5913 \begin_inset LatexCommand \label{sec:profiles}
5913 5914
5914 5915 \end_inset
5915 5916
5916 5917 IPython profiles
5917 5918 \layout Standard
5918 5919
5919 5920 As we already mentioned, IPython supports the
5920 5921 \family typewriter
5921 5922 -profile
5922 5923 \family default
5923 5924 command-line option (see sec.
5924 5925
5925 5926 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
5926 5927
5927 5928 \end_inset
5928 5929
5929 5930 ).
5930 5931 A profile is nothing more than a particular configuration file like your
5931 5932 basic
5932 5933 \family typewriter
5933 5934 ipythonrc
5934 5935 \family default
5935 5936 one, but with particular customizations for a specific purpose.
5936 5937 When you start IPython with '
5937 5938 \family typewriter
5938 5939 ipython -profile <name>
5939 5940 \family default
5940 5941 ', it assumes that in your
5941 5942 \family typewriter
5942 5943 IPYTHONDIR
5943 5944 \family default
5944 5945 there is a file called
5945 5946 \family typewriter
5946 5947 ipythonrc-<name>
5947 5948 \family default
5948 5949 , and loads it instead of the normal
5949 5950 \family typewriter
5950 5951 ipythonrc
5951 5952 \family default
5952 5953 .
5953 5954 \layout Standard
5954 5955
5955 5956 This system allows you to maintain multiple configurations which load modules,
5956 5957 set options, define functions, etc.
5957 5958 suitable for different tasks and activate them in a very simple manner.
5958 5959 In order to avoid having to repeat all of your basic options (common things
5959 5960 that don't change such as your color preferences, for example), any profile
5960 5961 can include another configuration file.
5961 5962 The most common way to use profiles is then to have each one include your
5962 5963 basic
5963 5964 \family typewriter
5964 5965 ipythonrc
5965 5966 \family default
5966 5967 file as a starting point, and then add further customizations.
5967 5968 \layout Standard
5968 5969
5969 5970 In sections
5970 5971 \begin_inset LatexCommand \ref{sec:syntax-extensions}
5971 5972
5972 5973 \end_inset
5973 5974
5974 5975 and
5975 5976 \begin_inset LatexCommand \ref{sec:Gnuplot}
5976 5977
5977 5978 \end_inset
5978 5979
5979 5980 we discuss some particular profiles which come as part of the standard
5980 5981 IPython distribution.
5981 5982 You may also look in your
5982 5983 \family typewriter
5983 5984 IPYTHONDIR
5984 5985 \family default
5985 5986 directory, any file whose name begins with
5986 5987 \family typewriter
5987 5988 ipythonrc-
5988 5989 \family default
5989 5990 is a profile.
5990 5991 You can use those as examples for further customizations to suit your own
5991 5992 needs.
5992 5993 \layout Section
5993 5994
5994 5995
5995 5996 \begin_inset OptArg
5996 5997 collapsed false
5997 5998
5998 5999 \layout Standard
5999 6000
6000 6001 IPython as default...
6001 6002 \end_inset
6002 6003
6003 6004 IPython as your default Python environment
6004 6005 \layout Standard
6005 6006
6006 6007 Python honors the environment variable
6007 6008 \family typewriter
6008 6009 PYTHONSTARTUP
6009 6010 \family default
6010 6011 and will execute at startup the file referenced by this variable.
6011 6012 If you put at the end of this file the following two lines of code:
6012 6013 \layout Standard
6013 6014
6014 6015
6015 6016 \family typewriter
6016 6017 import IPython
6017 6018 \newline
6018 6019 IPython.Shell.IPShell().mainloop(sys_exit=1)
6019 6020 \layout Standard
6020 6021
6021 6022 then IPython will be your working environment anytime you start Python.
6022 6023 The
6023 6024 \family typewriter
6024 6025 sys_exit=1
6025 6026 \family default
6026 6027 is needed to have IPython issue a call to
6027 6028 \family typewriter
6028 6029 sys.exit()
6029 6030 \family default
6030 6031 when it finishes, otherwise you'll be back at the normal Python '
6031 6032 \family typewriter
6032 6033 >>>
6033 6034 \family default
6034 6035 ' prompt
6035 6036 \begin_inset Foot
6036 6037 collapsed true
6037 6038
6038 6039 \layout Standard
6039 6040
6040 6041 Based on an idea by Holger Krekel.
6041 6042 \end_inset
6042 6043
6043 6044 .
6044 6045 \layout Standard
6045 6046
6046 6047 This is probably useful to developers who manage multiple Python versions
6047 6048 and don't want to have correspondingly multiple IPython versions.
6048 6049 Note that in this mode, there is no way to pass IPython any command-line
6049 6050 options, as those are trapped first by Python itself.
6050 6051 \layout Section
6051 6052
6052 6053
6053 6054 \begin_inset LatexCommand \label{sec:embed}
6054 6055
6055 6056 \end_inset
6056 6057
6057 6058 Embedding IPython
6058 6059 \layout Standard
6059 6060
6060 6061 It is possible to start an IPython instance
6061 6062 \emph on
6062 6063 inside
6063 6064 \emph default
6064 6065 your own Python programs.
6065 6066 This allows you to evaluate dynamically the state of your code, operate
6066 6067 with your variables, analyze them, etc.
6067 6068 Note however that any changes you make to values while in the shell do
6068 6069
6069 6070 \emph on
6070 6071 not
6071 6072 \emph default
6072 6073 propagate back to the running code, so it is safe to modify your values
6073 6074 because you won't break your code in bizarre ways by doing so.
6074 6075 \layout Standard
6075 6076
6076 6077 This feature allows you to easily have a fully functional python environment
6077 6078 for doing object introspection anywhere in your code with a simple function
6078 6079 call.
6079 6080 In some cases a simple print statement is enough, but if you need to do
6080 6081 more detailed analysis of a code fragment this feature can be very valuable.
6081 6082 \layout Standard
6082 6083
6083 6084 It can also be useful in scientific computing situations where it is common
6084 6085 to need to do some automatic, computationally intensive part and then stop
6085 6086 to look at data, plots, etc
6086 6087 \begin_inset Foot
6087 6088 collapsed true
6088 6089
6089 6090 \layout Standard
6090 6091
6091 6092 This functionality was inspired by IDL's combination of the
6092 6093 \family typewriter
6093 6094 stop
6094 6095 \family default
6095 6096 keyword and the
6096 6097 \family typewriter
6097 6098 .continue
6098 6099 \family default
6099 6100 executive command, which I have found very useful in the past, and by a
6100 6101 posting on comp.lang.python by cmkl <cmkleffner-AT-gmx.de> on Dec.
6101 6102 06/01 concerning similar uses of pyrepl.
6102 6103 \end_inset
6103 6104
6104 6105 .
6105 6106 Opening an IPython instance will give you full access to your data and
6106 6107 functions, and you can resume program execution once you are done with
6107 6108 the interactive part (perhaps to stop again later, as many times as needed).
6108 6109 \layout Standard
6109 6110
6110 6111 The following code snippet is the bare minimum you need to include in your
6111 6112 Python programs for this to work (detailed examples follow later):
6112 6113 \layout LyX-Code
6113 6114
6114 6115 from IPython.Shell import IPShellEmbed
6115 6116 \layout LyX-Code
6116 6117
6117 6118 ipshell = IPShellEmbed()
6118 6119 \layout LyX-Code
6119 6120
6120 6121 ipshell() # this call anywhere in your program will start IPython
6121 6122 \layout Standard
6122 6123
6123 6124 You can run embedded instances even in code which is itself being run at
6124 6125 the IPython interactive prompt with '
6125 6126 \family typewriter
6126 6127 %run\SpecialChar ~
6127 6128 <filename>
6128 6129 \family default
6129 6130 '.
6130 6131 Since it's easy to get lost as to where you are (in your top-level IPython
6131 6132 or in your embedded one), it's a good idea in such cases to set the in/out
6132 6133 prompts to something different for the embedded instances.
6133 6134 The code examples below illustrate this.
6134 6135 \layout Standard
6135 6136
6136 6137 You can also have multiple IPython instances in your program and open them
6137 6138 separately, for example with different options for data presentation.
6138 6139 If you close and open the same instance multiple times, its prompt counters
6139 6140 simply continue from each execution to the next.
6140 6141 \layout Standard
6141 6142
6142 6143 Please look at the docstrings in the
6143 6144 \family typewriter
6144 6145 Shell.py
6145 6146 \family default
6146 6147 module for more details on the use of this system.
6147 6148 \layout Standard
6148 6149
6149 6150 The following sample file illustrating how to use the embedding functionality
6150 6151 is provided in the examples directory as
6151 6152 \family typewriter
6152 6153 example-embed.py
6153 6154 \family default
6154 6155 .
6155 6156 It should be fairly self-explanatory:
6156 6157 \layout Standard
6157 6158
6158 6159
6159 6160 \begin_inset ERT
6160 6161 status Open
6161 6162
6162 6163 \layout Standard
6163 6164
6164 6165 \backslash
6165 6166 codelist{examples/example-embed.py}
6166 6167 \end_inset
6167 6168
6168 6169
6169 6170 \layout Standard
6170 6171
6171 6172 Once you understand how the system functions, you can use the following
6172 6173 code fragments in your programs which are ready for cut and paste:
6173 6174 \layout Standard
6174 6175
6175 6176
6176 6177 \begin_inset ERT
6177 6178 status Open
6178 6179
6179 6180 \layout Standard
6180 6181
6181 6182 \backslash
6182 6183 codelist{examples/example-embed-short.py}
6183 6184 \end_inset
6184 6185
6185 6186
6186 6187 \layout Section
6187 6188
6188 6189
6189 6190 \begin_inset LatexCommand \label{sec:using-pdb}
6190 6191
6191 6192 \end_inset
6192 6193
6193 6194 Using the Python debugger (
6194 6195 \family typewriter
6195 6196 pdb
6196 6197 \family default
6197 6198 )
6198 6199 \layout Subsection
6199 6200
6200 6201 Running entire programs via
6201 6202 \family typewriter
6202 6203 pdb
6203 6204 \layout Standard
6204 6205
6205 6206
6206 6207 \family typewriter
6207 6208 pdb
6208 6209 \family default
6209 6210 , the Python debugger, is a powerful interactive debugger which allows you
6210 6211 to step through code, set breakpoints, watch variables, etc.
6211 6212 IPython makes it very easy to start any script under the control of
6212 6213 \family typewriter
6213 6214 pdb
6214 6215 \family default
6215 6216 , regardless of whether you have wrapped it into a
6216 6217 \family typewriter
6217 6218 `main()'
6218 6219 \family default
6219 6220 function or not.
6220 6221 For this, simply type
6221 6222 \family typewriter
6222 6223 `%run -d myscript'
6223 6224 \family default
6224 6225 at an IPython prompt.
6225 6226 See the
6226 6227 \family typewriter
6227 6228 %run
6228 6229 \family default
6229 6230 command's documentation (via
6230 6231 \family typewriter
6231 6232 `%run?'
6232 6233 \family default
6233 6234 or in Sec.\SpecialChar ~
6234 6235
6235 6236 \begin_inset LatexCommand \ref{sec:magic}
6236 6237
6237 6238 \end_inset
6238 6239
6239 6240 ) for more details, including how to control where
6240 6241 \family typewriter
6241 6242 pdb
6242 6243 \family default
6243 6244 will stop execution first.
6244 6245 \layout Standard
6245 6246
6246 6247 For more information on the use of the
6247 6248 \family typewriter
6248 6249 pdb
6249 6250 \family default
6250 6251 debugger, read the included
6251 6252 \family typewriter
6252 6253 pdb.doc
6253 6254 \family default
6254 6255 file (part of the standard Python distribution).
6255 6256 On a stock Linux system it is located at
6256 6257 \family typewriter
6257 6258 /usr/lib/python2.3/pdb.doc
6258 6259 \family default
6259 6260 , but the easiest way to read it is by using the
6260 6261 \family typewriter
6261 6262 help()
6262 6263 \family default
6263 6264 function of the
6264 6265 \family typewriter
6265 6266 pdb
6266 6267 \family default
6267 6268 module as follows (in an IPython prompt):
6268 6269 \layout Standard
6269 6270
6270 6271
6271 6272 \family typewriter
6272 6273 In [1]: import pdb
6273 6274 \newline
6274 6275 In [2]: pdb.help()
6275 6276 \layout Standard
6276 6277
6277 6278 This will load the
6278 6279 \family typewriter
6279 6280 pdb.doc
6280 6281 \family default
6281 6282 document in a file viewer for you automatically.
6282 6283 \layout Subsection
6283 6284
6284 6285 Automatic invocation of
6285 6286 \family typewriter
6286 6287 pdb
6287 6288 \family default
6288 6289 on exceptions
6289 6290 \layout Standard
6290 6291
6291 6292 IPython, if started with the
6292 6293 \family typewriter
6293 6294 -pdb
6294 6295 \family default
6295 6296 option (or if the option is set in your rc file) can call the Python
6296 6297 \family typewriter
6297 6298 pdb
6298 6299 \family default
6299 6300 debugger every time your code triggers an uncaught exception
6300 6301 \begin_inset Foot
6301 6302 collapsed true
6302 6303
6303 6304 \layout Standard
6304 6305
6305 6306 Many thanks to Christopher Hart for the request which prompted adding this
6306 6307 feature to IPython.
6307 6308 \end_inset
6308 6309
6309 6310 .
6310 6311 This feature can also be toggled at any time with the
6311 6312 \family typewriter
6312 6313 %pdb
6313 6314 \family default
6314 6315 magic command.
6315 6316 This can be extremely useful in order to find the origin of subtle bugs,
6316 6317 because
6317 6318 \family typewriter
6318 6319 pdb
6319 6320 \family default
6320 6321 opens up at the point in your code which triggered the exception, and while
6321 6322 your program is at this point `dead', all the data is still available and
6322 6323 you can walk up and down the stack frame and understand the origin of the
6323 6324 problem.
6324 6325 \layout Standard
6325 6326
6326 6327 Furthermore, you can use these debugging facilities both with the embedded
6327 6328 IPython mode and without IPython at all.
6328 6329 For an embedded shell (see sec.
6329 6330
6330 6331 \begin_inset LatexCommand \ref{sec:embed}
6331 6332
6332 6333 \end_inset
6333 6334
6334 6335 ), simply call the constructor with
6335 6336 \family typewriter
6336 6337 `-pdb'
6337 6338 \family default
6338 6339 in the argument string and automatically
6339 6340 \family typewriter
6340 6341 pdb
6341 6342 \family default
6342 6343 will be called if an uncaught exception is triggered by your code.
6343 6344
6344 6345 \layout Standard
6345 6346
6346 6347 For stand-alone use of the feature in your programs which do not use IPython
6347 6348 at all, put the following lines toward the top of your `main' routine:
6348 6349 \layout Standard
6349 6350 \align left
6350 6351
6351 6352 \family typewriter
6352 6353 import sys,IPython.ultraTB
6353 6354 \newline
6354 6355 sys.excepthook = IPython.ultraTB.FormattedTB(mode=`Verbose', color_scheme=`Linux',
6355 6356 call_pdb=1)
6356 6357 \layout Standard
6357 6358
6358 6359 The
6359 6360 \family typewriter
6360 6361 mode
6361 6362 \family default
6362 6363 keyword can be either
6363 6364 \family typewriter
6364 6365 `Verbose'
6365 6366 \family default
6366 6367 or
6367 6368 \family typewriter
6368 6369 `Plain'
6369 6370 \family default
6370 6371 , giving either very detailed or normal tracebacks respectively.
6371 6372 The
6372 6373 \family typewriter
6373 6374 color_scheme
6374 6375 \family default
6375 6376 keyword can be one of
6376 6377 \family typewriter
6377 6378 `NoColor'
6378 6379 \family default
6379 6380 ,
6380 6381 \family typewriter
6381 6382 `Linux'
6382 6383 \family default
6383 6384 (default) or
6384 6385 \family typewriter
6385 6386 `LightBG'
6386 6387 \family default
6387 6388 .
6388 6389 These are the same options which can be set in IPython with
6389 6390 \family typewriter
6390 6391 -colors
6391 6392 \family default
6392 6393 and
6393 6394 \family typewriter
6394 6395 -xmode
6395 6396 \family default
6396 6397 .
6397 6398 \layout Standard
6398 6399
6399 6400 This will give any of your programs detailed, colored tracebacks with automatic
6400 6401 invocation of
6401 6402 \family typewriter
6402 6403 pdb
6403 6404 \family default
6404 6405 .
6405 6406 \layout Section
6406 6407
6407 6408
6408 6409 \begin_inset LatexCommand \label{sec:syntax-extensions}
6409 6410
6410 6411 \end_inset
6411 6412
6412 6413 Extensions for syntax processing
6413 6414 \layout Standard
6414 6415
6415 6416 This isn't for the faint of heart, because the potential for breaking things
6416 6417 is quite high.
6417 6418 But it can be a very powerful and useful feature.
6418 6419 In a nutshell, you can redefine the way IPython processes the user input
6419 6420 line to accept new, special extensions to the syntax without needing to
6420 6421 change any of IPython's own code.
6421 6422 \layout Standard
6422 6423
6423 6424 In the
6424 6425 \family typewriter
6425 6426 IPython/Extensions
6426 6427 \family default
6427 6428 directory you will find some examples supplied, which we will briefly describe
6428 6429 now.
6429 6430 These can be used `as is' (and both provide very useful functionality),
6430 6431 or you can use them as a starting point for writing your own extensions.
6431 6432 \layout Subsection
6432 6433
6433 6434 Pasting of code starting with
6434 6435 \family typewriter
6435 6436 `>>>
6436 6437 \family default
6437 6438 ' or
6438 6439 \family typewriter
6439 6440 `...
6440 6441
6441 6442 \family default
6442 6443 '
6443 6444 \layout Standard
6444 6445
6445 6446 In the python tutorial it is common to find code examples which have been
6446 6447 taken from real python sessions.
6447 6448 The problem with those is that all the lines begin with either
6448 6449 \family typewriter
6449 6450 `>>>
6450 6451 \family default
6451 6452 ' or
6452 6453 \family typewriter
6453 6454 `...
6454 6455
6455 6456 \family default
6456 6457 ', which makes it impossible to paste them all at once.
6457 6458 One must instead do a line by line manual copying, carefully removing the
6458 6459 leading extraneous characters.
6459 6460 \layout Standard
6460 6461
6461 6462 This extension identifies those starting characters and removes them from
6462 6463 the input automatically, so that one can paste multi-line examples directly
6463 6464 into IPython, saving a lot of time.
6464 6465 Please look at the file
6465 6466 \family typewriter
6466 6467 InterpreterPasteInput.py
6467 6468 \family default
6468 6469 in the
6469 6470 \family typewriter
6470 6471 IPython/Extensions
6471 6472 \family default
6472 6473 directory for details on how this is done.
6473 6474 \layout Standard
6474 6475
6475 6476 IPython comes with a special profile enabling this feature, called
6476 6477 \family typewriter
6477 6478 tutorial
6478 6479 \family default
6479 6480 \emph on
6480 6481 .
6481 6482
6482 6483 \emph default
6483 6484 Simply start IPython via
6484 6485 \family typewriter
6485 6486 `ipython\SpecialChar ~
6486 6487 -p\SpecialChar ~
6487 6488 tutorial'
6488 6489 \family default
6489 6490 and the feature will be available.
6490 6491 In a normal IPython session you can activate the feature by importing the
6491 6492 corresponding module with:
6492 6493 \newline
6493 6494
6494 6495 \family typewriter
6495 6496 In [1]: import IPython.Extensions.InterpreterPasteInput
6496 6497 \layout Standard
6497 6498
6498 6499 The following is a 'screenshot' of how things work when this extension is
6499 6500 on, copying an example from the standard tutorial:
6500 6501 \layout Standard
6501 6502
6502 6503
6503 6504 \family typewriter
6504 6505 IPython profile: tutorial
6505 6506 \newline
6506 6507 \SpecialChar ~
6507 6508
6508 6509 \newline
6509 6510 *** Pasting of code with ">>>" or "..." has been enabled.
6510 6511 \newline
6511 6512 \SpecialChar ~
6512 6513
6513 6514 \newline
6514 6515 In [1]: >>> def fib2(n): # return Fibonacci series up to n
6515 6516 \newline
6516 6517
6517 6518 \begin_inset ERT
6518 6519 status Collapsed
6519 6520
6520 6521 \layout Standard
6521 6522
6522 6523 \backslash
6523 6524 hspace*{0mm}
6524 6525 \end_inset
6525 6526
6526 6527 \SpecialChar ~
6527 6528 \SpecialChar ~
6528 6529 ...: ...\SpecialChar ~
6529 6530 \SpecialChar ~
6530 6531 \SpecialChar ~
6531 6532 \SpecialChar ~
6532 6533 """Return a list containing the Fibonacci series up to n."""
6533 6534 \newline
6534 6535
6535 6536 \begin_inset ERT
6536 6537 status Collapsed
6537 6538
6538 6539 \layout Standard
6539 6540
6540 6541 \backslash
6541 6542 hspace*{0mm}
6542 6543 \end_inset
6543 6544
6544 6545 \SpecialChar ~
6545 6546 \SpecialChar ~
6546 6547 ...: ...\SpecialChar ~
6547 6548 \SpecialChar ~
6548 6549 \SpecialChar ~
6549 6550 \SpecialChar ~
6550 6551 result = []
6551 6552 \newline
6552 6553
6553 6554 \begin_inset ERT
6554 6555 status Collapsed
6555 6556
6556 6557 \layout Standard
6557 6558
6558 6559 \backslash
6559 6560 hspace*{0mm}
6560 6561 \end_inset
6561 6562
6562 6563 \SpecialChar ~
6563 6564 \SpecialChar ~
6564 6565 ...: ...\SpecialChar ~
6565 6566 \SpecialChar ~
6566 6567 \SpecialChar ~
6567 6568 \SpecialChar ~
6568 6569 a, b = 0, 1
6569 6570 \newline
6570 6571
6571 6572 \begin_inset ERT
6572 6573 status Collapsed
6573 6574
6574 6575 \layout Standard
6575 6576
6576 6577 \backslash
6577 6578 hspace*{0mm}
6578 6579 \end_inset
6579 6580
6580 6581 \SpecialChar ~
6581 6582 \SpecialChar ~
6582 6583 ...: ...\SpecialChar ~
6583 6584 \SpecialChar ~
6584 6585 \SpecialChar ~
6585 6586 \SpecialChar ~
6586 6587 while b < n:
6587 6588 \newline
6588 6589
6589 6590 \begin_inset ERT
6590 6591 status Collapsed
6591 6592
6592 6593 \layout Standard
6593 6594
6594 6595 \backslash
6595 6596 hspace*{0mm}
6596 6597 \end_inset
6597 6598
6598 6599 \SpecialChar ~
6599 6600 \SpecialChar ~
6600 6601 ...: ...\SpecialChar ~
6601 6602 \SpecialChar ~
6602 6603 \SpecialChar ~
6603 6604 \SpecialChar ~
6604 6605 \SpecialChar ~
6605 6606 \SpecialChar ~
6606 6607 \SpecialChar ~
6607 6608 \SpecialChar ~
6608 6609 result.append(b)\SpecialChar ~
6609 6610 \SpecialChar ~
6610 6611 \SpecialChar ~
6611 6612 # see below
6612 6613 \newline
6613 6614
6614 6615 \begin_inset ERT
6615 6616 status Collapsed
6616 6617
6617 6618 \layout Standard
6618 6619
6619 6620 \backslash
6620 6621 hspace*{0mm}
6621 6622 \end_inset
6622 6623
6623 6624 \SpecialChar ~
6624 6625 \SpecialChar ~
6625 6626 ...: ...\SpecialChar ~
6626 6627 \SpecialChar ~
6627 6628 \SpecialChar ~
6628 6629 \SpecialChar ~
6629 6630 \SpecialChar ~
6630 6631 \SpecialChar ~
6631 6632 \SpecialChar ~
6632 6633 \SpecialChar ~
6633 6634 a, b = b, a+b
6634 6635 \newline
6635 6636
6636 6637 \begin_inset ERT
6637 6638 status Collapsed
6638 6639
6639 6640 \layout Standard
6640 6641
6641 6642 \backslash
6642 6643 hspace*{0mm}
6643 6644 \end_inset
6644 6645
6645 6646 \SpecialChar ~
6646 6647 \SpecialChar ~
6647 6648 ...: ...\SpecialChar ~
6648 6649 \SpecialChar ~
6649 6650 \SpecialChar ~
6650 6651 \SpecialChar ~
6651 6652 return result
6652 6653 \newline
6653 6654
6654 6655 \begin_inset ERT
6655 6656 status Collapsed
6656 6657
6657 6658 \layout Standard
6658 6659
6659 6660 \backslash
6660 6661 hspace*{0mm}
6661 6662 \end_inset
6662 6663
6663 6664 \SpecialChar ~
6664 6665 \SpecialChar ~
6665 6666 ...:
6666 6667 \newline
6667 6668 \SpecialChar ~
6668 6669
6669 6670 \newline
6670 6671 In [2]: fib2(10)
6671 6672 \newline
6672 6673 Out[2]: [1, 1, 2, 3, 5, 8]
6673 6674 \layout Standard
6674 6675
6675 6676 Note that as currently written, this extension does
6676 6677 \emph on
6677 6678 not
6678 6679 \emph default
6679 6680 recognize IPython's prompts for pasting.
6680 6681 Those are more complicated, since the user can change them very easily,
6681 6682 they involve numbers and can vary in length.
6682 6683 One could however extract all the relevant information from the IPython
6683 6684 instance and build an appropriate regular expression.
6684 6685 This is left as an exercise for the reader.
6685 6686 \layout Subsection
6686 6687
6687 6688 Input of physical quantities with units
6688 6689 \layout Standard
6689 6690
6690 6691 The module
6691 6692 \family typewriter
6692 6693 PhysicalQInput
6693 6694 \family default
6694 6695 allows a simplified form of input for physical quantities with units.
6695 6696 This file is meant to be used in conjunction with the
6696 6697 \family typewriter
6697 6698 PhysicalQInteractive
6698 6699 \family default
6699 6700 module (in the same directory) and
6700 6701 \family typewriter
6701 6702 Physics.PhysicalQuantities
6702 6703 \family default
6703 6704 from Konrad Hinsen's ScientificPython (
6704 6705 \begin_inset LatexCommand \htmlurl{http://starship.python.net/crew/hinsen/scientific.html}
6705 6706
6706 6707 \end_inset
6707 6708
6708 6709 ).
6709 6710 \layout Standard
6710 6711
6711 6712 The
6712 6713 \family typewriter
6713 6714 Physics.PhysicalQuantities
6714 6715 \family default
6715 6716 module defines
6716 6717 \family typewriter
6717 6718 PhysicalQuantity
6718 6719 \family default
6719 6720 objects, but these must be declared as instances of a class.
6720 6721 For example, to define
6721 6722 \family typewriter
6722 6723 v
6723 6724 \family default
6724 6725 as a velocity of 3\SpecialChar ~
6725 6726 m/s, normally you would write:
6726 6727 \family typewriter
6727 6728
6728 6729 \newline
6729 6730 In [1]: v = PhysicalQuantity(3,'m/s')
6730 6731 \layout Standard
6731 6732
6732 6733 Using the
6733 6734 \family typewriter
6734 6735 PhysicalQ_Input
6735 6736 \family default
6736 6737 extension this can be input instead as:
6737 6738 \family typewriter
6738 6739
6739 6740 \newline
6740 6741 In [1]: v = 3 m/s
6741 6742 \family default
6742 6743
6743 6744 \newline
6744 6745 which is much more convenient for interactive use (even though it is blatantly
6745 6746 invalid Python syntax).
6746 6747 \layout Standard
6747 6748
6748 6749 The
6749 6750 \family typewriter
6750 6751 physics
6751 6752 \family default
6752 6753 profile supplied with IPython (enabled via
6753 6754 \family typewriter
6754 6755 'ipython -p physics'
6755 6756 \family default
6756 6757 ) uses these extensions, which you can also activate with:
6757 6758 \layout Standard
6758 6759
6759 6760
6760 6761 \family typewriter
6761 6762 from math import * # math MUST be imported BEFORE PhysicalQInteractive
6762 6763 \newline
6763 6764 from IPython.Extensions.PhysicalQInteractive import *
6764 6765 \newline
6765 6766 import IPython.Extensions.PhysicalQInput
6766 6767 \layout Section
6767 6768
6768 6769 IPython as a system shell
6769 6770 \layout Standard
6770 6771
6771 6772 IPython ships with a special profile called
6772 6773 \family typewriter
6773 6774 pysh
6774 6775 \family default
6775 6776 , which you can activate at the command line as
6776 6777 \family typewriter
6777 6778 `ipython -p pysh'
6778 6779 \family default
6779 6780 .
6780 6781 This loads
6781 6782 \family typewriter
6782 6783 InterpreterExec
6783 6784 \family default
6784 6785 , along with some additional facilities and a prompt customized for filesystem
6785 6786 navigation.
6786 6787 \layout Standard
6787 6788
6788 6789 Note that this does
6789 6790 \emph on
6790 6791 not
6791 6792 \emph default
6792 6793 make IPython a full-fledged system shell.
6793 6794 In particular, it has no job control, so if you type Ctrl-Z (under Unix),
6794 6795 you'll suspend pysh itself, not the process you just started.
6795 6796
6796 6797 \layout Standard
6797 6798
6798 6799 What the shell profile allows you to do is to use the convenient and powerful
6799 6800 syntax of Python to do quick scripting at the command line.
6800 6801 Below we describe some of its features.
6801 6802 \layout Subsection
6802 6803
6803 6804 Aliases
6804 6805 \layout Standard
6805 6806
6806 6807 All of your
6807 6808 \family typewriter
6808 6809 $PATH
6809 6810 \family default
6810 6811 has been loaded as IPython aliases, so you should be able to type any normal
6811 6812 system command and have it executed.
6812 6813 See
6813 6814 \family typewriter
6814 6815 %alias?
6815 6816 \family default
6816 6817 and
6817 6818 \family typewriter
6818 6819 %unalias?
6819 6820 \family default
6820 6821 for details on the alias facilities.
6821 6822 See also
6822 6823 \family typewriter
6823 6824 %rehash?
6824 6825 \family default
6825 6826 and
6826 6827 \family typewriter
6827 6828 %rehashx?
6828 6829 \family default
6829 6830 for details on the mechanism used to load
6830 6831 \family typewriter
6831 6832 $PATH
6832 6833 \family default
6833 6834 .
6834 6835 \layout Subsection
6835 6836
6836 6837 Special syntax
6837 6838 \layout Standard
6838 6839
6839 6840 Any lines which begin with
6840 6841 \family typewriter
6841 6842 `~'
6842 6843 \family default
6843 6844 ,
6844 6845 \family typewriter
6845 6846 `/'
6846 6847 \family default
6847 6848 and
6848 6849 \family typewriter
6849 6850 `.'
6850 6851 \family default
6851 6852 will be executed as shell commands instead of as Python code.
6852 6853 The special escapes below are also recognized.
6853 6854
6854 6855 \family typewriter
6855 6856 !cmd
6856 6857 \family default
6857 6858 is valid in single or multi-line input, all others are only valid in single-lin
6858 6859 e input:
6859 6860 \layout Description
6860 6861
6861 6862
6862 6863 \family typewriter
6863 6864 !cmd
6864 6865 \family default
6865 6866 pass `cmd' directly to the shell
6866 6867 \layout Description
6867 6868
6868 6869
6869 6870 \family typewriter
6870 6871 !!cmd
6871 6872 \family default
6872 6873 execute `cmd' and return output as a list (split on `
6873 6874 \backslash
6874 6875 n')
6875 6876 \layout Description
6876 6877
6877 6878
6878 6879 \family typewriter
6879 6880 $var=cmd
6880 6881 \family default
6881 6882 capture output of cmd into var, as a string
6882 6883 \layout Description
6883 6884
6884 6885
6885 6886 \family typewriter
6886 6887 $$var=cmd
6887 6888 \family default
6888 6889 capture output of cmd into var, as a list (split on `
6889 6890 \backslash
6890 6891 n')
6891 6892 \layout Standard
6892 6893
6893 6894 The
6894 6895 \family typewriter
6895 6896 $
6896 6897 \family default
6897 6898 /
6898 6899 \family typewriter
6899 6900 $$
6900 6901 \family default
6901 6902 syntaxes make Python variables from system output, which you can later
6902 6903 use for further scripting.
6903 6904 The converse is also possible: when executing an alias or calling to the
6904 6905 system via
6905 6906 \family typewriter
6906 6907 !
6907 6908 \family default
6908 6909 /
6909 6910 \family typewriter
6910 6911 !!
6911 6912 \family default
6912 6913 , you can expand any python variable or expression by prepending it with
6913 6914
6914 6915 \family typewriter
6915 6916 $
6916 6917 \family default
6917 6918 .
6918 6919 Full details of the allowed syntax can be found in Python's PEP 215.
6919 6920 \layout Standard
6920 6921
6921 6922 A few brief examples will illustrate these (note that the indentation below
6922 6923 may be incorrectly displayed):
6923 6924 \layout Standard
6924 6925
6925 6926
6926 6927 \family typewriter
6927 6928 fperez[~/test]|3> !ls *s.py
6928 6929 \newline
6929 6930 scopes.py strings.py
6930 6931 \layout Standard
6931 6932
6932 6933 ls is an internal alias, so there's no need to use
6933 6934 \family typewriter
6934 6935 !
6935 6936 \family default
6936 6937 :
6937 6938 \layout Standard
6938 6939
6939 6940
6940 6941 \family typewriter
6941 6942 fperez[~/test]|4> ls *s.py
6942 6943 \newline
6943 6944 scopes.py* strings.py
6944 6945 \layout Standard
6945 6946
6946 6947 !!ls will return the output into a Python variable:
6947 6948 \layout Standard
6948 6949
6949 6950
6950 6951 \family typewriter
6951 6952 fperez[~/test]|5> !!ls *s.py
6952 6953 \newline
6953 6954
6954 6955 \begin_inset ERT
6955 6956 status Collapsed
6956 6957
6957 6958 \layout Standard
6958 6959
6959 6960 \backslash
6960 6961 hspace*{0mm}
6961 6962 \end_inset
6962 6963
6963 6964 \SpecialChar ~
6964 6965 \SpecialChar ~
6965 6966 \SpecialChar ~
6966 6967 \SpecialChar ~
6967 6968 \SpecialChar ~
6968 6969 \SpecialChar ~
6969 6970 \SpecialChar ~
6970 6971 \SpecialChar ~
6971 6972 \SpecialChar ~
6972 6973 \SpecialChar ~
6973 6974 \SpecialChar ~
6974 6975 \SpecialChar ~
6975 6976 \SpecialChar ~
6976 6977 \SpecialChar ~
6977 6978 <5> ['scopes.py', 'strings.py']
6978 6979 \newline
6979 6980 fperez[~/test]|6> print _5
6980 6981 \newline
6981 6982 ['scopes.py', 'strings.py']
6982 6983 \layout Standard
6983 6984
6984 6985
6985 6986 \family typewriter
6986 6987 $
6987 6988 \family default
6988 6989 and
6989 6990 \family typewriter
6990 6991 $$
6991 6992 \family default
6992 6993 allow direct capture to named variables:
6993 6994 \layout Standard
6994 6995
6995 6996
6996 6997 \family typewriter
6997 6998 fperez[~/test]|7> $astr = ls *s.py
6998 6999 \newline
6999 7000 fperez[~/test]|8> astr
7000 7001 \newline
7001 7002
7002 7003 \begin_inset ERT
7003 7004 status Collapsed
7004 7005
7005 7006 \layout Standard
7006 7007
7007 7008 \backslash
7008 7009 hspace*{0mm}
7009 7010 \end_inset
7010 7011
7011 7012 \SpecialChar ~
7012 7013 \SpecialChar ~
7013 7014 \SpecialChar ~
7014 7015 \SpecialChar ~
7015 7016 \SpecialChar ~
7016 7017 \SpecialChar ~
7017 7018 \SpecialChar ~
7018 7019 \SpecialChar ~
7019 7020 \SpecialChar ~
7020 7021 \SpecialChar ~
7021 7022 \SpecialChar ~
7022 7023 \SpecialChar ~
7023 7024 \SpecialChar ~
7024 7025 \SpecialChar ~
7025 7026 <8> 'scopes.py
7026 7027 \backslash
7027 7028 nstrings.py'
7028 7029 \layout Standard
7029 7030
7030 7031
7031 7032 \family typewriter
7032 7033 fperez[~/test]|9> $$alist = ls *s.py
7033 7034 \newline
7034 7035 fperez[~/test]|10> alist
7035 7036 \newline
7036 7037
7037 7038 \begin_inset ERT
7038 7039 status Collapsed
7039 7040
7040 7041 \layout Standard
7041 7042
7042 7043 \backslash
7043 7044 hspace*{0mm}
7044 7045 \end_inset
7045 7046
7046 7047 \SpecialChar ~
7047 7048 \SpecialChar ~
7048 7049 \SpecialChar ~
7049 7050 \SpecialChar ~
7050 7051 \SpecialChar ~
7051 7052 \SpecialChar ~
7052 7053 \SpecialChar ~
7053 7054 \SpecialChar ~
7054 7055 \SpecialChar ~
7055 7056 \SpecialChar ~
7056 7057 \SpecialChar ~
7057 7058 \SpecialChar ~
7058 7059 \SpecialChar ~
7059 7060 \SpecialChar ~
7060 7061 <10> ['scopes.py', 'strings.py']
7061 7062 \layout Standard
7062 7063
7063 7064 alist is now a normal python list you can loop over.
7064 7065 Using
7065 7066 \family typewriter
7066 7067 $
7067 7068 \family default
7068 7069 will expand back the python values when alias calls are made:
7069 7070 \layout Standard
7070 7071
7071 7072
7072 7073 \family typewriter
7073 7074 fperez[~/test]|11> for f in alist:
7074 7075 \newline
7075 7076
7076 7077 \begin_inset ERT
7077 7078 status Collapsed
7078 7079
7079 7080 \layout Standard
7080 7081
7081 7082 \backslash
7082 7083 hspace*{0mm}
7083 7084 \end_inset
7084 7085
7085 7086 \SpecialChar ~
7086 7087 \SpecialChar ~
7087 7088 \SpecialChar ~
7088 7089 \SpecialChar ~
7089 7090 \SpecialChar ~
7090 7091 \SpecialChar ~
7091 7092 \SpecialChar ~
7092 7093 \SpecialChar ~
7093 7094 \SpecialChar ~
7094 7095 \SpecialChar ~
7095 7096 \SpecialChar ~
7096 7097 \SpecialChar ~
7097 7098 \SpecialChar ~
7098 7099 \SpecialChar ~
7099 7100 |..> \SpecialChar ~
7100 7101 \SpecialChar ~
7101 7102 \SpecialChar ~
7102 7103 \SpecialChar ~
7103 7104 print 'file',f,
7104 7105 \newline
7105 7106
7106 7107 \begin_inset ERT
7107 7108 status Collapsed
7108 7109
7109 7110 \layout Standard
7110 7111
7111 7112 \backslash
7112 7113 hspace*{0mm}
7113 7114 \end_inset
7114 7115
7115 7116 \SpecialChar ~
7116 7117 \SpecialChar ~
7117 7118 \SpecialChar ~
7118 7119 \SpecialChar ~
7119 7120 \SpecialChar ~
7120 7121 \SpecialChar ~
7121 7122 \SpecialChar ~
7122 7123 \SpecialChar ~
7123 7124 \SpecialChar ~
7124 7125 \SpecialChar ~
7125 7126 \SpecialChar ~
7126 7127 \SpecialChar ~
7127 7128 \SpecialChar ~
7128 7129 \SpecialChar ~
7129 7130 |..> \SpecialChar ~
7130 7131 \SpecialChar ~
7131 7132 \SpecialChar ~
7132 7133 \SpecialChar ~
7133 7134 wc -l $f
7134 7135 \newline
7135 7136
7136 7137 \begin_inset ERT
7137 7138 status Collapsed
7138 7139
7139 7140 \layout Standard
7140 7141
7141 7142 \backslash
7142 7143 hspace*{0mm}
7143 7144 \end_inset
7144 7145
7145 7146 \SpecialChar ~
7146 7147 \SpecialChar ~
7147 7148 \SpecialChar ~
7148 7149 \SpecialChar ~
7149 7150 \SpecialChar ~
7150 7151 \SpecialChar ~
7151 7152 \SpecialChar ~
7152 7153 \SpecialChar ~
7153 7154 \SpecialChar ~
7154 7155 \SpecialChar ~
7155 7156 \SpecialChar ~
7156 7157 \SpecialChar ~
7157 7158 \SpecialChar ~
7158 7159 \SpecialChar ~
7159 7160 |..>
7160 7161 \newline
7161 7162 file scopes.py 13 scopes.py
7162 7163 \newline
7163 7164 file strings.py 4 strings.py
7164 7165 \layout Standard
7165 7166
7166 7167 Note that you may need to protect your variables with braces if you want
7167 7168 to append strings to their names.
7168 7169 To copy all files in alist to
7169 7170 \family typewriter
7170 7171 .bak
7171 7172 \family default
7172 7173 extensions, you must use:
7173 7174 \layout Standard
7174 7175
7175 7176
7176 7177 \family typewriter
7177 7178 fperez[~/test]|12> for f in alist:
7178 7179 \newline
7179 7180
7180 7181 \begin_inset ERT
7181 7182 status Collapsed
7182 7183
7183 7184 \layout Standard
7184 7185
7185 7186 \backslash
7186 7187 hspace*{0mm}
7187 7188 \end_inset
7188 7189
7189 7190 \SpecialChar ~
7190 7191 \SpecialChar ~
7191 7192 \SpecialChar ~
7192 7193 \SpecialChar ~
7193 7194 \SpecialChar ~
7194 7195 \SpecialChar ~
7195 7196 \SpecialChar ~
7196 7197 \SpecialChar ~
7197 7198 \SpecialChar ~
7198 7199 \SpecialChar ~
7199 7200 \SpecialChar ~
7200 7201 \SpecialChar ~
7201 7202 \SpecialChar ~
7202 7203 \SpecialChar ~
7203 7204 |..> \SpecialChar ~
7204 7205 \SpecialChar ~
7205 7206 \SpecialChar ~
7206 7207 \SpecialChar ~
7207 7208 cp $f ${f}.bak
7208 7209 \layout Standard
7209 7210
7210 7211 If you try using
7211 7212 \family typewriter
7212 7213 $f.bak
7213 7214 \family default
7214 7215 , you'll get an AttributeError exception saying that your string object
7215 7216 doesn't have a
7216 7217 \family typewriter
7217 7218 .bak
7218 7219 \family default
7219 7220 attribute.
7220 7221 This is because the
7221 7222 \family typewriter
7222 7223 $
7223 7224 \family default
7224 7225 expansion mechanism allows you to expand full Python expressions:
7225 7226 \layout Standard
7226 7227
7227 7228
7228 7229 \family typewriter
7229 7230 fperez[~/test]|13> echo "sys.platform is: $sys.platform"
7230 7231 \newline
7231 7232 sys.platform is: linux2
7232 7233 \layout Standard
7233 7234
7234 7235 IPython's input history handling is still active, which allows you to rerun
7235 7236 a single block of multi-line input by simply using exec:
7236 7237 \newline
7237 7238
7238 7239 \family typewriter
7239 7240 fperez[~/test]|14> $$alist = ls *.eps
7240 7241 \newline
7241 7242 fperez[~/test]|15> exec _i11
7242 7243 \newline
7243 7244 file image2.eps 921 image2.eps
7244 7245 \newline
7245 7246 file image.eps 921 image.eps
7246 7247 \layout Standard
7247 7248
7248 7249 While these are new special-case syntaxes, they are designed to allow very
7249 7250 efficient use of the shell with minimal typing.
7250 7251 At an interactive shell prompt, conciseness of expression wins over readability.
7251 7252 \layout Subsection
7252 7253
7253 7254 Useful functions and modules
7254 7255 \layout Standard
7255 7256
7256 7257 The os, sys and shutil modules from the Python standard library are automaticall
7257 7258 y loaded.
7258 7259 Some additional functions, useful for shell usage, are listed below.
7259 7260 You can request more help about them with `
7260 7261 \family typewriter
7261 7262 ?
7262 7263 \family default
7263 7264 '.
7264 7265 \layout Description
7265 7266
7266 7267
7267 7268 \family typewriter
7268 7269 shell
7269 7270 \family default
7270 7271 - execute a command in the underlying system shell
7271 7272 \layout Description
7272 7273
7273 7274
7274 7275 \family typewriter
7275 7276 system
7276 7277 \family default
7277 7278 - like
7278 7279 \family typewriter
7279 7280 shell()
7280 7281 \family default
7281 7282 , but return the exit status of the command
7282 7283 \layout Description
7283 7284
7284 7285
7285 7286 \family typewriter
7286 7287 sout
7287 7288 \family default
7288 7289 - capture the output of a command as a string
7289 7290 \layout Description
7290 7291
7291 7292
7292 7293 \family typewriter
7293 7294 lout
7294 7295 \family default
7295 7296 - capture the output of a command as a list (split on `
7296 7297 \backslash
7297 7298 n')
7298 7299 \layout Description
7299 7300
7300 7301
7301 7302 \family typewriter
7302 7303 getoutputerror
7303 7304 \family default
7304 7305 - capture (output,error) of a shell commandss
7305 7306 \layout Standard
7306 7307
7307 7308
7308 7309 \family typewriter
7309 7310 sout
7310 7311 \family default
7311 7312 /
7312 7313 \family typewriter
7313 7314 lout
7314 7315 \family default
7315 7316 are the functional equivalents of
7316 7317 \family typewriter
7317 7318 $
7318 7319 \family default
7319 7320 /
7320 7321 \family typewriter
7321 7322 $$
7322 7323 \family default
7323 7324 .
7324 7325 They are provided to allow you to capture system output in the middle of
7325 7326 true python code, function definitions, etc (where
7326 7327 \family typewriter
7327 7328 $
7328 7329 \family default
7329 7330 and
7330 7331 \family typewriter
7331 7332 $$
7332 7333 \family default
7333 7334 are invalid).
7334 7335 \layout Subsection
7335 7336
7336 7337 Directory management
7337 7338 \layout Standard
7338 7339
7339 7340 Since each command passed by pysh to the underlying system is executed in
7340 7341 a subshell which exits immediately, you can NOT use !cd to navigate the
7341 7342 filesystem.
7342 7343 \layout Standard
7343 7344
7344 7345 Pysh provides its own builtin
7345 7346 \family typewriter
7346 7347 `%cd
7347 7348 \family default
7348 7349 ' magic command to move in the filesystem (the
7349 7350 \family typewriter
7350 7351 %
7351 7352 \family default
7352 7353 is not required with automagic on).
7353 7354 It also maintains a list of visited directories (use
7354 7355 \family typewriter
7355 7356 %dhist
7356 7357 \family default
7357 7358 to see it) and allows direct switching to any of them.
7358 7359 Type
7359 7360 \family typewriter
7360 7361 `cd?
7361 7362 \family default
7362 7363 ' for more details.
7363 7364 \layout Standard
7364 7365
7365 7366
7366 7367 \family typewriter
7367 7368 %pushd
7368 7369 \family default
7369 7370 ,
7370 7371 \family typewriter
7371 7372 %popd
7372 7373 \family default
7373 7374 and
7374 7375 \family typewriter
7375 7376 %dirs
7376 7377 \family default
7377 7378 are provided for directory stack handling.
7378 7379 \layout Subsection
7379 7380
7380 7381 Prompt customization
7381 7382 \layout Standard
7382 7383
7383 7384 The supplied
7384 7385 \family typewriter
7385 7386 ipythonrc-pysh
7386 7387 \family default
7387 7388 profile comes with an example of a very colored and detailed prompt, mainly
7388 7389 to serve as an illustration.
7389 7390 The valid escape sequences, besides color names, are:
7390 7391 \layout Description
7391 7392
7392 7393
7393 7394 \backslash
7394 7395 # - Prompt number.
7395 7396 \layout Description
7396 7397
7397 7398
7398 7399 \backslash
7399 7400 D - Dots, as many as there are digits in
7400 7401 \backslash
7401 7402 # (so they align).
7402 7403 \layout Description
7403 7404
7404 7405
7405 7406 \backslash
7406 7407 w - Current working directory (cwd).
7407 7408 \layout Description
7408 7409
7409 7410
7410 7411 \backslash
7411 7412 W - Basename of current working directory.
7412 7413 \layout Description
7413 7414
7414 7415
7415 7416 \backslash
7416 7417 X
7417 7418 \emph on
7418 7419 N
7419 7420 \emph default
7420 7421 - Where
7421 7422 \emph on
7422 7423 N
7423 7424 \emph default
7424 7425 =0..5.
7425 7426 N terms of the cwd, with $HOME written as ~.
7426 7427 \layout Description
7427 7428
7428 7429
7429 7430 \backslash
7430 7431 Y
7431 7432 \emph on
7432 7433 N
7433 7434 \emph default
7434 7435 - Where
7435 7436 \emph on
7436 7437 N
7437 7438 \emph default
7438 7439 =0..5.
7439 7440 Like X
7440 7441 \emph on
7441 7442 N
7442 7443 \emph default
7443 7444 , but if ~ is term
7444 7445 \emph on
7445 7446 N
7446 7447 \emph default
7447 7448 +1 it's also shown.
7448 7449 \layout Description
7449 7450
7450 7451
7451 7452 \backslash
7452 7453 u - Username.
7453 7454 \layout Description
7454 7455
7455 7456
7456 7457 \backslash
7457 7458 H - Full hostname.
7458 7459 \layout Description
7459 7460
7460 7461
7461 7462 \backslash
7462 7463 h - Hostname up to first '.'
7463 7464 \layout Description
7464 7465
7465 7466
7466 7467 \backslash
7467 7468 $ - Root symbol ($ or #).
7468 7469
7469 7470 \layout Description
7470 7471
7471 7472
7472 7473 \backslash
7473 7474 t - Current time, in H:M:S format.
7474 7475 \layout Description
7475 7476
7476 7477
7477 7478 \backslash
7478 7479 v - IPython release version.
7479 7480
7480 7481 \layout Description
7481 7482
7482 7483
7483 7484 \backslash
7484 7485 n - Newline.
7485 7486
7486 7487 \layout Description
7487 7488
7488 7489
7489 7490 \backslash
7490 7491 r - Carriage return.
7491 7492
7492 7493 \layout Description
7493 7494
7494 7495
7495 7496 \backslash
7496 7497
7497 7498 \backslash
7498 7499 - An explicitly escaped '
7499 7500 \backslash
7500 7501 '.
7501 7502 \layout Standard
7502 7503
7503 7504 You can configure your prompt colors using any ANSI color escape.
7504 7505 Each color escape sets the color for any subsequent text, until another
7505 7506 escape comes in and changes things.
7506 7507 The valid color escapes are:
7507 7508 \layout Description
7508 7509
7509 7510
7510 7511 \backslash
7511 7512 C_Black
7512 7513 \layout Description
7513 7514
7514 7515
7515 7516 \backslash
7516 7517 C_Blue
7517 7518 \layout Description
7518 7519
7519 7520
7520 7521 \backslash
7521 7522 C_Brown
7522 7523 \layout Description
7523 7524
7524 7525
7525 7526 \backslash
7526 7527 C_Cyan
7527 7528 \layout Description
7528 7529
7529 7530
7530 7531 \backslash
7531 7532 C_DarkGray
7532 7533 \layout Description
7533 7534
7534 7535
7535 7536 \backslash
7536 7537 C_Green
7537 7538 \layout Description
7538 7539
7539 7540
7540 7541 \backslash
7541 7542 C_LightBlue
7542 7543 \layout Description
7543 7544
7544 7545
7545 7546 \backslash
7546 7547 C_LightCyan
7547 7548 \layout Description
7548 7549
7549 7550
7550 7551 \backslash
7551 7552 C_LightGray
7552 7553 \layout Description
7553 7554
7554 7555
7555 7556 \backslash
7556 7557 C_LightGreen
7557 7558 \layout Description
7558 7559
7559 7560
7560 7561 \backslash
7561 7562 C_LightPurple
7562 7563 \layout Description
7563 7564
7564 7565
7565 7566 \backslash
7566 7567 C_LightRed
7567 7568 \layout Description
7568 7569
7569 7570
7570 7571 \backslash
7571 7572 C_Purple
7572 7573 \layout Description
7573 7574
7574 7575
7575 7576 \backslash
7576 7577 C_Red
7577 7578 \layout Description
7578 7579
7579 7580
7580 7581 \backslash
7581 7582 C_White
7582 7583 \layout Description
7583 7584
7584 7585
7585 7586 \backslash
7586 7587 C_Yellow
7587 7588 \layout Description
7588 7589
7589 7590
7590 7591 \backslash
7591 7592 C_Normal Stop coloring, defaults to your terminal settings.
7592 7593 \layout Section
7593 7594
7594 7595
7595 7596 \begin_inset LatexCommand \label{sec:Threading-support}
7596 7597
7597 7598 \end_inset
7598 7599
7599 7600 Threading support
7600 7601 \layout Standard
7601 7602
7602 7603
7603 7604 \series bold
7604 7605 WARNING:
7605 7606 \series default
7606 7607 The threading support is still somewhat experimental, and it has only seen
7607 7608 reasonable testing under Linux.
7608 7609 Threaded code is particularly tricky to debug, and it tends to show extremely
7609 7610 platform-dependent behavior.
7610 7611 Since I only have access to Linux machines, I will have to rely on user's
7611 7612 experiences and assistance for this area of IPython to improve under other
7612 7613 platforms.
7613 7614 \layout Standard
7614 7615
7615 7616 IPython, via the
7616 7617 \family typewriter
7617 7618 -gthread
7618 7619 \family default
7619 7620 ,
7620 7621 \family typewriter
7621 7622 -qthread
7622 7623 \family default
7623 7624 and
7624 7625 \family typewriter
7625 7626 -wthread
7626 7627 \family default
7627 7628 options (described in Sec.\SpecialChar ~
7628 7629
7629 7630 \begin_inset LatexCommand \ref{sec:threading-opts}
7630 7631
7631 7632 \end_inset
7632 7633
7633 7634 ), can run in multithreaded mode to support pyGTK, Qt and WXPython applications
7634 7635 respectively.
7635 7636 These GUI toolkits need to control the python main loop of execution, so
7636 7637 under a normal Python interpreter, starting a pyGTK, Qt or WXPython application
7637 7638 will immediately freeze the shell.
7638 7639
7639 7640 \layout Standard
7640 7641
7641 7642 IPython, with one of these options (you can only use one at a time), separates
7642 7643 the graphical loop and IPython's code execution run into different threads.
7643 7644 This allows you to test interactively (with
7644 7645 \family typewriter
7645 7646 %run
7646 7647 \family default
7647 7648 , for example) your GUI code without blocking.
7648 7649 \layout Standard
7649 7650
7650 7651 A nice mini-tutorial on using IPython along with the Qt Designer application
7651 7652 is available at the SciPy wiki:
7652 7653 \begin_inset LatexCommand \htmlurl{http://www.scipy.org/wikis/topical_software/QtWithIPythonAndDesigner}
7653 7654
7654 7655 \end_inset
7655 7656
7656 7657 .
7657 7658 \layout Subsection
7658 7659
7659 7660 Tk issues
7660 7661 \layout Standard
7661 7662
7662 7663 As indicated in Sec.\SpecialChar ~
7663 7664
7664 7665 \begin_inset LatexCommand \ref{sec:threading-opts}
7665 7666
7666 7667 \end_inset
7667 7668
7668 7669 , a special
7669 7670 \family typewriter
7670 7671 -tk
7671 7672 \family default
7672 7673 option is provided to try and allow Tk graphical applications to coexist
7673 7674 interactively with WX, Qt or GTK ones.
7674 7675 Whether this works at all, however, is very platform and configuration
7675 7676 dependent.
7676 7677 Please experiment with simple test cases before committing to using this
7677 7678 combination of Tk and GTK/Qt/WX threading in a production environment.
7678 7679 \layout Subsection
7679 7680
7680 7681 Signals and Threads
7681 7682 \layout Standard
7682 7683
7683 7684 When any of the thread systems (GTK, Qt or WX) are active, either directly
7684 7685 or via
7685 7686 \family typewriter
7686 7687 -pylab
7687 7688 \family default
7688 7689 with a threaded backend, it is impossible to interrupt long-running Python
7689 7690 code via
7690 7691 \family typewriter
7691 7692 Ctrl-C
7692 7693 \family default
7693 7694 .
7694 7695 IPython can not pass the KeyboardInterrupt exception (or the underlying
7695 7696
7696 7697 \family typewriter
7697 7698 SIGINT
7698 7699 \family default
7699 7700 ) across threads, so any long-running process started from IPython will
7700 7701 run to completion, or will have to be killed via an external (OS-based)
7701 7702 mechanism.
7702 7703 \layout Standard
7703 7704
7704 7705 To the best of my knowledge, this limitation is imposed by the Python interprete
7705 7706 r itself, and it comes from the difficulty of writing portable signal/threaded
7706 7707 code.
7707 7708 If any user is an expert on this topic and can suggest a better solution,
7708 7709 I would love to hear about it.
7709 7710 In the IPython sources, look at the
7710 7711 \family typewriter
7711 7712 Shell.py
7712 7713 \family default
7713 7714 module, and in particular at the
7714 7715 \family typewriter
7715 7716 runcode()
7716 7717 \family default
7717 7718 method.
7718 7719
7719 7720 \layout Subsection
7720 7721
7721 7722 I/O pitfalls
7722 7723 \layout Standard
7723 7724
7724 7725 Be mindful that the Python interpreter switches between threads every
7725 7726 \begin_inset Formula $N$
7726 7727 \end_inset
7727 7728
7728 7729 bytecodes, where the default value as of Python\SpecialChar ~
7729 7730 2.3 is
7730 7731 \begin_inset Formula $N=100.$
7731 7732 \end_inset
7732 7733
7733 7734 This value can be read by using the
7734 7735 \family typewriter
7735 7736 sys.getcheckinterval()
7736 7737 \family default
7737 7738 function, and it can be reset via
7738 7739 \family typewriter
7739 7740 sys.setcheckinterval(
7740 7741 \emph on
7741 7742 N
7742 7743 \emph default
7743 7744 )
7744 7745 \family default
7745 7746 .
7746 7747 This switching of threads can cause subtly confusing effects if one of
7747 7748 your threads is doing file I/O.
7748 7749 In text mode, most systems only flush file buffers when they encounter
7749 7750 a
7750 7751 \family typewriter
7751 7752 `
7752 7753 \backslash
7753 7754 n'
7754 7755 \family default
7755 7756 .
7756 7757 An instruction as simple as
7757 7758 \family typewriter
7758 7759
7759 7760 \newline
7760 7761 \SpecialChar ~
7761 7762 \SpecialChar ~
7762 7763 print >> filehandle,
7763 7764 \begin_inset Quotes eld
7764 7765 \end_inset
7765 7766
7766 7767 hello world
7767 7768 \begin_inset Quotes erd
7768 7769 \end_inset
7769 7770
7770 7771
7771 7772 \family default
7772 7773
7773 7774 \newline
7774 7775 actually consists of several bytecodes, so it is possible that the newline
7775 7776 does not reach your file before the next thread switch.
7776 7777 Similarly, if you are writing to a file in binary mode, the file won't
7777 7778 be flushed until the buffer fills, and your other thread may see apparently
7778 7779 truncated files.
7779 7780
7780 7781 \layout Standard
7781 7782
7782 7783 For this reason, if you are using IPython's thread support and have (for
7783 7784 example) a GUI application which will read data generated by files written
7784 7785 to from the IPython thread, the safest approach is to open all of your
7785 7786 files in unbuffered mode (the third argument to the
7786 7787 \family typewriter
7787 7788 file/open
7788 7789 \family default
7789 7790 function is the buffering value):
7790 7791 \newline
7791 7792
7792 7793 \family typewriter
7793 7794 \SpecialChar ~
7794 7795 \SpecialChar ~
7795 7796 filehandle = open(filename,mode,0)
7796 7797 \layout Standard
7797 7798
7798 7799 This is obviously a brute force way of avoiding race conditions with the
7799 7800 file buffering.
7800 7801 If you want to do it cleanly, and you have a resource which is being shared
7801 7802 by the interactive IPython loop and your GUI thread, you should really
7802 7803 handle it with thread locking and syncrhonization properties.
7803 7804 The Python documentation discusses these.
7804 7805 \layout Section
7805 7806
7806 7807
7807 7808 \begin_inset LatexCommand \label{sec:interactive-demos}
7808 7809
7809 7810 \end_inset
7810 7811
7811 7812 Interactive demos with IPython
7812 7813 \layout Standard
7813 7814
7814 7815 IPython ships with a basic system for running scripts interactively in sections,
7815 7816 useful when presenting code to audiences.
7816 7817 A few tags embedded in comments (so that the script remains valid Python
7817 7818 code) divide a file into separate blocks, and the demo can be run one block
7818 7819 at a time, with IPython printing (with syntax highlighting) the block before
7819 7820 executing it, and returning to the interactive prompt after each block.
7820 7821 The interactive namespace is updated after each block is run with the contents
7821 7822 of the demo's namespace.
7822 7823 \layout Standard
7823 7824
7824 7825 This allows you to show a piece of code, run it and then execute interactively
7825 7826 commands based on the variables just created.
7826 7827 Once you want to continue, you simply execute the next block of the demo.
7827 7828 The following listing shows the markup necessary for dividing a script
7828 7829 into sections for execution as a demo.
7829 7830 \layout Standard
7830 7831
7831 7832
7832 7833 \begin_inset ERT
7833 7834 status Open
7834 7835
7835 7836 \layout Standard
7836 7837
7837 7838 \backslash
7838 7839 codelist{examples/example-demo.py}
7839 7840 \end_inset
7840 7841
7841 7842
7842 7843 \layout Standard
7843 7844
7844 7845 In order to run a file as a demo, you must first make a
7845 7846 \family typewriter
7846 7847 Demo
7847 7848 \family default
7848 7849 object out of it.
7849 7850 If the file is named
7850 7851 \family typewriter
7851 7852 myscript.py
7852 7853 \family default
7853 7854 , the following code will make a demo:
7854 7855 \layout LyX-Code
7855 7856
7856 7857 from IPython.demo import Demo
7857 7858 \layout LyX-Code
7858 7859
7859 7860 mydemo = Demo('myscript.py')
7860 7861 \layout Standard
7861 7862
7862 7863 This creates the
7863 7864 \family typewriter
7864 7865 mydemo
7865 7866 \family default
7866 7867 object, whose blocks you run one at a time by simply calling the object
7867 7868 with no arguments.
7868 7869 If you have autocall active in IPython (the default), all you need to do
7869 7870 is type
7870 7871 \layout LyX-Code
7871 7872
7872 7873 mydemo
7873 7874 \layout Standard
7874 7875
7875 7876 and IPython will call it, executing each block.
7876 7877 Demo objects can be restarted, you can move forward or back skipping blocks,
7877 7878 re-execute the last block, etc.
7878 7879 Simply use the Tab key on a demo object to see its methods, and call
7879 7880 \family typewriter
7880 7881 `?'
7881 7882 \family default
7882 7883 on them to see their docstrings for more usage details.
7883 7884 In addition, the
7884 7885 \family typewriter
7885 7886 demo
7886 7887 \family default
7887 7888 module itself contains a comprehensive docstring, which you can access
7888 7889 via
7889 7890 \layout LyX-Code
7890 7891
7891 7892 from IPython import demo
7892 7893 \layout LyX-Code
7893 7894
7894 7895 demo?
7895 7896 \layout Standard
7896 7897
7897 7898
7898 7899 \series bold
7899 7900 Limitations:
7900 7901 \series default
7901 7902 It is important to note that these demos are limited to fairly simple uses.
7902 7903 In particular, you can
7903 7904 \emph on
7904 7905 not
7905 7906 \emph default
7906 7907 put division marks in indented code (loops, if statements, function definitions
7907 7908 , etc.) Supporting something like this would basically require tracking the
7908 7909 internal execution state of the Python interpreter, so only top-level divisions
7909 7910 are allowed.
7910 7911 If you want to be able to open an IPython instance at an arbitrary point
7911 7912 in a program, you can use IPython's embedding facilities, described in
7912 7913 detail in Sec\SpecialChar \@.
7913 7914 \SpecialChar ~
7914 7915
7915 7916 \begin_inset LatexCommand \ref{sec:embed}
7916 7917
7917 7918 \end_inset
7918 7919
7919 7920 .
7920 7921 \layout Section
7921 7922
7922 7923
7923 7924 \begin_inset LatexCommand \label{sec:matplotlib-support}
7924 7925
7925 7926 \end_inset
7926 7927
7927 7928 Plotting with
7928 7929 \family typewriter
7929 7930 matplotlib
7930 7931 \family default
7931 7932
7932 7933 \layout Standard
7933 7934
7934 7935 The matplotlib library (
7935 7936 \begin_inset LatexCommand \htmlurl[http://matplotlib.sourceforge.net]{http://matplotlib.sourceforge.net}
7936 7937
7937 7938 \end_inset
7938 7939
7939 7940 ) provides high quality 2D plotting for Python.
7940 7941 Matplotlib can produce plots on screen using a variety of GUI toolkits,
7941 7942 including Tk, GTK and WXPython.
7942 7943 It also provides a number of commands useful for scientific computing,
7943 7944 all with a syntax compatible with that of the popular Matlab program.
7944 7945 \layout Standard
7945 7946
7946 7947 IPython accepts the special option
7947 7948 \family typewriter
7948 7949 -pylab
7949 7950 \family default
7950 7951 (Sec.\SpecialChar ~
7951 7952
7952 7953 \begin_inset LatexCommand \ref{sec:cmd-line-opts}
7953 7954
7954 7955 \end_inset
7955 7956
7956 7957 ).
7957 7958 This configures it to support matplotlib, honoring the settings in the
7958 7959
7959 7960 \family typewriter
7960 7961 .matplotlibrc
7961 7962 \family default
7962 7963 file.
7963 7964 IPython will detect the user's choice of matplotlib GUI backend, and automatica
7964 7965 lly select the proper threading model to prevent blocking.
7965 7966 It also sets matplotlib in interactive mode and modifies
7966 7967 \family typewriter
7967 7968 %run
7968 7969 \family default
7969 7970 slightly, so that any matplotlib-based script can be executed using
7970 7971 \family typewriter
7971 7972 %run
7972 7973 \family default
7973 7974 and the final
7974 7975 \family typewriter
7975 7976 show()
7976 7977 \family default
7977 7978 command does not block the interactive shell.
7978 7979 \layout Standard
7979 7980
7980 7981 The
7981 7982 \family typewriter
7982 7983 -pylab
7983 7984 \family default
7984 7985 option must be given first in order for IPython to configure its threading
7985 7986 mode.
7986 7987 However, you can still issue other options afterwards.
7987 7988 This allows you to have a matplotlib-based environment customized with
7988 7989 additional modules using the standard IPython profile mechanism (Sec.\SpecialChar ~
7989 7990
7990 7991 \begin_inset LatexCommand \ref{sec:profiles}
7991 7992
7992 7993 \end_inset
7993 7994
7994 7995 ): ``
7995 7996 \family typewriter
7996 7997 ipython -pylab -p myprofile
7997 7998 \family default
7998 7999 '' will load the profile defined in
7999 8000 \family typewriter
8000 8001 ipythonrc-myprofile
8001 8002 \family default
8002 8003 after configuring matplotlib.
8003 8004 \layout Section
8004 8005
8005 8006
8006 8007 \begin_inset LatexCommand \label{sec:Gnuplot}
8007 8008
8008 8009 \end_inset
8009 8010
8010 8011 Plotting with
8011 8012 \family typewriter
8012 8013 Gnuplot
8013 8014 \layout Standard
8014 8015
8015 8016 Through the magic extension system described in sec.
8016 8017
8017 8018 \begin_inset LatexCommand \ref{sec:magic}
8018 8019
8019 8020 \end_inset
8020 8021
8021 8022 , IPython incorporates a mechanism for conveniently interfacing with the
8022 8023 Gnuplot system (
8023 8024 \begin_inset LatexCommand \htmlurl{http://www.gnuplot.info}
8024 8025
8025 8026 \end_inset
8026 8027
8027 8028 ).
8028 8029 Gnuplot is a very complete 2D and 3D plotting package available for many
8029 8030 operating systems and commonly included in modern Linux distributions.
8030 8031
8031 8032 \layout Standard
8032 8033
8033 8034 Besides having Gnuplot installed, this functionality requires the
8034 8035 \family typewriter
8035 8036 Gnuplot.py
8036 8037 \family default
8037 8038 module for interfacing python with Gnuplot.
8038 8039 It can be downloaded from:
8039 8040 \begin_inset LatexCommand \htmlurl{http://gnuplot-py.sourceforge.net}
8040 8041
8041 8042 \end_inset
8042 8043
8043 8044 .
8044 8045 \layout Subsection
8045 8046
8046 8047 Proper Gnuplot configuration
8047 8048 \layout Standard
8048 8049
8049 8050 As of version 4.0, Gnuplot has excellent mouse and interactive keyboard support.
8050 8051 However, as of
8051 8052 \family typewriter
8052 8053 Gnuplot.py
8053 8054 \family default
8054 8055 version 1.7, a new option was added to communicate between Python and Gnuplot
8055 8056 via FIFOs (pipes).
8056 8057 This mechanism, while fast, also breaks the mouse system.
8057 8058 You must therefore set the variable
8058 8059 \family typewriter
8059 8060 prefer_fifo_data
8060 8061 \family default
8061 8062 to
8062 8063 \family typewriter
8063 8064 0
8064 8065 \family default
8065 8066 in file
8066 8067 \family typewriter
8067 8068 gp_unix.py
8068 8069 \family default
8069 8070 if you wish to keep the interactive mouse and keyboard features working
8070 8071 properly (
8071 8072 \family typewriter
8072 8073 prefer_inline_data
8073 8074 \family default
8074 8075 also must be
8075 8076 \family typewriter
8076 8077 0
8077 8078 \family default
8078 8079 , but this is the default so unless you've changed it manually you should
8079 8080 be fine).
8080 8081 \layout Standard
8081 8082
8082 8083 'Out of the box', Gnuplot is configured with a rather poor set of size,
8083 8084 color and linewidth choices which make the graphs fairly hard to read on
8084 8085 modern high-resolution displays (although they work fine on old 640x480
8085 8086 ones).
8086 8087 Below is a section of my
8087 8088 \family typewriter
8088 8089 .Xdefaults
8089 8090 \family default
8090 8091 file which I use for having a more convenient Gnuplot setup.
8091 8092 Remember to load it by running
8092 8093 \family typewriter
8093 8094 `xrdb .Xdefaults`
8094 8095 \family default
8095 8096 :
8096 8097 \layout Standard
8097 8098
8098 8099
8099 8100 \family typewriter
8100 8101 !******************************************************************
8101 8102 \newline
8102 8103 ! gnuplot options
8103 8104 \newline
8104 8105 ! modify this for a convenient window size
8105 8106 \newline
8106 8107 gnuplot*geometry: 780x580
8107 8108 \layout Standard
8108 8109
8109 8110
8110 8111 \family typewriter
8111 8112 ! on-screen font (not for PostScript)
8112 8113 \newline
8113 8114 gnuplot*font: -misc-fixed-bold-r-normal--15-120-100-100-c-90-iso8859-1
8114 8115 \layout Standard
8115 8116
8116 8117
8117 8118 \family typewriter
8118 8119 ! color options
8119 8120 \newline
8120 8121 gnuplot*background: black
8121 8122 \newline
8122 8123 gnuplot*textColor: white
8123 8124 \newline
8124 8125 gnuplot*borderColor: white
8125 8126 \newline
8126 8127 gnuplot*axisColor: white
8127 8128 \newline
8128 8129 gnuplot*line1Color: red
8129 8130 \newline
8130 8131 gnuplot*line2Color: green
8131 8132 \newline
8132 8133 gnuplot*line3Color: blue
8133 8134 \newline
8134 8135 gnuplot*line4Color: magenta
8135 8136 \newline
8136 8137 gnuplot*line5Color: cyan
8137 8138 \newline
8138 8139 gnuplot*line6Color: sienna
8139 8140 \newline
8140 8141 gnuplot*line7Color: orange
8141 8142 \newline
8142 8143 gnuplot*line8Color: coral
8143 8144 \layout Standard
8144 8145
8145 8146
8146 8147 \family typewriter
8147 8148 ! multiplicative factor for point styles
8148 8149 \newline
8149 8150 gnuplot*pointsize: 2
8150 8151 \layout Standard
8151 8152
8152 8153
8153 8154 \family typewriter
8154 8155 ! line width options (in pixels)
8155 8156 \newline
8156 8157 gnuplot*borderWidth: 2
8157 8158 \newline
8158 8159 gnuplot*axisWidth: 2
8159 8160 \newline
8160 8161 gnuplot*line1Width: 2
8161 8162 \newline
8162 8163 gnuplot*line2Width: 2
8163 8164 \newline
8164 8165 gnuplot*line3Width: 2
8165 8166 \newline
8166 8167 gnuplot*line4Width: 2
8167 8168 \newline
8168 8169 gnuplot*line5Width: 2
8169 8170 \newline
8170 8171 gnuplot*line6Width: 2
8171 8172 \newline
8172 8173 gnuplot*line7Width: 2
8173 8174 \newline
8174 8175 gnuplot*line8Width: 2
8175 8176 \layout Subsection
8176 8177
8177 8178 The
8178 8179 \family typewriter
8179 8180 IPython.GnuplotRuntime
8180 8181 \family default
8181 8182 module
8182 8183 \layout Standard
8183 8184
8184 8185 IPython includes a module called
8185 8186 \family typewriter
8186 8187 Gnuplot2.py
8187 8188 \family default
8188 8189 which extends and improves the default
8189 8190 \family typewriter
8190 8191 Gnuplot
8191 8192 \family default
8192 8193 .
8193 8194 \family typewriter
8194 8195 py
8195 8196 \family default
8196 8197 (which it still relies upon).
8197 8198 For example, the new
8198 8199 \family typewriter
8199 8200 plot
8200 8201 \family default
8201 8202 function adds several improvements to the original making it more convenient
8202 8203 for interactive use, and
8203 8204 \family typewriter
8204 8205 hardcopy
8205 8206 \family default
8206 8207 fixes a bug in the original which under some circumstances blocks the creation
8207 8208 of PostScript output.
8208 8209 \layout Standard
8209 8210
8210 8211 For scripting use,
8211 8212 \family typewriter
8212 8213 GnuplotRuntime.py
8213 8214 \family default
8214 8215 is provided, which wraps
8215 8216 \family typewriter
8216 8217 Gnuplot2.py
8217 8218 \family default
8218 8219 and creates a series of global aliases.
8219 8220 These make it easy to control Gnuplot plotting jobs through the Python
8220 8221 language.
8221 8222 \layout Standard
8222 8223
8223 8224 Below is some example code which illustrates how to configure Gnuplot inside
8224 8225 your own programs but have it available for further interactive use through
8225 8226 an embedded IPython instance.
8226 8227 Simply run this file at a system prompt.
8227 8228 This file is provided as
8228 8229 \family typewriter
8229 8230 example-gnuplot.py
8230 8231 \family default
8231 8232 in the examples directory:
8232 8233 \layout Standard
8233 8234
8234 8235
8235 8236 \begin_inset ERT
8236 8237 status Open
8237 8238
8238 8239 \layout Standard
8239 8240
8240 8241 \backslash
8241 8242 codelist{examples/example-gnuplot.py}
8242 8243 \end_inset
8243 8244
8244 8245
8245 8246 \layout Subsection
8246 8247
8247 8248 The
8248 8249 \family typewriter
8249 8250 numeric
8250 8251 \family default
8251 8252 profile: a scientific computing environment
8252 8253 \layout Standard
8253 8254
8254 8255 The
8255 8256 \family typewriter
8256 8257 numeric
8257 8258 \family default
8258 8259 IPython profile, which you can activate with
8259 8260 \family typewriter
8260 8261 `ipython -p numeric
8261 8262 \family default
8262 8263 ' will automatically load the IPython Gnuplot extensions (plus Numeric and
8263 8264 other useful things for numerical computing), contained in the
8264 8265 \family typewriter
8265 8266 IPython.GnuplotInteractive
8266 8267 \family default
8267 8268 module.
8268 8269 This will create the globals
8269 8270 \family typewriter
8270 8271 Gnuplot
8271 8272 \family default
8272 8273 (an alias to the improved Gnuplot2 module),
8273 8274 \family typewriter
8274 8275 gp
8275 8276 \family default
8276 8277 (a Gnuplot active instance), the new magic commands
8277 8278 \family typewriter
8278 8279 %gpc
8279 8280 \family default
8280 8281 and
8281 8282 \family typewriter
8282 8283 %gp_set_instance
8283 8284 \family default
8284 8285 and several other convenient globals.
8285 8286 Type
8286 8287 \family typewriter
8287 8288 gphelp()
8288 8289 \family default
8289 8290 for further details.
8290 8291 \layout Standard
8291 8292
8292 8293 This should turn IPython into a convenient environment for numerical computing,
8293 8294 with all the functions in the NumPy library and the Gnuplot facilities
8294 8295 for plotting.
8295 8296 Further improvements can be obtained by loading the SciPy libraries for
8296 8297 scientific computing, available at
8297 8298 \begin_inset LatexCommand \htmlurl{http://scipy.org}
8298 8299
8299 8300 \end_inset
8300 8301
8301 8302 .
8302 8303 \layout Standard
8303 8304
8304 8305 If you are in the middle of a working session with numerical objects and
8305 8306 need to plot them but you didn't start the
8306 8307 \family typewriter
8307 8308 numeric
8308 8309 \family default
8309 8310 profile, you can load these extensions at any time by typing
8310 8311 \newline
8311 8312
8312 8313 \family typewriter
8313 8314 from IPython.GnuplotInteractive import *
8314 8315 \newline
8315 8316
8316 8317 \family default
8317 8318 at the IPython prompt.
8318 8319 This will allow you to keep your objects intact and start using Gnuplot
8319 8320 to view them.
8320 8321 \layout Section
8321 8322
8322 8323 Reporting bugs
8323 8324 \layout Subsection*
8324 8325
8325 8326 Automatic crash reports
8326 8327 \layout Standard
8327 8328
8328 8329 Ideally, IPython itself shouldn't crash.
8329 8330 It will catch exceptions produced by you, but bugs in its internals will
8330 8331 still crash it.
8331 8332 \layout Standard
8332 8333
8333 8334 In such a situation, IPython will leave a file named
8334 8335 \family typewriter
8335 8336 IPython_crash_report.txt
8336 8337 \family default
8337 8338 in your IPYTHONDIR directory (that way if crashes happen several times
8338 8339 it won't litter many directories, the post-mortem file is always located
8339 8340 in the same place and new occurrences just overwrite the previous one).
8340 8341 If you can mail this file to the developers (see sec.
8341 8342
8342 8343 \begin_inset LatexCommand \ref{sec:credits}
8343 8344
8344 8345 \end_inset
8345 8346
8346 8347 for names and addresses), it will help us
8347 8348 \emph on
8348 8349 a lot
8349 8350 \emph default
8350 8351 in understanding the cause of the problem and fixing it sooner.
8351 8352 \layout Subsection*
8352 8353
8353 8354 The bug tracker
8354 8355 \layout Standard
8355 8356
8356 8357 IPython also has an online bug-tracker, located at
8357 8358 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython}
8358 8359
8359 8360 \end_inset
8360 8361
8361 8362 .
8362 8363 In addition to mailing the developers, it would be a good idea to file
8363 8364 a bug report here.
8364 8365 This will ensure that the issue is properly followed to conclusion.
8365 8366 \layout Standard
8366 8367
8367 8368 You can also use this bug tracker to file feature requests.
8368 8369 \layout Section
8369 8370
8370 8371 Brief history
8371 8372 \layout Subsection
8372 8373
8373 8374 Origins
8374 8375 \layout Standard
8375 8376
8376 8377 The current IPython system grew out of the following three projects:
8377 8378 \layout List
8378 8379 \labelwidthstring 00.00.0000
8379 8380
8380 8381 ipython by Fernando Pérez.
8381 8382 I was working on adding Mathematica-type prompts and a flexible configuration
8382 8383 system (something better than
8383 8384 \family typewriter
8384 8385 $PYTHONSTARTUP
8385 8386 \family default
8386 8387 ) to the standard Python interactive interpreter.
8387 8388 \layout List
8388 8389 \labelwidthstring 00.00.0000
8389 8390
8390 8391 IPP by Janko Hauser.
8391 8392 Very well organized, great usability.
8392 8393 Had an old help system.
8393 8394 IPP was used as the `container' code into which I added the functionality
8394 8395 from ipython and LazyPython.
8395 8396 \layout List
8396 8397 \labelwidthstring 00.00.0000
8397 8398
8398 8399 LazyPython by Nathan Gray.
8399 8400 Simple but
8400 8401 \emph on
8401 8402 very
8402 8403 \emph default
8403 8404 powerful.
8404 8405 The quick syntax (auto parens, auto quotes) and verbose/colored tracebacks
8405 8406 were all taken from here.
8406 8407 \layout Standard
8407 8408
8408 8409 When I found out (see sec.
8409 8410
8410 8411 \begin_inset LatexCommand \ref{figgins}
8411 8412
8412 8413 \end_inset
8413 8414
8414 8415 ) about IPP and LazyPython I tried to join all three into a unified system.
8415 8416 I thought this could provide a very nice working environment, both for
8416 8417 regular programming and scientific computing: shell-like features, IDL/Matlab
8417 8418 numerics, Mathematica-type prompt history and great object introspection
8418 8419 and help facilities.
8419 8420 I think it worked reasonably well, though it was a lot more work than I
8420 8421 had initially planned.
8421 8422 \layout Subsection
8422 8423
8423 8424 Current status
8424 8425 \layout Standard
8425 8426
8426 8427 The above listed features work, and quite well for the most part.
8427 8428 But until a major internal restructuring is done (see below), only bug
8428 8429 fixing will be done, no other features will be added (unless very minor
8429 8430 and well localized in the cleaner parts of the code).
8430 8431 \layout Standard
8431 8432
8432 8433 IPython consists of some 12000 lines of pure python code, of which roughly
8433 8434 50% are fairly clean.
8434 8435 The other 50% are fragile, messy code which needs a massive restructuring
8435 8436 before any further major work is done.
8436 8437 Even the messy code is fairly well documented though, and most of the problems
8437 8438 in the (non-existent) class design are well pointed to by a PyChecker run.
8438 8439 So the rewriting work isn't that bad, it will just be time-consuming.
8439 8440 \layout Subsection
8440 8441
8441 8442 Future
8442 8443 \layout Standard
8443 8444
8444 8445 See the separate
8445 8446 \family typewriter
8446 8447 new_design
8447 8448 \family default
8448 8449 document for details.
8449 8450 Ultimately, I would like to see IPython become part of the standard Python
8450 8451 distribution as a `big brother with batteries' to the standard Python interacti
8451 8452 ve interpreter.
8452 8453 But that will never happen with the current state of the code, so all contribut
8453 8454 ions are welcome.
8454 8455 \layout Section
8455 8456
8456 8457 License
8457 8458 \layout Standard
8458 8459
8459 8460 IPython is released under the terms of the BSD license, whose general form
8460 8461 can be found at:
8461 8462 \begin_inset LatexCommand \htmlurl{http://www.opensource.org/licenses/bsd-license.php}
8462 8463
8463 8464 \end_inset
8464 8465
8465 8466 .
8466 8467 The full text of the IPython license is reproduced below:
8467 8468 \layout Quote
8468 8469
8469 8470
8470 8471 \family typewriter
8471 8472 \size small
8472 8473 IPython is released under a BSD-type license.
8473 8474 \layout Quote
8474 8475
8475 8476
8476 8477 \family typewriter
8477 8478 \size small
8478 8479 Copyright (c) 2001, 2002, 2003, 2004 Fernando Perez <fperez@colorado.edu>.
8479 8480 \layout Quote
8480 8481
8481 8482
8482 8483 \family typewriter
8483 8484 \size small
8484 8485 Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and
8485 8486 \newline
8486 8487 Nathaniel Gray <n8gray@caltech.edu>.
8487 8488 \layout Quote
8488 8489
8489 8490
8490 8491 \family typewriter
8491 8492 \size small
8492 8493 All rights reserved.
8493 8494 \layout Quote
8494 8495
8495 8496
8496 8497 \family typewriter
8497 8498 \size small
8498 8499 Redistribution and use in source and binary forms, with or without modification,
8499 8500 are permitted provided that the following conditions are met:
8500 8501 \layout Quote
8501 8502
8502 8503
8503 8504 \family typewriter
8504 8505 \size small
8505 8506 a.
8506 8507 Redistributions of source code must retain the above copyright notice,
8507 8508 this list of conditions and the following disclaimer.
8508 8509 \layout Quote
8509 8510
8510 8511
8511 8512 \family typewriter
8512 8513 \size small
8513 8514 b.
8514 8515 Redistributions in binary form must reproduce the above copyright notice,
8515 8516 this list of conditions and the following disclaimer in the documentation
8516 8517 and/or other materials provided with the distribution.
8517 8518 \layout Quote
8518 8519
8519 8520
8520 8521 \family typewriter
8521 8522 \size small
8522 8523 c.
8523 8524 Neither the name of the copyright holders nor the names of any contributors
8524 8525 to this software may be used to endorse or promote products derived from
8525 8526 this software without specific prior written permission.
8526 8527 \layout Quote
8527 8528
8528 8529
8529 8530 \family typewriter
8530 8531 \size small
8531 8532 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8532 8533 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8533 8534 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8534 8535 PURPOSE ARE DISCLAIMED.
8535 8536 IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8536 8537 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
8537 8538 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
8538 8539 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
8539 8540 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8540 8541 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8541 8542 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8542 8543
8543 8544 \layout Standard
8544 8545
8545 8546 Individual authors are the holders of the copyright for their code and are
8546 8547 listed in each file.
8547 8548 \layout Standard
8548 8549
8549 8550 Some files (
8550 8551 \family typewriter
8551 8552 DPyGetOpt.py
8552 8553 \family default
8553 8554 , for example) may be licensed under different conditions.
8554 8555 Ultimately each file indicates clearly the conditions under which its author/au
8555 8556 thors have decided to publish the code.
8556 8557 \layout Standard
8557 8558
8558 8559 Versions of IPython up to and including 0.6.3 were released under the GNU
8559 8560 Lesser General Public License (LGPL), available at
8560 8561 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/copyleft/lesser.html}
8561 8562
8562 8563 \end_inset
8563 8564
8564 8565 .
8565 8566 \layout Section
8566 8567
8567 8568
8568 8569 \begin_inset LatexCommand \label{sec:credits}
8569 8570
8570 8571 \end_inset
8571 8572
8572 8573 Credits
8573 8574 \layout Standard
8574 8575
8575 8576 IPython is mainly developed by Fernando Pérez
8576 8577 \family typewriter
8577 8578 <fperez@colorado.edu>
8578 8579 \family default
8579 8580 , but the project was born from mixing in Fernando's code with the IPP project
8580 8581 by Janko Hauser
8581 8582 \family typewriter
8582 8583 <jhauser-AT-zscout.de>
8583 8584 \family default
8584 8585 and LazyPython by Nathan Gray
8585 8586 \family typewriter
8586 8587 <n8gray-AT-caltech.edu>
8587 8588 \family default
8588 8589 .
8589 8590 For all IPython-related requests, please contact Fernando.
8590 8591
8591 8592 \layout Standard
8592 8593
8593 8594 As of late 2005, the following developers have joined the core team:
8594 8595 \layout List
8595 8596 \labelwidthstring 00.00.0000
8596 8597
8597 8598 Robert\SpecialChar ~
8598 8599 Kern
8599 8600 \family typewriter
8600 8601 <rkern-AT-enthought.com>
8601 8602 \family default
8602 8603 : co-mentored the 2005 Google Summer of Code project to develop python interacti
8603 8604 ve notebooks (XML documents) and graphical interface.
8604 8605 This project was awarded to the students Tzanko Matev
8605 8606 \family typewriter
8606 8607 <tsanko-AT-gmail.com>
8607 8608 \family default
8608 8609 and Toni Alatalo
8609 8610 \family typewriter
8610 8611 <antont-AT-an.org>
8611 8612 \layout List
8612 8613 \labelwidthstring 00.00.0000
8613 8614
8614 8615 Brian\SpecialChar ~
8615 8616 Granger
8616 8617 \family typewriter
8617 8618 <bgranger-AT-scu.edu>
8618 8619 \family default
8619 8620 : extending IPython to allow support for interactive parallel computing.
8620 8621 \layout Standard
8621 8622
8622 8623 User or development help should be requested via the IPython mailing lists:
8623 8624 \layout Description
8624 8625
8625 8626 User\SpecialChar ~
8626 8627 list:
8627 8628 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-user}
8628 8629
8629 8630 \end_inset
8630 8631
8631 8632
8632 8633 \layout Description
8633 8634
8634 8635 Developer's\SpecialChar ~
8635 8636 list:
8636 8637 \begin_inset LatexCommand \htmlurl{http://scipy.net/mailman/listinfo/ipython-dev}
8637 8638
8638 8639 \end_inset
8639 8640
8640 8641
8641 8642 \layout Standard
8642 8643
8643 8644 The IPython project is also very grateful to
8644 8645 \begin_inset Foot
8645 8646 collapsed true
8646 8647
8647 8648 \layout Standard
8648 8649
8649 8650 I've mangled email addresses to reduce spam, since the IPython manuals can
8650 8651 be accessed online.
8651 8652 \end_inset
8652 8653
8653 8654 :
8654 8655 \layout Standard
8655 8656
8656 8657 Bill Bumgarner
8657 8658 \family typewriter
8658 8659 <bbum-AT-friday.com>
8659 8660 \family default
8660 8661 : for providing the DPyGetOpt module which gives very powerful and convenient
8661 8662 handling of command-line options (light years ahead of what Python 2.1.1's
8662 8663 getopt module does).
8663 8664 \layout Standard
8664 8665
8665 8666 Ka-Ping Yee
8666 8667 \family typewriter
8667 8668 <ping-AT-lfw.org>
8668 8669 \family default
8669 8670 : for providing the Itpl module for convenient and powerful string interpolation
8670 8671 with a much nicer syntax than formatting through the '%' operator.
8671 8672 \layout Standard
8672 8673
8673 8674 Arnd Bäcker
8674 8675 \family typewriter
8675 8676 <baecker-AT-physik.tu-dresden.de>
8676 8677 \family default
8677 8678 : for his many very useful suggestions and comments, and lots of help with
8678 8679 testing and documentation checking.
8679 8680 Many of IPython's newer features are a result of discussions with him (bugs
8680 8681 are still my fault, not his).
8681 8682 \layout Standard
8682 8683
8683 8684 Obviously Guido van\SpecialChar ~
8684 8685 Rossum and the whole Python development team, that goes
8685 8686 without saying.
8686 8687 \layout Standard
8687 8688
8688 8689 IPython's website is generously hosted at
8689 8690 \begin_inset LatexCommand \htmlurl{http://ipython.scipy.org}
8690 8691
8691 8692 \end_inset
8692 8693
8693 8694 by Enthought (
8694 8695 \begin_inset LatexCommand \htmlurl{http://www.enthought.com}
8695 8696
8696 8697 \end_inset
8697 8698
8698 8699 ).
8699 8700 I am very grateful to them and all of the SciPy team for their contribution.
8700 8701 \layout Standard
8701 8702
8702 8703
8703 8704 \begin_inset LatexCommand \label{figgins}
8704 8705
8705 8706 \end_inset
8706 8707
8707 8708 Fernando would also like to thank Stephen Figgins
8708 8709 \family typewriter
8709 8710 <fig-AT-monitor.net>
8710 8711 \family default
8711 8712 , an O'Reilly Python editor.
8712 8713 His Oct/11/2001 article about IPP and LazyPython, was what got this project
8713 8714 started.
8714 8715 You can read it at:
8715 8716 \begin_inset LatexCommand \htmlurl{http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html}
8716 8717
8717 8718 \end_inset
8718 8719
8719 8720 .
8720 8721 \layout Standard
8721 8722
8722 8723 And last but not least, all the kind IPython users who have emailed new
8723 8724 code, bug reports, fixes, comments and ideas.
8724 8725 A brief list follows, please let me know if I have ommitted your name by
8725 8726 accident:
8726 8727 \layout List
8727 8728 \labelwidthstring 00.00.0000
8728 8729
8729 8730 Jack\SpecialChar ~
8730 8731 Moffit
8731 8732 \family typewriter
8732 8733 <jack-AT-xiph.org>
8733 8734 \family default
8734 8735 Bug fixes, including the infamous color problem.
8735 8736 This bug alone caused many lost hours and frustration, many thanks to him
8736 8737 for the fix.
8737 8738 I've always been a fan of Ogg & friends, now I have one more reason to
8738 8739 like these folks.
8739 8740 \newline
8740 8741 Jack is also contributing with Debian packaging and many other things.
8741 8742 \layout List
8742 8743 \labelwidthstring 00.00.0000
8743 8744
8744 8745 Alexander\SpecialChar ~
8745 8746 Schmolck
8746 8747 \family typewriter
8747 8748 <a.schmolck-AT-gmx.net>
8748 8749 \family default
8749 8750 Emacs work, bug reports, bug fixes, ideas, lots more.
8750 8751 The ipython.el mode for (X)Emacs is Alex's code, providing full support
8751 8752 for IPython under (X)Emacs.
8752 8753 \layout List
8753 8754 \labelwidthstring 00.00.0000
8754 8755
8755 8756 Andrea\SpecialChar ~
8756 8757 Riciputi
8757 8758 \family typewriter
8758 8759 <andrea.riciputi-AT-libero.it>
8759 8760 \family default
8760 8761 Mac OSX information, Fink package management.
8761 8762 \layout List
8762 8763 \labelwidthstring 00.00.0000
8763 8764
8764 8765 Gary\SpecialChar ~
8765 8766 Bishop
8766 8767 \family typewriter
8767 8768 <gb-AT-cs.unc.edu>
8768 8769 \family default
8769 8770 Bug reports, and patches to work around the exception handling idiosyncracies
8770 8771 of WxPython.
8771 8772 Readline and color support for Windows.
8772 8773 \layout List
8773 8774 \labelwidthstring 00.00.0000
8774 8775
8775 8776 Jeffrey\SpecialChar ~
8776 8777 Collins
8777 8778 \family typewriter
8778 8779 <Jeff.Collins-AT-vexcel.com>
8779 8780 \family default
8780 8781 Bug reports.
8781 8782 Much improved readline support, including fixes for Python 2.3.
8782 8783 \layout List
8783 8784 \labelwidthstring 00.00.0000
8784 8785
8785 8786 Dryice\SpecialChar ~
8786 8787 Liu
8787 8788 \family typewriter
8788 8789 <dryice-AT-liu.com.cn>
8789 8790 \family default
8790 8791 FreeBSD port.
8791 8792 \layout List
8792 8793 \labelwidthstring 00.00.0000
8793 8794
8794 8795 Mike\SpecialChar ~
8795 8796 Heeter
8796 8797 \family typewriter
8797 8798 <korora-AT-SDF.LONESTAR.ORG>
8798 8799 \layout List
8799 8800 \labelwidthstring 00.00.0000
8800 8801
8801 8802 Christopher\SpecialChar ~
8802 8803 Hart
8803 8804 \family typewriter
8804 8805 <hart-AT-caltech.edu>
8805 8806 \family default
8806 8807 PDB integration.
8807 8808 \layout List
8808 8809 \labelwidthstring 00.00.0000
8809 8810
8810 8811 Milan\SpecialChar ~
8811 8812 Zamazal
8812 8813 \family typewriter
8813 8814 <pdm-AT-zamazal.org>
8814 8815 \family default
8815 8816 Emacs info.
8816 8817 \layout List
8817 8818 \labelwidthstring 00.00.0000
8818 8819
8819 8820 Philip\SpecialChar ~
8820 8821 Hisley
8821 8822 \family typewriter
8822 8823 <compsys-AT-starpower.net>
8823 8824 \layout List
8824 8825 \labelwidthstring 00.00.0000
8825 8826
8826 8827 Holger\SpecialChar ~
8827 8828 Krekel
8828 8829 \family typewriter
8829 8830 <pyth-AT-devel.trillke.net>
8830 8831 \family default
8831 8832 Tab completion, lots more.
8832 8833 \layout List
8833 8834 \labelwidthstring 00.00.0000
8834 8835
8835 8836 Robin\SpecialChar ~
8836 8837 Siebler
8837 8838 \family typewriter
8838 8839 <robinsiebler-AT-starband.net>
8839 8840 \layout List
8840 8841 \labelwidthstring 00.00.0000
8841 8842
8842 8843 Ralf\SpecialChar ~
8843 8844 Ahlbrink
8844 8845 \family typewriter
8845 8846 <ralf_ahlbrink-AT-web.de>
8846 8847 \layout List
8847 8848 \labelwidthstring 00.00.0000
8848 8849
8849 8850 Thorsten\SpecialChar ~
8850 8851 Kampe
8851 8852 \family typewriter
8852 8853 <thorsten-AT-thorstenkampe.de>
8853 8854 \layout List
8854 8855 \labelwidthstring 00.00.0000
8855 8856
8856 8857 Fredrik\SpecialChar ~
8857 8858 Kant
8858 8859 \family typewriter
8859 8860 <fredrik.kant-AT-front.com>
8860 8861 \family default
8861 8862 Windows setup.
8862 8863 \layout List
8863 8864 \labelwidthstring 00.00.0000
8864 8865
8865 8866 Syver\SpecialChar ~
8866 8867 Enstad
8867 8868 \family typewriter
8868 8869 <syver-en-AT-online.no>
8869 8870 \family default
8870 8871 Windows setup.
8871 8872 \layout List
8872 8873 \labelwidthstring 00.00.0000
8873 8874
8874 8875 Richard
8875 8876 \family typewriter
8876 8877 <rxe-AT-renre-europe.com>
8877 8878 \family default
8878 8879 Global embedding.
8879 8880 \layout List
8880 8881 \labelwidthstring 00.00.0000
8881 8882
8882 8883 Hayden\SpecialChar ~
8883 8884 Callow
8884 8885 \family typewriter
8885 8886 <h.callow-AT-elec.canterbury.ac.nz>
8886 8887 \family default
8887 8888 Gnuplot.py 1.6 compatibility.
8888 8889 \layout List
8889 8890 \labelwidthstring 00.00.0000
8890 8891
8891 8892 Leonardo\SpecialChar ~
8892 8893 Santagada
8893 8894 \family typewriter
8894 8895 <retype-AT-terra.com.br>
8895 8896 \family default
8896 8897 Fixes for Windows installation.
8897 8898 \layout List
8898 8899 \labelwidthstring 00.00.0000
8899 8900
8900 8901 Christopher\SpecialChar ~
8901 8902 Armstrong
8902 8903 \family typewriter
8903 8904 <radix-AT-twistedmatrix.com>
8904 8905 \family default
8905 8906 Bugfixes.
8906 8907 \layout List
8907 8908 \labelwidthstring 00.00.0000
8908 8909
8909 8910 Francois\SpecialChar ~
8910 8911 Pinard
8911 8912 \family typewriter
8912 8913 <pinard-AT-iro.umontreal.ca>
8913 8914 \family default
8914 8915 Code and documentation fixes.
8915 8916 \layout List
8916 8917 \labelwidthstring 00.00.0000
8917 8918
8918 8919 Cory\SpecialChar ~
8919 8920 Dodt
8920 8921 \family typewriter
8921 8922 <cdodt-AT-fcoe.k12.ca.us>
8922 8923 \family default
8923 8924 Bug reports and Windows ideas.
8924 8925 Patches for Windows installer.
8925 8926 \layout List
8926 8927 \labelwidthstring 00.00.0000
8927 8928
8928 8929 Olivier\SpecialChar ~
8929 8930 Aubert
8930 8931 \family typewriter
8931 8932 <oaubert-AT-bat710.univ-lyon1.fr>
8932 8933 \family default
8933 8934 New magics.
8934 8935 \layout List
8935 8936 \labelwidthstring 00.00.0000
8936 8937
8937 8938 King\SpecialChar ~
8938 8939 C.\SpecialChar ~
8939 8940 Shu
8940 8941 \family typewriter
8941 8942 <kingshu-AT-myrealbox.com>
8942 8943 \family default
8943 8944 Autoindent patch.
8944 8945 \layout List
8945 8946 \labelwidthstring 00.00.0000
8946 8947
8947 8948 Chris\SpecialChar ~
8948 8949 Drexler
8949 8950 \family typewriter
8950 8951 <chris-AT-ac-drexler.de>
8951 8952 \family default
8952 8953 Readline packages for Win32/CygWin.
8953 8954 \layout List
8954 8955 \labelwidthstring 00.00.0000
8955 8956
8956 8957 Gustavo\SpecialChar ~
8957 8958 Córdova\SpecialChar ~
8958 8959 Avila
8959 8960 \family typewriter
8960 8961 <gcordova-AT-sismex.com>
8961 8962 \family default
8962 8963 EvalDict code for nice, lightweight string interpolation.
8963 8964 \layout List
8964 8965 \labelwidthstring 00.00.0000
8965 8966
8966 8967 Kasper\SpecialChar ~
8967 8968 Souren
8968 8969 \family typewriter
8969 8970 <Kasper.Souren-AT-ircam.fr>
8970 8971 \family default
8971 8972 Bug reports, ideas.
8972 8973 \layout List
8973 8974 \labelwidthstring 00.00.0000
8974 8975
8975 8976 Gever\SpecialChar ~
8976 8977 Tulley
8977 8978 \family typewriter
8978 8979 <gever-AT-helium.com>
8979 8980 \family default
8980 8981 Code contributions.
8981 8982 \layout List
8982 8983 \labelwidthstring 00.00.0000
8983 8984
8984 8985 Ralf\SpecialChar ~
8985 8986 Schmitt
8986 8987 \family typewriter
8987 8988 <ralf-AT-brainbot.com>
8988 8989 \family default
8989 8990 Bug reports & fixes.
8990 8991 \layout List
8991 8992 \labelwidthstring 00.00.0000
8992 8993
8993 8994 Oliver\SpecialChar ~
8994 8995 Sander
8995 8996 \family typewriter
8996 8997 <osander-AT-gmx.de>
8997 8998 \family default
8998 8999 Bug reports.
8999 9000 \layout List
9000 9001 \labelwidthstring 00.00.0000
9001 9002
9002 9003 Rod\SpecialChar ~
9003 9004 Holland
9004 9005 \family typewriter
9005 9006 <rhh-AT-structurelabs.com>
9006 9007 \family default
9007 9008 Bug reports and fixes to logging module.
9008 9009 \layout List
9009 9010 \labelwidthstring 00.00.0000
9010 9011
9011 9012 Daniel\SpecialChar ~
9012 9013 'Dang'\SpecialChar ~
9013 9014 Griffith
9014 9015 \family typewriter
9015 9016 <pythondev-dang-AT-lazytwinacres.net>
9016 9017 \family default
9017 9018 Fixes, enhancement suggestions for system shell use.
9018 9019 \layout List
9019 9020 \labelwidthstring 00.00.0000
9020 9021
9021 9022 Viktor\SpecialChar ~
9022 9023 Ransmayr
9023 9024 \family typewriter
9024 9025 <viktor.ransmayr-AT-t-online.de>
9025 9026 \family default
9026 9027 Tests and reports on Windows installation issues.
9027 9028 Contributed a true Windows binary installer.
9028 9029 \layout List
9029 9030 \labelwidthstring 00.00.0000
9030 9031
9031 9032 Mike\SpecialChar ~
9032 9033 Salib
9033 9034 \family typewriter
9034 9035 <msalib-AT-mit.edu>
9035 9036 \family default
9036 9037 Help fixing a subtle bug related to traceback printing.
9037 9038 \layout List
9038 9039 \labelwidthstring 00.00.0000
9039 9040
9040 9041 W.J.\SpecialChar ~
9041 9042 van\SpecialChar ~
9042 9043 der\SpecialChar ~
9043 9044 Laan
9044 9045 \family typewriter
9045 9046 <gnufnork-AT-hetdigitalegat.nl>
9046 9047 \family default
9047 9048 Bash-like prompt specials.
9048 9049 \layout List
9049 9050 \labelwidthstring 00.00.0000
9050 9051
9051 9052 Ville\SpecialChar ~
9052 9053 Vainio
9053 9054 \family typewriter
9054 9055 <vivainio-AT-kolumbus.fi>
9055 9056 \family default
9056 9057 Bugfixes and suggestions.
9057 9058 Excellent patches for many new features.
9058 9059 \layout List
9059 9060 \labelwidthstring 00.00.0000
9060 9061
9061 9062 Antoon\SpecialChar ~
9062 9063 Pardon
9063 9064 \family typewriter
9064 9065 <Antoon.Pardon-AT-rece.vub.ac.be>
9065 9066 \family default
9066 9067 Critical fix for the multithreaded IPython.
9067 9068 \layout List
9068 9069 \labelwidthstring 00.00.0000
9069 9070
9070 9071 John\SpecialChar ~
9071 9072 Hunter
9072 9073 \family typewriter
9073 9074 <jdhunter-AT-nitace.bsd.uchicago.edu>
9074 9075 \family default
9075 9076 Matplotlib author, helped with all the development of support for matplotlib
9076 9077 in IPyhton, including making necessary changes to matplotlib itself.
9077 9078 \layout List
9078 9079 \labelwidthstring 00.00.0000
9079 9080
9080 9081 Matthew\SpecialChar ~
9081 9082 Arnison
9082 9083 \family typewriter
9083 9084 <maffew-AT-cat.org.au>
9084 9085 \family default
9085 9086 Bug reports, `
9086 9087 \family typewriter
9087 9088 %run -d
9088 9089 \family default
9089 9090 ' idea.
9090 9091 \layout List
9091 9092 \labelwidthstring 00.00.0000
9092 9093
9093 9094 Prabhu\SpecialChar ~
9094 9095 Ramachandran
9095 9096 \family typewriter
9096 9097 <prabhu_r-AT-users.sourceforge.net>
9097 9098 \family default
9098 9099 Help with (X)Emacs support, threading patches, ideas...
9099 9100 \layout List
9100 9101 \labelwidthstring 00.00.0000
9101 9102
9102 9103 Norbert\SpecialChar ~
9103 9104 Tretkowski
9104 9105 \family typewriter
9105 9106 <tretkowski-AT-inittab.de>
9106 9107 \family default
9107 9108 help with Debian packaging and distribution.
9108 9109 \layout List
9109 9110 \labelwidthstring 00.00.0000
9110 9111
9111 9112 George\SpecialChar ~
9112 9113 Sakkis <
9113 9114 \family typewriter
9114 9115 gsakkis-AT-eden.rutgers.edu>
9115 9116 \family default
9116 9117 New matcher for tab-completing named arguments of user-defined functions.
9117 9118 \layout List
9118 9119 \labelwidthstring 00.00.0000
9119 9120
9120 9121 J�rgen\SpecialChar ~
9121 9122 Stenarson
9122 9123 \family typewriter
9123 9124 <jorgen.stenarson-AT-bostream.nu>
9124 9125 \family default
9125 9126 Wildcard support implementation for searching namespaces.
9126 9127 \layout List
9127 9128 \labelwidthstring 00.00.0000
9128 9129
9129 9130 Vivian\SpecialChar ~
9130 9131 De\SpecialChar ~
9131 9132 Smedt
9132 9133 \family typewriter
9133 9134 <vivian-AT-vdesmedt.com>
9134 9135 \family default
9135 9136 Debugger enhancements, so that when pdb is activated from within IPython,
9136 9137 coloring, tab completion and other features continue to work seamlessly.
9137 9138 \layout List
9138 9139 \labelwidthstring 00.00.0000
9139 9140
9140 9141 Scott\SpecialChar ~
9141 9142 Tsai
9142 9143 \family typewriter
9143 9144 <scottt958-AT-yahoo.com.tw>
9144 9145 \family default
9145 9146 Support for automatic editor invocation on syntax errors (see
9146 9147 \begin_inset LatexCommand \htmlurl{http://www.scipy.net/roundup/ipython/issue36}
9147 9148
9148 9149 \end_inset
9149 9150
9150 9151 ).
9151 9152 \the_end
General Comments 0
You need to be logged in to leave comments. Login now