protoc-gen-chattolib 996 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3
  2. """Standalone launcher for the chattolib protoc plugin.
  3. Loaded by file path (not via `import chattolib`) so running it never triggers
  4. ``chattolib/__init__.py`` — which eagerly imports the client and its generated
  5. stubs. That matters for bootstrap: this plugin *generates* those stubs, so it
  6. must run before they exist. ``protoc`` finds it on PATH and invokes it with
  7. ``--chattolib_out``.
  8. The plugin path is resolved from the launcher's *real* location (this file may
  9. be reached through a symlink), so it works from any PATH entry.
  10. """
  11. import importlib.util
  12. import os
  13. import sys
  14. _here = os.path.dirname(os.path.realpath(__file__)) # .../scripts
  15. _plugin = os.path.join(_here, os.pardir, "src", "chattolib", "_protoc_plugin.py")
  16. _plugin = os.path.abspath(_plugin)
  17. spec = importlib.util.spec_from_file_location("_chattolib_protoc_plugin", _plugin)
  18. mod = importlib.util.module_from_spec(spec)
  19. spec.loader.exec_module(mod) # type: ignore[union-attr]
  20. sys.exit(mod.main())