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