Skip to content

.proto files are in directories that don’t match their package name #18

@micolous

Description

@micolous

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:

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

  1. In full disclosure, I added this feature to hatch-protobuf. However, when googleapis-common-protos broke this, people other than me complained about it too, so I don’t think I’m the first to do this. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions