I am trying to create a python library to distribute my proto definitions to users and want that the python stubs are generated at the time of library installation when they do pip install protolib
.
Following is a preview of my code structure:
Tree of: /root/protolib
.
|__src
| |__requirements.txt
| |__protos
| | |__helloworld.proto
| |__stubs
| |__setup.py
I want that python stubs are generated in the stubs
directory at the time of pip install
. I came across this post and was able to create a wheel but the stubs are getting generated at the time of wheel creation and are being written in the protos
directory in my source code repo. This is because the function command.build_package_protos()
in grpc_tools
package of the grpc
library use one same location for proto_path
, python_out
, and grpc_python_out
i.e. inclusion_root
. If changing the location for the generated stubs is not possible, then I think I am ready to move my .proto
files to the stubs
directory so that users are still able to import them from stubs
(as shown below as end goal). But I still want my source code repo free of generated stubs i.e. the stubs should be generated only at the time of pip install
.
The end goal is to enable the user to import stubs like:
from stubs import helloworld_pb2, helloworld_pb2_grpc