##// END OF EJS Templates
Support relative import in "%run -d -m"
Takafumi Arakaki -
Show More
@@ -543,25 +543,27 b' python-profiler package from non-free.""")'
543 # every single object ever created.
543 # every single object ever created.
544 sys.modules[main_mod_name] = main_mod
544 sys.modules[main_mod_name] = main_mod
545
545
546 if 'p' in opts or 'd' in opts:
547 if 'm' in opts:
548 code = 'run_module(modulename, prog_ns)'
549 code_ns = {
550 'run_module': self.shell.safe_run_module,
551 'prog_ns': prog_ns,
552 'modulename': modulename,
553 }
554 else:
555 code = 'execfile(filename, prog_ns)'
556 code_ns = {
557 'execfile': self.shell.safe_execfile,
558 'prog_ns': prog_ns,
559 'filename': get_py_filename(filename),
560 }
561
546 try:
562 try:
547 stats = None
563 stats = None
548 with self.shell.readline_no_record:
564 with self.shell.readline_no_record:
549 if 'p' in opts:
565 if 'p' in opts:
550 if 'm' in opts:
566 stats = self.prun('', code, False, opts, namespace=code_ns)
551 code = 'run_module(modulename, prog_ns)'
552 prun_ns = {
553 'run_module': self.shell.safe_run_module,
554 'prog_ns': prog_ns,
555 'modulename': modulename,
556 }
557 else:
558 code = 'execfile(filename, prog_ns)'
559 prun_ns = {
560 'execfile': self.shell.safe_execfile,
561 'prog_ns': prog_ns,
562 'filename': get_py_filename(filename),
563 }
564 stats = self.prun('', code, False, opts, namespace=prun_ns)
565 else:
567 else:
566 if 'd' in opts:
568 if 'd' in opts:
567 deb = debugger.Pdb(self.shell.colors)
569 deb = debugger.Pdb(self.shell.colors)
@@ -596,11 +598,10 b' python-profiler package from non-free.""")'
596 # Start file run
598 # Start file run
597 print "NOTE: Enter 'c' at the",
599 print "NOTE: Enter 'c' at the",
598 print "%s prompt to start your script." % deb.prompt
600 print "%s prompt to start your script." % deb.prompt
599 ns = {'execfile': py3compat.execfile, 'prog_ns': prog_ns}
600 try:
601 try:
601 #save filename so it can be used by methods on the deb object
602 #save filename so it can be used by methods on the deb object
602 deb._exec_filename = filename
603 deb._exec_filename = filename
603 deb.run('execfile("%s", prog_ns)' % filename, ns)
604 deb.run(code, code_ns)
604
605
605 except:
606 except:
606 etype, value, tb = sys.exc_info()
607 etype, value, tb = sys.exc_info()
General Comments 0
You need to be logged in to leave comments. Login now