MCPcopy Create free account
hub / github.com/ipython/ipython / _exec_file

Method _exec_file

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

Source from the content-addressed store, hash-verified

324 self.shell.showtraceback()
325
326 def _exec_file(self, fname, shell_futures=False):
327 try:
328 full_filename = filefind(fname, [u'.', self.ipython_dir])
329 except IOError:
330 self.log.warning("File not found: %r"%fname)
331 return
332 # Make sure that the running script gets a proper sys.argv as if it
333 # were run from a system shell.
334 save_argv = sys.argv
335 sys.argv = [full_filename] + self.extra_args[1:]
336 try:
337 if os.path.isfile(full_filename):
338 self.log.info("Running file in user namespace: %s" %
339 full_filename)
340 # Ensure that __file__ is always defined to match Python
341 # behavior.
342 with preserve_keys(self.shell.user_ns, '__file__'):
343 self.shell.user_ns['__file__'] = fname
344 if full_filename.endswith('.ipy') or full_filename.endswith('.ipynb'):
345 self.shell.safe_execfile_ipy(full_filename,
346 shell_futures=shell_futures)
347 else:
348 # default to python, even without extension
349 self.shell.safe_execfile(full_filename,
350 self.shell.user_ns,
351 shell_futures=shell_futures,
352 raise_exceptions=True)
353 finally:
354 sys.argv = save_argv
355
356 def _run_startup_files(self):
357 """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