danielgtaylor / danielgtaylor/python-betterproto

Add support for custom options

Offen
#119 18 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit plugin.py und dem Laden der options proto rund um CodeGeneratorRequest.ParseFromString, und lies dann die verlinkte Dokumentation zu custom-options sowie das protobuf issue. Ermittle, wie Optionen für die generierte Python-Ausgabe geparst, gespeichert und bereitgestellt werden sollten; die Arbeit ist abgeschlossen, wenn ein dokumentierter, nutzbarer generischer Mechanismus implementiert und durch Tests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers, tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.