-
Notifications
You must be signed in to change notification settings - Fork 7
Description
I’d like to use gnostic’s models in another Protobuf schema as annotations.
As part of that process, the generated Python bindings for my service need a dependency on generated Python bindings for gnostic models, even if they’re only used as annotations and never referenced at runtime by application code.
The build process for my own Protobuf modules generates _pb2.py files at build time, and then installs both .proto and _pb2.py files into Python’s site-packages directory using namespace packages, so the directory structure (as referenced by .proto imports) must match declared package names.
This lets you point protoc at Python’s site-packages, and everything that imports from such a .proto just works, ie:
protoc --proto-path lib/python3.X/site-packages/ --proto_path src/ src/my_package/example.protoThis layout is implemented by the googleapis-common-protos package (and likely others), and supported by hatch-protobuf’s build process1.
Unfortunately, gnostic-models package names don’t match file paths at all, so they’re not amenable to this usage:
-
openapiv2/should beopenapi/v2/:gnostic-models/openapiv2/OpenAPIv2.proto
Line 19 in fbe822a
package openapi.v2; -
openapiv3/should beopenapi/v3/:package openapi.v3; gnostic-models/openapiv3/OpenAPIv3.proto
Line 19 in fbe822a
package openapi.v3; -
extensions/should begnostic/extension/v1/:gnostic-models/extensions/extension.proto
Line 17 in fbe822a
package gnostic.extension.v1;
To fix this, you’d need to rename all these directories so they match the declared package names, and then update any references to those old paths.
Footnotes
-
In full disclosure, I added this feature to
hatch-protobuf. However, whengoogleapis-common-protosbroke this, people other than me complained about it too, so I don’t think I’m the first to do this. 😄 ↩