entry_points.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import sys
  2. import __res
  3. def repl():
  4. user_ns = {}
  5. py_main = __res.find("PY_MAIN")
  6. if py_main:
  7. mod_name, func_name = (py_main.split(b":", 1) + [None])[:2]
  8. try:
  9. import importlib
  10. mod = importlib.import_module(mod_name.decode("UTF-8"))
  11. user_ns = mod.__dict__
  12. except ModuleNotFoundError:
  13. import traceback
  14. traceback.print_exc()
  15. if func_name and "__main__" not in user_ns:
  16. def run(args):
  17. if isinstance(args, str):
  18. import shlex
  19. args = shlex.split(args)
  20. import sys
  21. sys.argv = [sys.argv[0]] + args
  22. getattr(mod, func_name)()
  23. user_ns["__main__"] = run
  24. try:
  25. import IPython
  26. except ModuleNotFoundError:
  27. pass
  28. else:
  29. return IPython.start_ipython(user_ns=user_ns)
  30. import code
  31. code.interact(local=user_ns)
  32. def resource_files():
  33. sys.stdout.buffer.write(b"\n".join(sorted(__res.resfs_files()) + [b""]))
  34. def run_constructors():
  35. for key, module_name in __res.iter_keys(b"py/constructors/"):
  36. import importlib
  37. module = importlib.import_module(module_name.decode())
  38. init_func = getattr(module, __res.find(key).decode())
  39. init_func()