danielgtaylor / danielgtaylor/python-betterproto

Add support for custom options

Aperta
#119 18 commenti 6 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.