Skip to content
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

Feature: "M" module mapping option #160

Open
pcj opened this issue Jul 20, 2022 · 1 comment
Open

Feature: "M" module mapping option #160

pcj opened this issue Jul 20, 2022 · 1 comment

Comments

@pcj
Copy link

pcj commented Jul 20, 2022

The plugin maps proto filenames to python module names in a predicable manner according to _type_names and other functions. This results in import statements like:

from google.protobuf.descriptor_pb2 import FileDescriptorProto, DescriptorProto

In our case as an artifact of the build system (bazel), the well-known types (and some other types) have alternate desired module name mappings. The desired import would be something like:

from protobufapis.google.protobuf.descriptor_pb2 import FileDescriptorProto, DescriptorProto

I would suggest a "mapping" option that allows the end-user to do such a mapping. Other protoc plugins have the same requirement. For protoc-gen-go, for example, has the M option.

For example:

--grpclib_opt=M=google/protobuf/duration.proto=protobufapis.google.protobuf.duration

Would parse the option, do a lookup in the type map, and produce the output:

from protobufapis.google.protobuf.descriptor_pb2 import FileDescriptorProto, DescriptorProto

Happy to create a PR to implement it, and thanks for the great plugin!

@vmagamedov
Copy link
Owner

It would be great to have this option. Looking forward to review and merge your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants