MCPcopy Index your code
hub / github.com/ipython/ipython / rerun

Method rerun

IPython/core/magics/history.py:311–361  ·  view source on GitHub ↗

Re-run previous input By default, you can specify ranges of input history to be repeated (as with %history). With no arguments, it will repeat the last line. Options: -l : Repeat the last n lines of input, not including the current command.

(self, parameter_s='')

Source from the content-addressed store, hash-verified

309
310 @line_magic
311 def rerun(self, parameter_s=''):
312 """Re-run previous input
313
314 By default, you can specify ranges of input history to be repeated
315 (as with %history). With no arguments, it will repeat the last line.
316
317 Options:
318
319 -l <n> : Repeat the last n lines of input, not including the
320 current command.
321
322 -g foo : Repeat the most recent line which contains foo
323 """
324 opts, args = self.parse_options(parameter_s, 'l:g:', mode='string')
325 if "l" in opts: # Last n lines
326 try:
327 n = int(opts["l"])
328 except ValueError:
329 print("Number of lines must be an integer")
330 return
331
332 if n == 0:
333 print("Requested 0 last lines - nothing to run")
334 return
335 elif n < 0:
336 print("Number of lines to rerun cannot be negative")
337 return
338
339 hist = self.shell.history_manager.get_tail(n)
340 elif "g" in opts: # Search
341 p = "*"+opts['g']+"*"
342 hist = list(self.shell.history_manager.search(p))
343 for l in reversed(hist):
344 if "rerun" not in l[2]:
345 hist = [l] # The last match which isn't a %rerun
346 break
347 else:
348 hist = [] # No matches except %rerun
349 elif args: # Specify history ranges
350 hist = self.shell.history_manager.get_range_by_str(args)
351 else: # Last line
352 hist = self.shell.history_manager.get_tail(1)
353 hist = [x[2] for x in hist]
354 if not hist:
355 print("No lines in history match specification")
356 return
357 histlines = "\n".join(hist)
358 print("=== Executing: ===")
359 print(histlines)
360 print("=== Output: ===")
361 self.shell.run_cell("\n".join(hist), store_history=False)

Callers

nothing calls this directly

Calls 5

parse_optionsMethod · 0.80
get_tailMethod · 0.45
searchMethod · 0.45
get_range_by_strMethod · 0.45
run_cellMethod · 0.45

Tested by

no test coverage detected