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.proto
This 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 be openapi/v2/:
-
openapiv3/ should be openapi/v3/:
-
extensions/ should be gnostic/extension/v1/:
|
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.
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
gnosticmodels, 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.pyfiles at build time, and then installs both.protoand_pb2.pyfiles into Python’ssite-packagesdirectory using namespace packages, so the directory structure (as referenced by.protoimports) must match declared package names.This lets you point
protocat Python’ssite-packages, and everything that imports from such a.protojust works, ie:This layout is implemented by the
googleapis-common-protospackage (and likely others), and supported byhatch-protobuf’s build process1.Unfortunately,
gnostic-modelspackage 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
openapiv3/should beopenapi/v3/:gnostic-models/openapiv3/annotations.proto
Line 17 in fbe822a
gnostic-models/openapiv3/OpenAPIv3.proto
Line 19 in fbe822a
extensions/should begnostic/extension/v1/:gnostic-models/extensions/extension.proto
Line 17 in fbe822a
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. 😄 ↩