Skip to content

Commit

Permalink
Revert "Merge pull request #1831 from steverweber/fix_1814"
Browse files Browse the repository at this point in the history
This reverts commit 2717feb, reversing
changes made to ea4f608.
  • Loading branch information
bfroehle committed Sep 26, 2012
1 parent 1981689 commit 41feaae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 0 additions & 10 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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().
Expand Down
12 changes: 10 additions & 2 deletions IPython/core/shellapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 41feaae

Please sign in to comment.