##// END OF EJS Templates
- Fairly significant changes to include Vivian's patches for improved pdb...
fperez -
Show More
@@ -0,0 +1,109 b''
1 # -*- coding: utf-8 -*-
2 """
3 Color schemes for exception handling code in IPython.
4
5 $Id: Prompts.py 638 2005-07-18 03:01:41Z fperez $"""
6
7 #*****************************************************************************
8 # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu>
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #*****************************************************************************
13
14 from IPython import Release
15 __author__ = '%s <%s>' % Release.authors['Fernando']
16 __license__ = Release.license
17 __version__ = Release.version
18
19 #****************************************************************************
20 # Required modules
21 from IPython.ColorANSI import ColorSchemeTable, TermColors, ColorScheme
22
23 ExceptionColors = ColorSchemeTable()
24
25 # Populate it with color schemes
26 C = TermColors # shorthand and local lookup
27 ExceptionColors.add_scheme(ColorScheme(
28 'NoColor',
29 # The color to be used for the top line
30 topline = C.NoColor,
31
32 # The colors to be used in the traceback
33 filename = C.NoColor,
34 lineno = C.NoColor,
35 name = C.NoColor,
36 vName = C.NoColor,
37 val = C.NoColor,
38 em = C.NoColor,
39
40 # Emphasized colors for the last frame of the traceback
41 normalEm = C.NoColor,
42 filenameEm = C.NoColor,
43 linenoEm = C.NoColor,
44 nameEm = C.NoColor,
45 valEm = C.NoColor,
46
47 # Colors for printing the exception
48 excName = C.NoColor,
49 line = C.NoColor,
50 caret = C.NoColor,
51 Normal = C.NoColor
52 ))
53
54 # make some schemes as instances so we can copy them for modification easily
55 ExceptionColors.add_scheme(ColorScheme(
56 'Linux',
57 # The color to be used for the top line
58 topline = C.LightRed,
59
60 # The colors to be used in the traceback
61 filename = C.Green,
62 lineno = C.Green,
63 name = C.Purple,
64 vName = C.Cyan,
65 val = C.Green,
66 em = C.LightCyan,
67
68 # Emphasized colors for the last frame of the traceback
69 normalEm = C.LightCyan,
70 filenameEm = C.LightGreen,
71 linenoEm = C.LightGreen,
72 nameEm = C.LightPurple,
73 valEm = C.LightBlue,
74
75 # Colors for printing the exception
76 excName = C.LightRed,
77 line = C.Yellow,
78 caret = C.White,
79 Normal = C.Normal
80 ))
81
82 # For light backgrounds, swap dark/light colors
83 ExceptionColors.add_scheme(ColorScheme(
84 'LightBG',
85 # The color to be used for the top line
86 topline = C.Red,
87
88 # The colors to be used in the traceback
89 filename = C.LightGreen,
90 lineno = C.LightGreen,
91 name = C.LightPurple,
92 vName = C.Cyan,
93 val = C.LightGreen,
94 em = C.Cyan,
95
96 # Emphasized colors for the last frame of the traceback
97 normalEm = C.Cyan,
98 filenameEm = C.Green,
99 linenoEm = C.Green,
100 nameEm = C.Purple,
101 valEm = C.Blue,
102
103 # Colors for printing the exception
104 excName = C.Red,
105 #line = C.Brown, # brown often is displayed as yellow
106 line = C.Red,
107 caret = C.Normal,
108 Normal = C.Normal
109 ))
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Tools for coloring text in ANSI terminals.
2 """Tools for coloring text in ANSI terminals.
3
3
4 $Id: ColorANSI.py 410 2004-11-04 07:58:17Z fperez $"""
4 $Id: ColorANSI.py 951 2005-12-25 00:57:24Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu>
7 # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu>
@@ -17,7 +17,6 b' __license__ = Release.license'
17 __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable']
17 __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable']
18
18
19 import os
19 import os
20 from UserDict import UserDict
21
20
22 from IPython.Struct import Struct
21 from IPython.Struct import Struct
23
22
@@ -95,7 +94,13 b' class ColorScheme:'
95 else:
94 else:
96 self.colors = Struct(colordict)
95 self.colors = Struct(colordict)
97
96
98 class ColorSchemeTable(UserDict):
97 def copy(self,name=None):
98 """Return a full copy of the object, optionally renaming it."""
99 if name is None:
100 name = self.name
101 return ColorScheme(name,self.colors.__dict__)
102
103 class ColorSchemeTable(dict):
99 """General class to handle tables of color schemes.
104 """General class to handle tables of color schemes.
100
105
101 It's basically a dict of color schemes with a couple of shorthand
106 It's basically a dict of color schemes with a couple of shorthand
@@ -112,17 +117,21 b' class ColorSchemeTable(UserDict):'
112 the default active scheme.
117 the default active scheme.
113 """
118 """
114
119
115 UserDict.__init__(self)
120 # create object attributes to be set later
116 if scheme_list is None:
117 self.active_scheme_name = ''
121 self.active_scheme_name = ''
118 self.active_colors = None
122 self.active_colors = None
119 else:
123
124 if scheme_list:
120 if default_scheme == '':
125 if default_scheme == '':
121 raise ValueError,'you must specify the default color scheme'
126 raise ValueError,'you must specify the default color scheme'
122 for scheme in scheme_list:
127 for scheme in scheme_list:
123 self.add_scheme(scheme)
128 self.add_scheme(scheme)
124 self.set_active_scheme(default_scheme)
129 self.set_active_scheme(default_scheme)
125
130
131 def copy(self):
132 """Return full copy of object"""
133 return ColorSchemeTable(self.values(),self.active_scheme_name)
134
126 def add_scheme(self,new_scheme):
135 def add_scheme(self,new_scheme):
127 """Add a new color scheme to the table."""
136 """Add a new color scheme to the table."""
128 if not isinstance(new_scheme,ColorScheme):
137 if not isinstance(new_scheme,ColorScheme):
@@ -135,20 +144,20 b' class ColorSchemeTable(UserDict):'
135 Names are by default compared in a case-insensitive way, but this can
144 Names are by default compared in a case-insensitive way, but this can
136 be changed by setting the parameter case_sensitive to true."""
145 be changed by setting the parameter case_sensitive to true."""
137
146
138 scheme_list = self.keys()
147 scheme_names = self.keys()
139 if case_sensitive:
148 if case_sensitive:
140 valid_schemes = scheme_list
149 valid_schemes = scheme_names
141 scheme_test = scheme
150 scheme_test = scheme
142 else:
151 else:
143 valid_schemes = [s.lower() for s in scheme_list]
152 valid_schemes = [s.lower() for s in scheme_names]
144 scheme_test = scheme.lower()
153 scheme_test = scheme.lower()
145 try:
154 try:
146 scheme_idx = valid_schemes.index(scheme_test)
155 scheme_idx = valid_schemes.index(scheme_test)
147 except ValueError:
156 except ValueError:
148 raise ValueError,'Unrecognized color scheme: ' + scheme + \
157 raise ValueError,'Unrecognized color scheme: ' + scheme + \
149 '\nValid schemes: '+str(scheme_list).replace("'', ",'')
158 '\nValid schemes: '+str(scheme_names).replace("'', ",'')
150 else:
159 else:
151 active = scheme_list[scheme_idx]
160 active = scheme_names[scheme_idx]
152 self.active_scheme_name = active
161 self.active_scheme_name = active
153 self.active_colors = self[active].colors
162 self.active_colors = self[active].colors
154 # Now allow using '' as an index for the current active scheme
163 # Now allow using '' as an index for the current active scheme
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """sys.excepthook for IPython itself, leaves a detailed report on disk.
2 """sys.excepthook for IPython itself, leaves a detailed report on disk.
3
3
4 $Id: CrashHandler.py 775 2005-09-01 20:24:59Z fperez $"""
4 $Id: CrashHandler.py 951 2005-12-25 00:57:24Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
7 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -23,10 +23,10 b' import os,sys'
23 from pprint import pprint,pformat
23 from pprint import pprint,pformat
24
24
25 # Homebrewed
25 # Homebrewed
26 from IPython.genutils import *
27 from IPython.Itpl import Itpl,itpl,printpl
26 from IPython.Itpl import Itpl,itpl,printpl
27 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
28 from IPython import ultraTB
28 from IPython import ultraTB
29 from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names
29 from IPython.genutils import *
30
30
31 #****************************************************************************
31 #****************************************************************************
32 class CrashHandler:
32 class CrashHandler:
@@ -15,39 +15,250 b' details on the PSF (Python Software Foundation) standard license, see:'
15
15
16 http://www.python.org/2.2.3/license.html
16 http://www.python.org/2.2.3/license.html
17
17
18 $Id: Debugger.py 590 2005-05-30 06:26:51Z fperez $"""
18 $Id: Debugger.py 951 2005-12-25 00:57:24Z fperez $"""
19
19
20 from IPython import Release
20 from IPython import Release
21 __author__ = '%s <%s>' % Release.authors['Fernando']
21 __author__ = '%s <%s>' % Release.authors['Fernando']
22 __license__ = 'Python'
22 __license__ = 'Python'
23
23
24 import pdb,bdb,cmd,os,sys
24 import pdb,bdb,cmd,os,sys,linecache
25 from IPython import PyColorize, ColorANSI
26 from IPython.genutils import Term
27 from IPython.excolors import ExceptionColors
28
29 def _file_lines(fname):
30 """Return the contents of a named file as a list of lines.
31
32 This function never raises an IOError exception: if the file can't be
33 read, it simply returns an empty list."""
34
35 try:
36 outfile = open(fname)
37 except IOError:
38 return []
39 else:
40 out = outfile.readlines()
41 outfile.close()
42 return out
43
25
44
26 class Pdb(pdb.Pdb):
45 class Pdb(pdb.Pdb):
27 """Modified Pdb class, does not load readline."""
46 """Modified Pdb class, does not load readline."""
28 def __init__(self):
47 def __init__(self,color_scheme='NoColor'):
29 bdb.Bdb.__init__(self)
48 bdb.Bdb.__init__(self)
30 cmd.Cmd.__init__(self,completekey=None) # don't load readline
49 cmd.Cmd.__init__(self,completekey=None) # don't load readline
31 self.prompt = '(Pdb) '
50 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
32 self.aliases = {}
51 self.aliases = {}
33
52
34 # Read $HOME/.pdbrc and ./.pdbrc
53 # Read $HOME/.pdbrc and ./.pdbrc
54 try:
55 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
56 ".pdbrc"))
57 except KeyError:
35 self.rcLines = []
58 self.rcLines = []
36 if os.environ.has_key('HOME'):
59 self.rcLines.extend(_file_lines(".pdbrc"))
37 envHome = os.environ['HOME']
60
61 # Create color table: we copy the default one from the traceback
62 # module and add a few attributes needed for debugging
63 self.color_scheme_table = ExceptionColors.copy()
64
65 # shorthands
66 C = ColorANSI.TermColors
67 cst = self.color_scheme_table
68
69 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
70 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
71
72 cst['Linux'].colors.breakpoint_enabled = C.LightRed
73 cst['Linux'].colors.breakpoint_disabled = C.Red
74
75 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
76 cst['LightBG'].colors.breakpoint_disabled = C.Red
77
78 self.set_colors(color_scheme)
79
80 def set_colors(self, scheme):
81 """Shorthand access to the color table scheme selector method."""
82 self.color_scheme_table.set_active_scheme(scheme)
83
84
85 def interaction(self, frame, traceback):
86 __IPYTHON__.set_completer_frame(frame)
87 pdb.Pdb.interaction(self, frame, traceback)
88
89
90 def do_up(self, arg):
91 pdb.Pdb.do_up(self, arg)
92 __IPYTHON__.set_completer_frame(self.curframe)
93 do_u = do_up
94
95
96 def do_down(self, arg):
97 pdb.Pdb.do_down(self, arg)
98 __IPYTHON__.set_completer_frame(self.curframe)
99 do_d = do_down
100
101
102 def postloop(self):
103 __IPYTHON__.set_completer_frame(None)
104
105
106 def print_stack_trace(self):
38 try:
107 try:
39 rcFile = open(os.path.join(envHome, ".pdbrc"))
108 for frame_lineno in self.stack:
40 except IOError:
109 self.print_stack_entry(frame_lineno, context = 5)
110 except KeyboardInterrupt:
41 pass
111 pass
112
113
114 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
115 context = 3):
116 frame, lineno = frame_lineno
117 print >>Term.cout, self.format_stack_entry(frame_lineno, '', context)
118
119
120 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
121 import linecache, repr
122
123 ret = ""
124
125 Colors = self.color_scheme_table.active_colors
126 ColorsNormal = Colors.Normal
127 tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
128 tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
129 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
130 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
131 ColorsNormal)
132
133 frame, lineno = frame_lineno
134
135 return_value = ''
136 if '__return__' in frame.f_locals:
137 rv = frame.f_locals['__return__']
138 #return_value += '->'
139 return_value += repr.repr(rv) + '\n'
140 ret += return_value
141
142 #s = filename + '(' + `lineno` + ')'
143 filename = self.canonic(frame.f_code.co_filename)
144 link = tpl_link % filename
145
146 if frame.f_code.co_name:
147 func = frame.f_code.co_name
148 else:
149 func = "<lambda>"
150
151 call = ''
152 if func != '?':
153 if '__args__' in frame.f_locals:
154 args = repr.repr(frame.f_locals['__args__'])
155 else:
156 args = '()'
157 call = tpl_call % (func, args)
158
159 level = '%s %s\n' % (link, call)
160 ret += level
161
162 start = lineno - 1 - context//2
163 lines = linecache.getlines(filename)
164 start = max(start, 0)
165 start = min(start, len(lines) - context)
166 lines = lines[start : start + context]
167
168 for i in range(len(lines)):
169 line = lines[i]
170 if start + 1 + i == lineno:
171 ret += self.__format_line(tpl_line_em, filename, start + 1 + i, line, arrow = True)
172 else:
173 ret += self.__format_line(tpl_line, filename, start + 1 + i, line, arrow = False)
174
175 return ret
176
177
178 def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
179 bp_mark = ""
180 bp_mark_color = ""
181
182 bp = None
183 if lineno in self.get_file_breaks(filename):
184 bps = self.get_breaks(filename, lineno)
185 bp = bps[-1]
186
187 if bp:
188 Colors = self.color_scheme_table.active_colors
189 bp_mark = str(bp.number)
190 bp_mark_color = Colors.breakpoint_enabled
191 if not bp.enabled:
192 bp_mark_color = Colors.breakpoint_disabled
193
194 numbers_width = 7
195 if arrow:
196 # This is the line with the error
197 pad = numbers_width - len(str(lineno)) - len(bp_mark)
198 if pad >= 3:
199 marker = '-'*(pad-3) + '-> '
200 elif pad == 2:
201 marker = '> '
202 elif pad == 1:
203 marker = '>'
204 else:
205 marker = ''
206 num = '%s%s' % (marker, str(lineno))
207 line = tpl_line % (bp_mark_color + bp_mark, num, line)
42 else:
208 else:
43 for line in rcFile.readlines():
209 num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
44 self.rcLines.append(line)
210 line = tpl_line % (bp_mark_color + bp_mark, num, line)
45 rcFile.close()
211
212 return line
213
214
215 def do_list(self, arg):
216 self.lastcmd = 'list'
217 last = None
218 if arg:
46 try:
219 try:
47 rcFile = open(".pdbrc")
220 x = eval(arg, {}, {})
48 except IOError:
221 if type(x) == type(()):
49 pass
222 first, last = x
223 first = int(first)
224 last = int(last)
225 if last < first:
226 # Assume it's a count
227 last = first + last
228 else:
229 first = max(1, int(x) - 5)
230 except:
231 print '*** Error in argument:', `arg`
232 return
233 elif self.lineno is None:
234 first = max(1, self.curframe.f_lineno - 5)
50 else:
235 else:
51 for line in rcFile.readlines():
236 first = self.lineno + 1
52 self.rcLines.append(line)
237 if last is None:
53 rcFile.close()
238 last = first + 10
239 filename = self.curframe.f_code.co_filename
240 try:
241 Colors = self.color_scheme_table.active_colors
242 ColorsNormal = Colors.Normal
243 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
244 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
245 src = []
246 for lineno in range(first, last+1):
247 line = linecache.getline(filename, lineno)
248 if not line:
249 break
250
251 if lineno == self.curframe.f_lineno:
252 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
253 else:
254 line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
255
256 src.append(line)
257 self.lineno = lineno
258
259 print >>Term.cout, ''.join(src)
260
261 except KeyboardInterrupt:
262 pass
263
264 do_l = do_list
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 923 2005-11-15 08:51:15Z fperez $"""
4 $Id: Magic.py 951 2005-12-25 00:57:24Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -22,13 +22,16 b' __license__ = Release.license'
22 # Python standard modules
22 # Python standard modules
23 import __builtin__
23 import __builtin__
24 import os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time
24 import os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time
25 import Debugger
26 from getopt import getopt
27 from pprint import pprint, pformat
28 from cStringIO import StringIO
29
30 # profile isn't bundled by default in Debian for license reasons
25 try:
31 try:
26 import profile,pstats
32 import profile,pstats
27 except ImportError:
33 except ImportError:
28 profile = pstats = None
34 profile = pstats = None
29 from getopt import getopt
30 from pprint import pprint, pformat
31 from cStringIO import StringIO
32
35
33 # Homebrewed
36 # Homebrewed
34 from IPython.Struct import Struct
37 from IPython.Struct import Struct
@@ -1371,7 +1374,7 b' Currently the magic system has the following functions:\\n"""'
1371 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1374 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1372 else:
1375 else:
1373 if opts.has_key('d'):
1376 if opts.has_key('d'):
1374 deb = pdb.Pdb()
1377 deb = Debugger.Pdb(self.shell.rc.colors)
1375 # reset Breakpoint state, which is moronically kept
1378 # reset Breakpoint state, which is moronically kept
1376 # in a class
1379 # in a class
1377 bdb.Breakpoint.next = 1
1380 bdb.Breakpoint.next = 1
@@ -1397,8 +1400,15 b' Currently the magic system has the following functions:\\n"""'
1397 deb.do_break('%s:%s' % (filename,bp))
1400 deb.do_break('%s:%s' % (filename,bp))
1398 # Start file run
1401 # Start file run
1399 print "NOTE: Enter 'c' at the",
1402 print "NOTE: Enter 'c' at the",
1400 print "(Pdb) prompt to start your script."
1403 print "ipdb> prompt to start your script."
1404 try:
1401 deb.run('execfile("%s")' % filename,prog_ns)
1405 deb.run('execfile("%s")' % filename,prog_ns)
1406 except:
1407 etype, value, tb = sys.exc_info()
1408 # Skip three frames in the traceback: the %run one,
1409 # one inside bdb.py, and the command-line typed by the
1410 # user (run by exec in pdb itself).
1411 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1402 else:
1412 else:
1403 if runner is None:
1413 if runner is None:
1404 runner = self.shell.safe_execfile
1414 runner = self.shell.safe_execfile
@@ -2,7 +2,7 b''
2 """
2 """
3 Classes for handling input/output prompts.
3 Classes for handling input/output prompts.
4
4
5 $Id: Prompts.py 638 2005-07-18 03:01:41Z fperez $"""
5 $Id: Prompts.py 951 2005-12-25 00:57:24Z fperez $"""
6
6
7 #*****************************************************************************
7 #*****************************************************************************
8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
@@ -49,6 +49,7 b' PromptColors.add_scheme(ColorANSI.ColorScheme('
49
49
50 normal = Colors.NoColor # color off (usu. Colors.Normal)
50 normal = Colors.NoColor # color off (usu. Colors.Normal)
51 ))
51 ))
52
52 # make some schemes as instances so we can copy them for modification easily:
53 # make some schemes as instances so we can copy them for modification easily:
53 __PColLinux = ColorANSI.ColorScheme(
54 __PColLinux = ColorANSI.ColorScheme(
54 'Linux',
55 'Linux',
@@ -64,8 +65,9 b' __PColLinux = ColorANSI.ColorScheme('
64 )
65 )
65 # Don't forget to enter it into the table!
66 # Don't forget to enter it into the table!
66 PromptColors.add_scheme(__PColLinux)
67 PromptColors.add_scheme(__PColLinux)
68
67 # Slightly modified Linux for light backgrounds
69 # Slightly modified Linux for light backgrounds
68 __PColLightBG = ColorANSI.ColorScheme('LightBG',**__PColLinux.colors.dict().copy())
70 __PColLightBG = __PColLinux.copy('LightBG')
69
71
70 __PColLightBG.colors.update(
72 __PColLightBG.colors.update(
71 in_prompt = InputColors.Blue,
73 in_prompt = InputColors.Blue,
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Release data for the IPython project.
2 """Release data for the IPython project.
3
3
4 $Id: Release.py 775 2005-09-01 20:24:59Z fperez $"""
4 $Id: Release.py 951 2005-12-25 00:57:24Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu>
7 # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu>
@@ -24,7 +24,7 b" name = 'ipython'"
24
24
25 version = '0.6.16.svn'
25 version = '0.6.16.svn'
26
26
27 revision = '$Revision: 775 $'
27 revision = '$Revision: 951 $'
28
28
29 description = "An enhanced interactive Python shell."
29 description = "An enhanced interactive Python shell."
30
30
@@ -69,6 +69,8 b" authors = {'Fernando' : ('Fernando Perez','fperez@colorado.edu'),"
69
69
70 url = 'http://ipython.scipy.org'
70 url = 'http://ipython.scipy.org'
71
71
72 download_url = 'http://ipython.scipy.org/dist'
73
72 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
74 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
73
75
74 keywords = ['Interactive','Interpreter','Shell']
76 keywords = ['Interactive','Interpreter','Shell']
@@ -6,7 +6,7 b' Requires Python 2.1 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 924 2005-11-15 20:24:31Z fperez $
9 $Id: iplib.py 951 2005-12-25 00:57:24Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -54,7 +54,7 b' from codeop import CommandCompiler'
54 # IPython's own modules
54 # IPython's own modules
55 import IPython
55 import IPython
56 from IPython import OInspect,PyColorize,ultraTB
56 from IPython import OInspect,PyColorize,ultraTB
57 from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names
57 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
58 from IPython.Logger import Logger
58 from IPython.Logger import Logger
59 from IPython.Magic import Magic,magic2python,shlex_split
59 from IPython.Magic import Magic,magic2python,shlex_split
60 from IPython.usage import cmd_line_usage,interactive_usage
60 from IPython.usage import cmd_line_usage,interactive_usage
@@ -970,6 +970,14 b' class InteractiveShell(code.InteractiveConsole, Logger, Magic):'
970 outcomps.sort()
970 outcomps.sort()
971 return outcomps
971 return outcomps
972
972
973 def set_completer_frame(self, frame):
974 if frame:
975 ns = frame.f_globals.copy()
976 ns.update(frame.f_locals)
977 self.Completer.namespace = ns
978 else:
979 self.Completer.namespace = self.user_ns
980
973 def post_config_initialization(self):
981 def post_config_initialization(self):
974 """Post configuration init method
982 """Post configuration init method
975
983
@@ -60,7 +60,7 b' You can implement other color schemes easily, the syntax is fairly'
60 self-explanatory. Please send back new schemes you develop to the author for
60 self-explanatory. Please send back new schemes you develop to the author for
61 possible inclusion in future releases.
61 possible inclusion in future releases.
62
62
63 $Id: ultraTB.py 703 2005-08-16 17:34:44Z fperez $"""
63 $Id: ultraTB.py 951 2005-12-25 00:57:24Z fperez $"""
64
64
65 #*****************************************************************************
65 #*****************************************************************************
66 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
66 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
@@ -85,8 +85,8 b' from UserDict import UserDict'
85 from IPython import Debugger
85 from IPython import Debugger
86
86
87 from IPython.Struct import Struct
87 from IPython.Struct import Struct
88 from IPython.ColorANSI import *
89 from IPython.genutils import Term,uniq_stable,error,info
88 from IPython.genutils import Term,uniq_stable,error,info
89 from IPython.excolors import ExceptionColors
90
90
91 #---------------------------------------------------------------------------
91 #---------------------------------------------------------------------------
92 # Code begins
92 # Code begins
@@ -99,131 +99,42 b' def inspect_error():'
99 error('Internal Python error in the inspect module.\n'
99 error('Internal Python error in the inspect module.\n'
100 'Below is the traceback from this internal error.\n')
100 'Below is the traceback from this internal error.\n')
101
101
102 # Make a global variable out of the color scheme table used for coloring
103 # exception tracebacks. This allows user code to add new schemes at runtime.
104 ExceptionColors = ColorSchemeTable()
105
106 # Populate it with color schemes
107 C = TermColors # shorthand and local lookup
108 ExceptionColors.add_scheme(ColorScheme(
109 'NoColor',
110 # The color to be used for the top line
111 topline = C.NoColor,
112
113 # The colors to be used in the traceback
114 filename = C.NoColor,
115 lineno = C.NoColor,
116 name = C.NoColor,
117 vName = C.NoColor,
118 val = C.NoColor,
119 em = C.NoColor,
120
121 # Emphasized colors for the last frame of the traceback
122 normalEm = C.NoColor,
123 filenameEm = C.NoColor,
124 linenoEm = C.NoColor,
125 nameEm = C.NoColor,
126 valEm = C.NoColor,
127
128 # Colors for printing the exception
129 excName = C.NoColor,
130 line = C.NoColor,
131 caret = C.NoColor,
132 Normal = C.NoColor
133 ))
134
135 # make some schemes as instances so we can copy them for modification easily
136 ExceptionColors.add_scheme(ColorScheme(
137 'Linux',
138 # The color to be used for the top line
139 topline = C.LightRed,
140
141 # The colors to be used in the traceback
142 filename = C.Green,
143 lineno = C.Green,
144 name = C.Purple,
145 vName = C.Cyan,
146 val = C.Green,
147 em = C.LightCyan,
148
149 # Emphasized colors for the last frame of the traceback
150 normalEm = C.LightCyan,
151 filenameEm = C.LightGreen,
152 linenoEm = C.LightGreen,
153 nameEm = C.LightPurple,
154 valEm = C.LightBlue,
155
156 # Colors for printing the exception
157 excName = C.LightRed,
158 line = C.Yellow,
159 caret = C.White,
160 Normal = C.Normal
161 ))
162
163 # For light backgrounds, swap dark/light colors
164 ExceptionColors.add_scheme(ColorScheme(
165 'LightBG',
166 # The color to be used for the top line
167 topline = C.Red,
168
169 # The colors to be used in the traceback
170 filename = C.LightGreen,
171 lineno = C.LightGreen,
172 name = C.LightPurple,
173 vName = C.Cyan,
174 val = C.LightGreen,
175 em = C.Cyan,
176
177 # Emphasized colors for the last frame of the traceback
178 normalEm = C.Cyan,
179 filenameEm = C.Green,
180 linenoEm = C.Green,
181 nameEm = C.Purple,
182 valEm = C.Blue,
183
184 # Colors for printing the exception
185 excName = C.Red,
186 #line = C.Brown, # brown often is displayed as yellow
187 line = C.Red,
188 caret = C.Normal,
189 Normal = C.Normal
190 ))
191
192 class TBTools:
102 class TBTools:
193 """Basic tools used by all traceback printer classes."""
103 """Basic tools used by all traceback printer classes."""
194
104
195 def __init__(self,color_scheme = 'NoColor',call_pdb=0):
105 def __init__(self,color_scheme = 'NoColor',call_pdb=False):
196 # Whether to call the interactive pdb debugger after printing
106 # Whether to call the interactive pdb debugger after printing
197 # tracebacks or not
107 # tracebacks or not
198 self.call_pdb = call_pdb
108 self.call_pdb = call_pdb
199 if call_pdb:
200 self.pdb = Debugger.Pdb()
201 else:
202 self.pdb = None
203
109
204 # Create color table
110 # Create color table
205 self.ColorSchemeTable = ExceptionColors
111 self.color_scheme_table = ExceptionColors
206
112
207 self.set_colors(color_scheme)
113 self.set_colors(color_scheme)
208 self.old_scheme = color_scheme # save initial value for toggles
114 self.old_scheme = color_scheme # save initial value for toggles
209
115
116 if call_pdb:
117 self.pdb = Debugger.Pdb(self.color_scheme_table.active_scheme_name)
118 else:
119 self.pdb = None
120
210 def set_colors(self,*args,**kw):
121 def set_colors(self,*args,**kw):
211 """Shorthand access to the color table scheme selector method."""
122 """Shorthand access to the color table scheme selector method."""
212
123
213 self.ColorSchemeTable.set_active_scheme(*args,**kw)
124 self.color_scheme_table.set_active_scheme(*args,**kw)
214 # for convenience, set Colors to the active scheme
125 # for convenience, set Colors to the active scheme
215 self.Colors = self.ColorSchemeTable.active_colors
126 self.Colors = self.color_scheme_table.active_colors
216
127
217 def color_toggle(self):
128 def color_toggle(self):
218 """Toggle between the currently active color scheme and NoColor."""
129 """Toggle between the currently active color scheme and NoColor."""
219
130
220 if self.ColorSchemeTable.active_scheme_name == 'NoColor':
131 if self.color_scheme_table.active_scheme_name == 'NoColor':
221 self.ColorSchemeTable.set_active_scheme(self.old_scheme)
132 self.color_scheme_table.set_active_scheme(self.old_scheme)
222 self.Colors = self.ColorSchemeTable.active_colors
133 self.Colors = self.color_scheme_table.active_colors
223 else:
134 else:
224 self.old_scheme = self.ColorSchemeTable.active_scheme_name
135 self.old_scheme = self.color_scheme_table.active_scheme_name
225 self.ColorSchemeTable.set_active_scheme('NoColor')
136 self.color_scheme_table.set_active_scheme('NoColor')
226 self.Colors = self.ColorSchemeTable.active_colors
137 self.Colors = self.color_scheme_table.active_colors
227
138
228 #---------------------------------------------------------------------------
139 #---------------------------------------------------------------------------
229 class ListTB(TBTools):
140 class ListTB(TBTools):
@@ -660,14 +571,21 b' class VerboseTB(TBTools):'
660
571
661 if self.call_pdb:
572 if self.call_pdb:
662 if self.pdb is None:
573 if self.pdb is None:
663 self.pdb = Debugger.Pdb()
574 self.pdb = Debugger.Pdb(
664 # the system displayhook may have changed, restore the original for pdb
575 self.color_scheme_table.active_scheme_name)
576 # the system displayhook may have changed, restore the original
577 # for pdb
665 dhook = sys.displayhook
578 dhook = sys.displayhook
666 sys.displayhook = sys.__displayhook__
579 sys.displayhook = sys.__displayhook__
667 self.pdb.reset()
580 self.pdb.reset()
581 # Find the right frame so we don't pop up inside ipython itself
582 etb = self.tb
668 while self.tb.tb_next is not None:
583 while self.tb.tb_next is not None:
669 self.tb = self.tb.tb_next
584 self.tb = self.tb.tb_next
670 try:
585 try:
586 if etb and etb.tb_next:
587 etb = etb.tb_next
588 self.pdb.botframe = etb.tb_frame
671 self.pdb.interaction(self.tb.tb_frame, self.tb)
589 self.pdb.interaction(self.tb.tb_frame, self.tb)
672 except:
590 except:
673 print '*** ERROR ***'
591 print '*** ERROR ***'
@@ -801,7 +719,7 b' class AutoFormattedTB(FormattedTB):'
801 print >> out, self.text(etype, evalue, etb)
719 print >> out, self.text(etype, evalue, etb)
802 self.tb_offset = tb_offset
720 self.tb_offset = tb_offset
803 else:
721 else:
804 print >> out, self.text()
722 print >> out, self.text(etype, evalue, etb)
805 self.debugger()
723 self.debugger()
806
724
807 def text(self,etype=None,value=None,tb=None,context=5,mode=None):
725 def text(self,etype=None,value=None,tb=None,context=5,mode=None):
@@ -1,3 +1,19 b''
1 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * setup.py: added download_url to setup(). This registers the
4 download address at PyPI, which is not only useful to humans
5 browsing the site, but is also picked up by setuptools (the Eggs
6 machinery). Thanks to Ville and R. Kern for the info/discussion
7 on this.
8
9 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
10
11 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
12 This brings a lot of nice functionality to the pdb mode, which now
13 has tab-completion, syntax highlighting, and better stack handling
14 than before. Many thanks to Vivian De Smedt
15 <vivian-AT-vdesmedt.com> for the original patches.
16
1 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
17 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
2
18
3 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
19 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
@@ -11,7 +27,7 b''
11 Fix bug where a naked 'alias' call in the ipythonrc file would
27 Fix bug where a naked 'alias' call in the ipythonrc file would
12 cause a crash. Bug reported by Jorgen Stenarson.
28 cause a crash. Bug reported by Jorgen Stenarson.
13
29
14 2005-11-15 <Fernando.Perez@colorado.edu>
30 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
15
31
16 * IPython/ipmaker.py (make_IPython): cleanups which should improve
32 * IPython/ipmaker.py (make_IPython): cleanups which should improve
17 startup time.
33 startup time.
@@ -26,13 +42,13 b''
26 searches. Users can still select either mode at runtime on a
42 searches. Users can still select either mode at runtime on a
27 per-search basis.
43 per-search basis.
28
44
29 2005-11-13 <Fernando.Perez@colorado.edu>
45 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
30
46
31 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
47 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
32 attributes in wildcard searches for subclasses. Modified version
48 attributes in wildcard searches for subclasses. Modified version
33 of a patch by Jorgen.
49 of a patch by Jorgen.
34
50
35 2005-11-12 <Fernando.Perez@colorado.edu>
51 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
36
52
37 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
53 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
38 embedded instances. I added a user_global_ns attribute to the
54 embedded instances. I added a user_global_ns attribute to the
@@ -133,6 +133,7 b' setup(name = name,'
133 author = authors['Fernando'][0],
133 author = authors['Fernando'][0],
134 author_email = authors['Fernando'][1],
134 author_email = authors['Fernando'][1],
135 url = url,
135 url = url,
136 download_url = download_url,
136 license = license,
137 license = license,
137 platforms = platforms,
138 platforms = platforms,
138 keywords = keywords,
139 keywords = keywords,
General Comments 0
You need to be logged in to leave comments. Login now