Permalink
Browse files

don't require .py extension in %run or command-line

There was an artificial requirement that files must have a '.py'
extension to be run. This didn't seem to have any reason, and removing
it changed no behavior.  extensionless files are interpreted
as pure-Python.
  • Loading branch information...
1 parent 3207b26 commit 3c385ef85d8c176085d437635157cbe858554a3e @minrk minrk committed Jul 7, 2011
Showing with 6 additions and 15 deletions.
  1. +0 −7 IPython/core/interactiveshell.py
  2. +6 −8 IPython/core/shellapp.py
@@ -2152,9 +2152,6 @@ def safe_execfile(self, fname, *where, **kw):
kw.setdefault('exit_ignore', False)
fname = os.path.abspath(os.path.expanduser(fname))
- # Make sure we have a .py file
- if not fname.endswith('.py'):
- warn('File must end with .py to be run using execfile: <%s>' % fname)
# Make sure we can open the file
try:
@@ -2203,10 +2200,6 @@ def safe_execfile_ipy(self, fname):
"""
fname = os.path.abspath(os.path.expanduser(fname))
- # Make sure we have a .py file
- if not fname.endswith('.ipy'):
- warn('File must end with .py to be run using execfile: <%s>' % fname)
-
# Make sure we can open the file
try:
with open(fname) as thefile:
@@ -189,7 +189,12 @@ def _run_exec_lines(self):
def _exec_file(self, fname):
full_filename = filefind(fname, [u'.', self.ipython_dir])
if os.path.isfile(full_filename):
- if full_filename.endswith(u'.py'):
+ 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.log.info("Running file in user namespace: %s" %
full_filename)
# Ensure that __file__ is always defined to match Python behavior
@@ -198,13 +203,6 @@ def _exec_file(self, fname):
self.shell.safe_execfile(full_filename, self.shell.user_ns)
finally:
del self.shell.user_ns['__file__']
- elif full_filename.endswith('.ipy'):
- self.log.info("Running file in user namespace: %s" %
- full_filename)
- self.shell.safe_execfile_ipy(full_filename)
- else:
- self.log.warn("File does not have a .py or .ipy extension: <%s>"
- % full_filename)
def _run_exec_files(self):
"""Run files from IPythonApp.exec_files"""

0 comments on commit 3c385ef

Please sign in to comment.