(error=ImportError)
| 229 | return _run_code(code, {}, init_globals, run_name, mod_spec) |
| 230 | |
| 231 | def _get_main_module_details(error=ImportError): |
| 232 | # Helper that gives a nicer error message when attempting to |
| 233 | # execute a zipfile or directory by invoking __main__.py |
| 234 | # Also moves the standard __main__ out of the way so that the |
| 235 | # preexisting __loader__ entry doesn't cause issues |
| 236 | main_name = "__main__" |
| 237 | saved_main = sys.modules[main_name] |
| 238 | del sys.modules[main_name] |
| 239 | try: |
| 240 | return _get_module_details(main_name) |
| 241 | except ImportError as exc: |
| 242 | if main_name in str(exc): |
| 243 | raise error("can't find %r module in %r" % |
| 244 | (main_name, sys.path[0])) from exc |
| 245 | raise |
| 246 | finally: |
| 247 | sys.modules[main_name] = saved_main |
| 248 | |
| 249 | |
| 250 | def _get_code_from_file(fname): |
no test coverage detected