danielgtaylor / danielgtaylor/python-betterproto
Add support for custom options
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
Custom options are a vanilla proto feature documented [here](https://developers.google.com/protocol-buffers/docs/proto#customoptions). I personally have a use case for them to apply constraints, similar to [protoc-gen-validate](https://github.com/envoyproxy/protoc-gen-validate). I think supporting generic custom options would be a great addition to python-betterproto.
In order for this to happen, I see a couple changes that would be needed:
1. The options proto needs to be compiled by protoc and imported into the namespace from which `CodeGeneratorRequest. ParseFromString` is called. This req is documented in protocolbuffers/protobuf#3321.
2. `plugin.py` needs the ability to parse the custom options and somehow store them.
3. We'd need to figure out how to _use_ the custom options: Python has no concept of applying "options" (aside from comments). There are many mechanisms that could be employed (getters/setters, pydantic, comments, etc.). My feeling is that to cover all use cases, `plugin.py` would need to be made extendable so that individual implementations can decide how to parse custom options and how to use them in the generation of the output `.py` files.
Is there any interest in this? I'd be willing to try and work on something.
Contributor guide
Assessment
This issue has not been assessed yet.