protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Support pyi_out in py_proto_library

Open micahjsmith opened this issue 3 years ago • 7 comments

Recently, the --pyi_out flag was added to protoc, which is really great. I have a project where protos are compiled using bazel/py_proto_library. From everything that I have seen, there is no ability to additionally generate the .pyi files using this mode.

  • is it currently possible to generate .pyi files using py_proto_library? if so, how?
  • if not, what would be a path to add this support? I'm happy to make a PR (with maybe a few pointers)

thanks!

micahjsmith avatar Aug 05 '22 13:08 micahjsmith

You may need to contact bazel and ask them how to do that.

From our side, both --pyi_out and --python_out=pyi_out work

anandolee avatar Aug 19 '22 21:08 anandolee

py_proto_library was owned by protobuf repo, though I see it has been very recently deprecated from protobuf.bzl and will be available in bazel 5.3. After learning more about this, I have confirmed that it does not support pyi_out (it only supports python_out). If I have time to re-raise with bazel, I will xref back here.

micahjsmith avatar Sep 07 '22 21:09 micahjsmith

I actually can't find any indication of py_proto_library being moved to bazel, rules_proto, or anything similar. can someone please point me to leads on the future of py_proto_library? thanks!

micahjsmith avatar Sep 09 '22 15:09 micahjsmith

rule_python just closed my FR for the same thing (https://github.com/bazelbuild/rules_python/issues/1293) by saying that py_proto_library is fully owned by protobuf now. Can we have a reconsideration?

bluec0re avatar Jun 05 '24 11:06 bluec0re

Yes, please. Can this issue be re-opened?

psalaberria002 avatar Jun 07 '24 17:06 psalaberria002

I created a small test which uses patches to add a new rule pyi_proto_library: https://github.com/bluec0re/bazel-protobuf-pyi-test

It works, but is obviously very brittle and also not very thought out (merely a proof of concept by c&p most code). Official support would be nice.

bluec0re avatar Jun 19 '24 08:06 bluec0re

Will add pytype_proto_library

anandolee avatar Jun 21 '24 04:06 anandolee

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.

github-actions[bot] avatar Sep 19 '24 10:09 github-actions[bot]

Still in the need for this. So would appreciate to keep this FR open.

bluec0re avatar Sep 19 '24 19:09 bluec0re

@anandolee did you have time to look into this?

psalaberria002 avatar Sep 25 '24 07:09 psalaberria002

ping to prevent next inactive tag

ramilmsh avatar Nov 29 '24 16:11 ramilmsh

In case helpful, looks like rules_proto_grpc is planning to add pyi support in their next release.

Edit: I was able to successfully generate pyi files before their next release and included a comment in that thread.

harrisonfang-helm avatar Feb 18 '25 00:02 harrisonfang-helm

Note that the py_proto_library included in gRPC supports generating .pyi files: https://github.com/grpc/grpc/blob/v1.71.0/bazel/python_rules.bzl#L74

dws avatar May 02 '25 05:05 dws

@anandolee Perhaps I could get you to approve my PR for running CI? These changes worked for me when I experimented with using the py_proto_library from protobuf instead of the one from gRPC. I did my experiment with protobuf 29.4, but the changes cherry-pick cleanly to the main branch.

dws avatar May 02 '25 13:05 dws

+1 This has been very needed for more than 2 years.

Is there any progress on this front?

antspy avatar May 09 '25 05:05 antspy