Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor part for "%run -d"

  • Loading branch information...
commit 2975de6aff4d44b86327d14af995f2733bedf9d8 1 parent 984279a
@tkf tkf authored
Showing with 47 additions and 43 deletions.
  1. +47 −43 IPython/core/magics/execution.py
View
90 IPython/core/magics/execution.py
@@ -566,49 +566,8 @@ def run(self, parameter_s='', runner=None,
stats = self.prun('', code, False, opts, namespace=code_ns)
else:
if 'd' in opts:
- deb = debugger.Pdb(self.shell.colors)
- # reset Breakpoint state, which is moronically kept
- # in a class
- bdb.Breakpoint.next = 1
- bdb.Breakpoint.bplist = {}
- bdb.Breakpoint.bpbynumber = [None]
- # Set an initial breakpoint to stop execution
- maxtries = 10
- bp_file, bp_line = parse_breakpoint(opts.get('b', ['1'])[0], filename)
- checkline = deb.checkline(bp_file, bp_line)
- if not checkline:
- for bp in range(bp_line + 1, bp_line + maxtries + 1):
- if deb.checkline(bp_file, bp):
- break
- else:
- msg = ("\nI failed to find a valid line to set "
- "a breakpoint\n"
- "after trying up to line: %s.\n"
- "Please set a valid breakpoint manually "
- "with the -b option." % bp)
- error(msg)
- return
- # if we find a good linenumber, set the breakpoint
- deb.do_break('%s:%s' % (bp_file, bp_line))
-
- # Mimic Pdb._runscript(...)
- deb._wait_for_mainpyfile = True
- deb.mainpyfile = deb.canonic(filename)
-
- # Start file run
- print "NOTE: Enter 'c' at the",
- print "%s prompt to start your script." % deb.prompt
- try:
- #save filename so it can be used by methods on the deb object
- deb._exec_filename = filename
- deb.run(code, code_ns)
-
- except:
- etype, value, tb = sys.exc_info()
- # Skip three frames in the traceback: the %run one,
- # one inside bdb.py, and the command-line typed by the
- # user (run by exec in pdb itself).
- self.shell.InteractiveTB(etype, value, tb, tb_offset=3)
+ self._run_with_debugger(
+ code, code_ns, opts.get('b', ['1'])[0], filename)
else:
if 'm' in opts:
def run():
@@ -676,6 +635,51 @@ def run():
return stats
+ def _run_with_debugger(self, code, code_ns, break_point, filename):
+ deb = debugger.Pdb(self.shell.colors)
+ # reset Breakpoint state, which is moronically kept
+ # in a class
+ bdb.Breakpoint.next = 1
+ bdb.Breakpoint.bplist = {}
+ bdb.Breakpoint.bpbynumber = [None]
+ # Set an initial breakpoint to stop execution
+ maxtries = 10
+ bp_file, bp_line = parse_breakpoint(break_point, filename)
+ checkline = deb.checkline(bp_file, bp_line)
+ if not checkline:
+ for bp in range(bp_line + 1, bp_line + maxtries + 1):
+ if deb.checkline(bp_file, bp):
+ break
+ else:
+ msg = ("\nI failed to find a valid line to set "
+ "a breakpoint\n"
+ "after trying up to line: %s.\n"
+ "Please set a valid breakpoint manually "
+ "with the -b option." % bp)
+ error(msg)
+ return
+ # if we find a good linenumber, set the breakpoint
+ deb.do_break('%s:%s' % (bp_file, bp_line))
+
+ # Mimic Pdb._runscript(...)
+ deb._wait_for_mainpyfile = True
+ deb.mainpyfile = deb.canonic(filename)
+
+ # Start file run
+ print "NOTE: Enter 'c' at the",
+ print "%s prompt to start your script." % deb.prompt
+ try:
+ #save filename so it can be used by methods on the deb object
+ deb._exec_filename = filename
+ deb.run(code, code_ns)
+
+ except:
+ etype, value, tb = sys.exc_info()
+ # Skip three frames in the traceback: the %run one,
+ # one inside bdb.py, and the command-line typed by the
+ # user (run by exec in pdb itself).
+ self.shell.InteractiveTB(etype, value, tb, tb_offset=3)
+
@staticmethod
def _run_with_timing(run, nruns):
twall0 = time.time()
Please sign in to comment.
Something went wrong with that request. Please try again.