-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support adding a pb2_module_prefix on protoc plugin #196
base: master
Are you sure you want to change the base?
Support adding a pb2_module_prefix on protoc plugin #196
Conversation
Prefix path is not something that Google's Such customisations can be done in |
Update: Re-read your response and rewrote my response |
The distinction is important because, as noted in the
That means if we use For instance, if a.proto imports b.proto in the same directory:
This shows that |
I wonder how I found some hacks in rules_proto_grpc project but I was unable to find how they implemented these import prefixes for messages and grpcio stubs. In your example if you don't want to change imports in proto files then If |
I've put up a reproduction in https://github.com/chrisirhc/protobuf-import-prefix-repro . It seems that the use case I'm looking for is not supported by protoc itself. The protoc compiler will always treat imports in the
The goal is to add an import prefix so that there's no namespace collisions in the absolute import. Hence, the behavior. However, it does seem like the behavior I'm looking for is not supported on protoc itself and hence it requires every plugin to add this feature if it needs to be supported, like here. This is unfortunate, since that means that every proto file that has imports needs to be aware of what directory structure (or what import prefix) it will be finally used in. For example, vendoring groups of proto files requires all imports to be rewritten in them. |
This allows for usage with rules_proto_grpc with prefix_path.
prefix_path
on therules_proto_grpc
'spython_grpclib_library
prefixes the generated files. However, the generated_grpc
files can't find it because it's looking in the original proto path's module path instead of the prefix path.Example usage from
python_grpclib_library
:The
options
get passed to the plugin asrequest.parameter
, comma-separated.Usage from protoc plugin:
I didn't find any tests for plugin.py , and don't have a good sense of how I'd go about adding a test or documentation about this.
Right now, this PR is a bit weird in that it uses the
=
character twice in the arguments. Happy to change it if anyone else has other suggestions for a better character to use or another parsing method.