##// END OF EJS Templates
Revert "Merge pull request #1831 from steverweber/fix_1814"...
Bradley M. Froehle -
Show More
@@ -2455,9 +2455,6 b' class InteractiveShell(SingletonConfigurable):'
2455 dname = os.path.dirname(fname)
2455 dname = os.path.dirname(fname)
2456
2456
2457 with prepended_to_syspath(dname):
2457 with prepended_to_syspath(dname):
2458 # Ensure that __file__ is always defined to match Python behavior
2459 save_fname = self.user_ns.get('__file__',None)
2460 self.user_ns['__file__'] = fname
2461 try:
2458 try:
2462 py3compat.execfile(fname,*where)
2459 py3compat.execfile(fname,*where)
2463 except SystemExit as status:
2460 except SystemExit as status:
@@ -2478,8 +2475,6 b' class InteractiveShell(SingletonConfigurable):'
2478 if kw['raise_exceptions']:
2475 if kw['raise_exceptions']:
2479 raise
2476 raise
2480 self.showtraceback()
2477 self.showtraceback()
2481 finally:
2482 self.user_ns['__file__'] = save_fname
2483
2478
2484 def safe_execfile_ipy(self, fname):
2479 def safe_execfile_ipy(self, fname):
2485 """Like safe_execfile, but for .ipy files with IPython syntax.
2480 """Like safe_execfile, but for .ipy files with IPython syntax.
@@ -2506,9 +2501,6 b' class InteractiveShell(SingletonConfigurable):'
2506 dname = os.path.dirname(fname)
2501 dname = os.path.dirname(fname)
2507
2502
2508 with prepended_to_syspath(dname):
2503 with prepended_to_syspath(dname):
2509 # Ensure that __file__ is always defined to match Python behavior
2510 save_fname = self.user_ns.get('__file__',None)
2511 self.user_ns['__file__'] = fname
2512 try:
2504 try:
2513 with open(fname) as thefile:
2505 with open(fname) as thefile:
2514 # self.run_cell currently captures all exceptions
2506 # self.run_cell currently captures all exceptions
@@ -2519,8 +2511,6 b' class InteractiveShell(SingletonConfigurable):'
2519 except:
2511 except:
2520 self.showtraceback()
2512 self.showtraceback()
2521 warn('Unknown failure executing file: <%s>' % fname)
2513 warn('Unknown failure executing file: <%s>' % fname)
2522 finally:
2523 self.user_ns['__file__'] = save_fname
2524
2514
2525 def safe_run_module(self, mod_name, where):
2515 def safe_run_module(self, mod_name, where):
2526 """A safe version of runpy.run_module().
2516 """A safe version of runpy.run_module().
@@ -277,12 +277,20 b' class InteractiveShellApp(Configurable):'
277 sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
277 sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
278 try:
278 try:
279 if os.path.isfile(full_filename):
279 if os.path.isfile(full_filename):
280 self.log.info("Running file in user namespace: %s" % full_filename)
281 if full_filename.endswith('.ipy'):
280 if full_filename.endswith('.ipy'):
281 self.log.info("Running file in user namespace: %s" %
282 full_filename)
282 self.shell.safe_execfile_ipy(full_filename)
283 self.shell.safe_execfile_ipy(full_filename)
283 else:
284 else:
284 # default to python, even without extension
285 # default to python, even without extension
285 self.shell.safe_execfile(full_filename, self.shell.user_ns)
286 self.log.info("Running file in user namespace: %s" %
287 full_filename)
288 # Ensure that __file__ is always defined to match Python behavior
289 self.shell.user_ns['__file__'] = fname
290 try:
291 self.shell.safe_execfile(full_filename, self.shell.user_ns)
292 finally:
293 del self.shell.user_ns['__file__']
286 finally:
294 finally:
287 sys.argv = save_argv
295 sys.argv = save_argv
288
296
General Comments 0
You need to be logged in to leave comments. Login now