Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update buf plugin with latest v2 beta #608

Open
zbstof opened this issue Sep 5, 2024 · 3 comments
Open

Update buf plugin with latest v2 beta #608

zbstof opened this issue Sep 5, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@zbstof
Copy link

zbstof commented Sep 5, 2024

Summary

Buf uses 1.2.5 of betterproto package, which cannot process optional keywords

What is the feature request for?

The core library

The Problem

In our company we have a standard to use buf to generate bindings to proto files.
And we wanted to use betterproto plugin to generate idiomatic python code.
Unfortunately, the only version of the plugin (v1.2.5) doesn't support some "newer" protobuf features, like "optional" keyword.
This was fixed in v.2.0.0b4, but this release is not available in buf.

The Ideal Solution

Can I ask to release latest beta (v.2.0.0b7 as the time of writing) as another version of community plugin?
https://github.com/danielgtaylor/python-betterproto/milestone/4 does not seem to be forthcoming.
Thanks

The Current Solution

Rely on official buf python plugin
https://buf.build/protocolbuffers/python?version=v28.0

@zbstof zbstof added the enhancement New feature or request label Sep 5, 2024
@JitPackJoyride
Copy link
Contributor

Hey, to get around this, I did an extra step on top of buf.gen.yaml with a poetry dependency that looked like this:

betterproto = {extras = ["compiler"], version = "^2.0.0b7", allow-prereleases = true}

You're likely also going to need grpcio and grpcio-tools installed.

Then, in my custom generate script, I did this:

  # Find all .proto files
  proto_files=$(find /schemas/proto -name "*.proto")

  # Special case for Python to use betterproto so that we can use Pydantic Dataclasses
  python3 -m grpc_tools.protoc \
      -I /schemas/proto \
      --python_betterproto_out=/schemas/output/python/proto/ \
      --python_betterproto_opt=pydantic_dataclasses,typing.310 \
      $proto_files

Hope that helps!

@zbstof
Copy link
Author

zbstof commented Sep 11, 2024

Thank you @JitPackJoyride.
I do have similar workaround at hand. But if we are willing to call raw protoc, I don't see why we need buf at all

@alikleit
Copy link

any take on this? Will Buf include pre-released commits? or make any exception on libraries like betterproto for beta releases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants