Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Merge pull request #1831 from steverweber/fix_1814"

This reverts commit 2717feb, reversing
changes made to ea4f608.
  • Loading branch information...
commit 41feaae2b27783dd1ab1600f1ef474b107b95cdc 1 parent 1981689
@bfroehle authored
Showing with 10 additions and 12 deletions.
  1. +0 −10 IPython/core/interactiveshell.py
  2. +10 −2 IPython/core/shellapp.py
View
10 IPython/core/interactiveshell.py
@@ -2455,9 +2455,6 @@ def safe_execfile(self, fname, *where, **kw):
dname = os.path.dirname(fname)
with prepended_to_syspath(dname):
- # Ensure that __file__ is always defined to match Python behavior
- save_fname = self.user_ns.get('__file__',None)
- self.user_ns['__file__'] = fname
try:
py3compat.execfile(fname,*where)
except SystemExit as status:
@@ -2478,8 +2475,6 @@ def safe_execfile(self, fname, *where, **kw):
if kw['raise_exceptions']:
raise
self.showtraceback()
- finally:
- self.user_ns['__file__'] = save_fname
def safe_execfile_ipy(self, fname):
"""Like safe_execfile, but for .ipy files with IPython syntax.
@@ -2506,9 +2501,6 @@ def safe_execfile_ipy(self, fname):
dname = os.path.dirname(fname)
with prepended_to_syspath(dname):
- # Ensure that __file__ is always defined to match Python behavior
- save_fname = self.user_ns.get('__file__',None)
- self.user_ns['__file__'] = fname
try:
with open(fname) as thefile:
# self.run_cell currently captures all exceptions
@@ -2519,8 +2511,6 @@ def safe_execfile_ipy(self, fname):
except:
self.showtraceback()
warn('Unknown failure executing file: <%s>' % fname)
- finally:
- self.user_ns['__file__'] = save_fname
def safe_run_module(self, mod_name, where):
"""A safe version of runpy.run_module().
View
12 IPython/core/shellapp.py
@@ -277,12 +277,20 @@ def _exec_file(self, fname):
sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
try:
if os.path.isfile(full_filename):
- self.log.info("Running file in user namespace: %s" % full_filename)
if full_filename.endswith('.ipy'):
+ self.log.info("Running file in user namespace: %s" %
+ full_filename)
self.shell.safe_execfile_ipy(full_filename)
else:
# default to python, even without extension
- self.shell.safe_execfile(full_filename, self.shell.user_ns)
+ self.log.info("Running file in user namespace: %s" %
+ full_filename)
+ # Ensure that __file__ is always defined to match Python behavior
+ self.shell.user_ns['__file__'] = fname
+ try:
+ self.shell.safe_execfile(full_filename, self.shell.user_ns)
+ finally:
+ del self.shell.user_ns['__file__']
finally:
sys.argv = save_argv
Please sign in to comment.
Something went wrong with that request. Please try again.