cosmopolitan/third_party/python/Lib/launchpy.py
Justine Tunney b5f743cdc3 Begin incorporating Python unit tests into build
We now build a separate APE binary for each test so they can run in
parallel. We've got 148 tests running fast and stable so far.
2021-09-12 21:04:44 -07:00

15 lines
506 B
Python

import sys
from importlib import _bootstrap_external
def run_module_as_main(mod_name):
path = "/zip/.python/%s.pyc" % (mod_name.replace(".", "/"))
loader = _bootstrap_external.SourcelessFileLoader(mod_name, path)
code = loader.get_code(mod_name)
globs = sys.modules["__main__"].__dict__
globs["__name__"] = "__main__"
globs["__file__"] = path[:-1]
globs["__package__"] = None
globs["__loader__"] = loader
globs["__spec__"] = None
exec(code, globs)
return globs