Protocol Buffer Definitions in Packages

For my future reference, and for anyone who happens to hit this as they start into protocol buffering where you want to have the protocol definitions as part of your packages.

The protocol buffer compiler uses relative path names from the directory you specify with '-I' to the directory where the .proto files are to guess the package names for the resulting files. So if your CI does a chdir to your .protos directory you will wind up with all of the rpc/pb2 modules as top-level modules.

What you likely want to do is to run the proto compiler such that the -I directory is '.' (the directory) and the output directories (--python_out and --python_grpc_out) are *also* '.' then reference 'yourpackage/protos/yourproto.proto' in your imports and in the compilation call so that the resulting files will import their cross-references from yourpackage.protos' rather than the global namespace.


Comments are closed.


Pingbacks are closed.