()
| 362 | |
| 363 | |
| 364 | def run_module(): |
| 365 | # Add current directory to path, like Python itself does for -m. This must |
| 366 | # be in place before trying to use find_spec below to resolve submodules. |
| 367 | sys.path.insert(0, str("")) |
| 368 | |
| 369 | # We want to do the same thing that run_module() would do here, without |
| 370 | # actually invoking it. |
| 371 | argv_0 = sys.argv[0] |
| 372 | try: |
| 373 | spec = None if options.target is None else find_spec(options.target) |
| 374 | if spec is not None: |
| 375 | argv_0 = spec.origin |
| 376 | except Exception: |
| 377 | log.swallow_exception("Error determining module path for sys.argv") |
| 378 | |
| 379 | start_debugging(argv_0) |
| 380 | log.describe_environment("Pre-launch environment:") |
| 381 | log.info("Running module {0!r}", options.target) |
| 382 | |
| 383 | # Docs say that runpy.run_module is equivalent to -m, but it's not actually |
| 384 | # the case for packages - -m sets __name__ to "__main__", but run_module sets |
| 385 | # it to "pkg.__main__". This breaks everything that uses the standard pattern |
| 386 | # __name__ == "__main__" to detect being run as a CLI app. On the other hand, |
| 387 | # runpy._run_module_as_main is a private function that actually implements -m. |
| 388 | try: |
| 389 | run_module_as_main = runpy._run_module_as_main |
| 390 | except AttributeError: |
| 391 | log.warning("runpy._run_module_as_main is missing, falling back to run_module.") |
| 392 | runpy.run_module(options.target, alter_sys=True) |
| 393 | else: |
| 394 | run_module_as_main(options.target, alter_argv=True) |
| 395 | |
| 396 | |
| 397 | def run_code(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…