(self, fname, shell_futures=False)
| 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""" |
no test coverage detected