##// END OF EJS Templates
fix #1814 set __file__ when running [i]python files through interactiveshell
s8weber -
Show More
@@ -2419,9 +2419,9 b' class InteractiveShell(SingletonConfigurable):'
2419 dname = os.path.dirname(fname)
2419 dname = os.path.dirname(fname)
2420
2420
2421 with prepended_to_syspath(dname):
2421 with prepended_to_syspath(dname):
2422 # Ensure that __file__ is always defined to match Python behavior
2422 # Ensure that __file__ is always defined to match Python behavior
2423 save_fname = self.user_ns.get('__file__',None)
2423 save_fname = self.user_ns.get('__file__',None)
2424 self.user_ns['__file__'] = fname
2424 self.user_ns['__file__'] = fname
2425 try:
2425 try:
2426 py3compat.execfile(fname,*where)
2426 py3compat.execfile(fname,*where)
2427 except SystemExit, status:
2427 except SystemExit, status:
@@ -2470,9 +2470,9 b' class InteractiveShell(SingletonConfigurable):'
2470 dname = os.path.dirname(fname)
2470 dname = os.path.dirname(fname)
2471
2471
2472 with prepended_to_syspath(dname):
2472 with prepended_to_syspath(dname):
2473 # Ensure that __file__ is always defined to match Python behavior
2473 # Ensure that __file__ is always defined to match Python behavior
2474 save_fname = self.user_ns.get('__file__',None)
2474 save_fname = self.user_ns.get('__file__',None)
2475 self.user_ns['__file__'] = fname
2475 self.user_ns['__file__'] = fname
2476 try:
2476 try:
2477 with open(fname) as thefile:
2477 with open(fname) as thefile:
2478 # self.run_cell currently captures all exceptions
2478 # self.run_cell currently captures all exceptions
@@ -278,11 +278,11 b' class InteractiveShellApp(Configurable):'
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)
280 self.log.info("Running file in user namespace: %s" % full_filename)
281 if full_filename.endswith('.ipy'):
281 if full_filename.endswith('.ipy'):
282 self.shell.safe_execfile_ipy(full_filename)
282 self.shell.safe_execfile_ipy(full_filename)
283 else:
283 else:
284 # default to python, even without extension
284 # default to python, even without extension
285 self.shell.safe_execfile(full_filename, self.shell.user_ns)
285 self.shell.safe_execfile(full_filename, self.shell.user_ns)
286 finally:
286 finally:
287 sys.argv = save_argv
287 sys.argv = save_argv
288
288
General Comments 0
You need to be logged in to leave comments. Login now