In Python, the gRPC project proto files are shipped in smaller packages. For example, I want to use status.proto, which is the grpc-status package.
The protoc compiler is provided as a Python module by the grpc-tools package.
# my.proto
syntax = "proto3";
import "google/rpc/status.proto";
Installing everything in a virtualenv:
python -m venv v
source v/bin/activate
pip install grpc-status grpc-tools
The compiler module doesn't automatically find and use the proto files installed by the grpc-status package.
python -m grpc_tools.protoc -I . my.proto
Results in:
google/rpc/status.proto: File not found.
(This file is available at v/lib/python3.11/site-packages/google/rpc/status.proto and was installed by googleapis-common-protos, a dependency of grpcio-status.)
This surprises me, because the proto files are distributed in separate packages, and the protoc compiler is itself a Python module, and so the entire arrangement for "provided" proto files seems easy and designed to be configured within Python by grpc_tools itself. It seems I must be doing something wrong.
Do I really need to explicitly tell the compiler module about Python's site-packages?
SITE_PROTO_FILES=$( python -c 'import site; print(site.getsitepackages()[0])' )
# This compiles.
python -m grpc_tools.protoc -I $SITE_PROTO_FILES -I . my.proto
I have searched the gRPC documentation, Google Group GitHub Issue tracker, and read python -m grpc_tools.protoc --help, but have not found anything useful about this.