MCPcopy Index your code
hub / github.com/ipython/ipython / _exec_file

Method _exec_file

IPython/core/shellapp.py:385–413  ·  view source on GitHub ↗
(self, fname, shell_futures=False)

Source from the content-addressed store, hash-verified

383 self.shell.showtraceback()
384
385 def _exec_file(self, fname, shell_futures=False):
386 try:
387 full_filename = filefind(fname, [u'.', self.ipython_dir])
388 except IOError:
389 self.log.warning("File not found: %r"%fname)
390 return
391 # Make sure that the running script gets a proper sys.argv as if it
392 # were run from a system shell.
393 save_argv = sys.argv
394 sys.argv = [full_filename] + self.extra_args[1:]
395 try:
396 if os.path.isfile(full_filename):
397 self.log.info("Running file in user namespace: %s" %
398 full_filename)
399 # Ensure that __file__ is always defined to match Python
400 # behavior.
401 with preserve_keys(self.shell.user_ns, '__file__'):
402 self.shell.user_ns['__file__'] = fname
403 if full_filename.endswith('.ipy') or full_filename.endswith('.ipynb'):
404 self.shell.safe_execfile_ipy(full_filename,
405 shell_futures=shell_futures)
406 else:
407 # default to python, even without extension
408 self.shell.safe_execfile(full_filename,
409 self.shell.user_ns,
410 shell_futures=shell_futures,
411 raise_exceptions=True)
412 finally:
413 sys.argv = save_argv
414
415 def _run_startup_files(self):
416 """Run files from profile startup directory"""

Callers 3

_run_startup_filesMethod · 0.95
_run_exec_filesMethod · 0.95
_run_cmd_line_codeMethod · 0.95

Calls 5

filefindFunction · 0.90
preserve_keysClass · 0.90
infoMethod · 0.80
safe_execfile_ipyMethod · 0.80
safe_execfileMethod · 0.80

Tested by

no test coverage detected