Show More
@@ -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 19 |
|
4 | $Id: Magic.py 1956 2006-11-30 05:22:31Z 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 | |
@@ -1164,14 +1164,21 b' Currently the magic system has the following functions:\\n"""' | |||||
1164 | self.shell.logger.logstate() |
|
1164 | self.shell.logger.logstate() | |
1165 |
|
1165 | |||
1166 | def magic_pdb(self, parameter_s=''): |
|
1166 | def magic_pdb(self, parameter_s=''): | |
1167 | """Control the calling of the pdb interactive debugger. |
|
1167 | """Control the automatic calling of the pdb interactive debugger. | |
1168 |
|
1168 | |||
1169 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
|
1169 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without | |
1170 | argument it works as a toggle. |
|
1170 | argument it works as a toggle. | |
1171 |
|
1171 | |||
1172 | When an exception is triggered, IPython can optionally call the |
|
1172 | When an exception is triggered, IPython can optionally call the | |
1173 | interactive pdb debugger after the traceback printout. %pdb toggles |
|
1173 | interactive pdb debugger after the traceback printout. %pdb toggles | |
1174 |
this feature on and off. |
|
1174 | this feature on and off. | |
|
1175 | ||||
|
1176 | The initial state of this feature is set in your ipythonrc | |||
|
1177 | configuration file (the variable is called 'pdb'). | |||
|
1178 | ||||
|
1179 | If you want to just activate the debugger AFTER an exception has fired, | |||
|
1180 | without having to type '%pdb on' and rerunning your code, you can use | |||
|
1181 | the %debug magic.""" | |||
1175 |
|
1182 | |||
1176 | par = parameter_s.strip().lower() |
|
1183 | par = parameter_s.strip().lower() | |
1177 |
|
1184 | |||
@@ -1184,12 +1191,27 b' Currently the magic system has the following functions:\\n"""' | |||||
1184 | return |
|
1191 | return | |
1185 | else: |
|
1192 | else: | |
1186 | # toggle |
|
1193 | # toggle | |
1187 |
new_pdb = not self.shell. |
|
1194 | new_pdb = not self.shell.call_pdb | |
1188 |
|
1195 | |||
1189 | # set on the shell |
|
1196 | # set on the shell | |
1190 | self.shell.call_pdb = new_pdb |
|
1197 | self.shell.call_pdb = new_pdb | |
1191 | print 'Automatic pdb calling has been turned',on_off(new_pdb) |
|
1198 | print 'Automatic pdb calling has been turned',on_off(new_pdb) | |
1192 |
|
1199 | |||
|
1200 | def magic_debug(self, parameter_s=''): | |||
|
1201 | """Activate the interactive debugger in post-mortem mode. | |||
|
1202 | ||||
|
1203 | If an exception has just occurred, this lets you inspect its stack | |||
|
1204 | frames interactively. Note that this will always work only on the last | |||
|
1205 | traceback that occurred, so you must call this quickly after an | |||
|
1206 | exception that you wish to inspect has fired, because if another one | |||
|
1207 | occurs, it clobbers the previous one. | |||
|
1208 | ||||
|
1209 | If you want IPython to automatically do this on every exception, see | |||
|
1210 | the %pdb magic for more details. | |||
|
1211 | """ | |||
|
1212 | ||||
|
1213 | self.shell.debugger(force=True) | |||
|
1214 | ||||
1193 | def magic_prun(self, parameter_s ='',user_mode=1, |
|
1215 | def magic_prun(self, parameter_s ='',user_mode=1, | |
1194 | opts=None,arg_lst=None,prog_ns=None): |
|
1216 | opts=None,arg_lst=None,prog_ns=None): | |
1195 |
|
1217 |
@@ -6,7 +6,7 b' Requires Python 2.3 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 19 |
|
9 | $Id: iplib.py 1956 2006-11-30 05:22:31Z fperez $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
@@ -1412,20 +1412,31 b' want to merge them back into the new files.""" % locals()' | |||||
1412 | value = msg, (filename, lineno, offset, line) |
|
1412 | value = msg, (filename, lineno, offset, line) | |
1413 | self.SyntaxTB(etype,value,[]) |
|
1413 | self.SyntaxTB(etype,value,[]) | |
1414 |
|
1414 | |||
1415 | def debugger(self): |
|
1415 | def debugger(self,force=False): | |
1416 |
"""Call the pydb/pdb debugger. |
|
1416 | """Call the pydb/pdb debugger. | |
1417 |
|
|
1417 | ||
1418 | if not self.rc.pdb: |
|
1418 | Keywords: | |
|
1419 | ||||
|
1420 | - force(False): by default, this routine checks the instance call_pdb | |||
|
1421 | flag and does not actually invoke the debugger if the flag is false. | |||
|
1422 | The 'force' option forces the debugger to activate even if the flag | |||
|
1423 | is false. | |||
|
1424 | """ | |||
|
1425 | ||||
|
1426 | if not (force or self.call_pdb): | |||
1419 | return |
|
1427 | return | |
|
1428 | ||||
1420 | have_pydb = False |
|
1429 | have_pydb = False | |
1421 | if sys.version[:3] >= '2.5': |
|
1430 | if sys.version[:3] >= '2.5': | |
|
1431 | # use pydb if available | |||
1422 | try: |
|
1432 | try: | |
1423 | from pydb import pm |
|
1433 | from pydb import pm | |
1424 | have_pydb = True |
|
1434 | have_pydb = True | |
1425 | except ImportError: |
|
1435 | except ImportError: | |
1426 | pass |
|
1436 | pass | |
1427 | if not have_pydb: |
|
1437 | if not have_pydb: | |
1428 | from pdb import pm |
|
1438 | # fallback to our internal debugger | |
|
1439 | pm = lambda : self.InteractiveTB.debugger(force=True) | |||
1429 | self.history_saving_wrapper(pm)() |
|
1440 | self.history_saving_wrapper(pm)() | |
1430 |
|
1441 | |||
1431 | def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None): |
|
1442 | def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None): |
@@ -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 1 |
|
63 | $Id: ultraTB.py 1956 2006-11-30 05:22:31Z fperez $""" | |
64 |
|
64 | |||
65 | #***************************************************************************** |
|
65 | #***************************************************************************** | |
66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
|
66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> | |
@@ -666,8 +666,16 b' class VerboseTB(TBTools):' | |||||
666 | # return all our info assembled as a single string |
|
666 | # return all our info assembled as a single string | |
667 | return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) ) |
|
667 | return '%s\n\n%s\n%s' % (head,'\n'.join(frames),''.join(exception[0]) ) | |
668 |
|
668 | |||
669 | def debugger(self): |
|
669 | def debugger(self,force=False): | |
670 |
"""Call up the pdb debugger if desired, always clean up the tb |
|
670 | """Call up the pdb debugger if desired, always clean up the tb | |
|
671 | reference. | |||
|
672 | ||||
|
673 | Keywords: | |||
|
674 | ||||
|
675 | - force(False): by default, this routine checks the instance call_pdb | |||
|
676 | flag and does not actually invoke the debugger if the flag is false. | |||
|
677 | The 'force' option forces the debugger to activate even if the flag | |||
|
678 | is false. | |||
671 |
|
679 | |||
672 | If the call_pdb flag is set, the pdb interactive debugger is |
|
680 | If the call_pdb flag is set, the pdb interactive debugger is | |
673 | invoked. In all cases, the self.tb reference to the current traceback |
|
681 | invoked. In all cases, the self.tb reference to the current traceback | |
@@ -678,7 +686,7 b' class VerboseTB(TBTools):' | |||||
678 | requires a special setup for the readline completers, you'll have to |
|
686 | requires a special setup for the readline completers, you'll have to | |
679 | fix that by hand after invoking the exception handler.""" |
|
687 | fix that by hand after invoking the exception handler.""" | |
680 |
|
688 | |||
681 | if self.call_pdb: |
|
689 | if force or self.call_pdb: | |
682 | if self.pdb is None: |
|
690 | if self.pdb is None: | |
683 | self.pdb = Debugger.Pdb( |
|
691 | self.pdb = Debugger.Pdb( | |
684 | self.color_scheme_table.active_scheme_name) |
|
692 | self.color_scheme_table.active_scheme_name) | |
@@ -688,7 +696,10 b' class VerboseTB(TBTools):' | |||||
688 | sys.displayhook = sys.__displayhook__ |
|
696 | sys.displayhook = sys.__displayhook__ | |
689 | self.pdb.reset() |
|
697 | self.pdb.reset() | |
690 | # Find the right frame so we don't pop up inside ipython itself |
|
698 | # Find the right frame so we don't pop up inside ipython itself | |
691 |
|
|
699 | if hasattr(self,'tb'): | |
|
700 | etb = self.tb | |||
|
701 | else: | |||
|
702 | etb = self.tb = sys.last_traceback | |||
692 | while self.tb.tb_next is not None: |
|
703 | while self.tb.tb_next is not None: | |
693 | self.tb = self.tb.tb_next |
|
704 | self.tb = self.tb.tb_next | |
694 | try: |
|
705 | try: | |
@@ -696,12 +707,11 b' class VerboseTB(TBTools):' | |||||
696 | etb = etb.tb_next |
|
707 | etb = etb.tb_next | |
697 | self.pdb.botframe = etb.tb_frame |
|
708 | self.pdb.botframe = etb.tb_frame | |
698 | self.pdb.interaction(self.tb.tb_frame, self.tb) |
|
709 | self.pdb.interaction(self.tb.tb_frame, self.tb) | |
699 |
|
|
710 | finally: | |
700 | print '*** ERROR ***' |
|
711 | sys.displayhook = dhook | |
701 | print 'This version of pdb has a bug and crashed.' |
|
712 | ||
702 | print 'Returning to IPython...' |
|
713 | if hasattr(self,'tb'): | |
703 | sys.displayhook = dhook |
|
714 | del self.tb | |
704 | del self.tb |
|
|||
705 |
|
715 | |||
706 | def handler(self, info=None): |
|
716 | def handler(self, info=None): | |
707 | (etype, evalue, etb) = info or sys.exc_info() |
|
717 | (etype, evalue, etb) = info or sys.exc_info() |
@@ -1,4 +1,11 b'' | |||||
1 | 2006-11-2(8 Ville Vainio <vivainio@gmail.com> |
|
1 | 2006-11-29 Fernando Perez <Fernando.Perez@colorado.edu> | |
|
2 | ||||
|
3 | * IPython/Magic.py (magic_debug): new %debug magic to activate the | |||
|
4 | interactive debugger on the last traceback, without having to call | |||
|
5 | %pdb and rerun your code. Made minor changes in various modules, | |||
|
6 | should automatically recognize pydb if available. | |||
|
7 | ||||
|
8 | 2006-11-28 Ville Vainio <vivainio@gmail.com> | |||
2 |
|
9 | |||
3 | * completer.py: If the text start with !, show file completions |
|
10 | * completer.py: If the text start with !, show file completions | |
4 | properly. This helps when trying to complete command name |
|
11 | properly. This helps when trying to complete command name |
General Comments 0
You need to be logged in to leave comments.
Login now