Support pyi_out in py_proto_library
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
.pyifiles usingpy_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!
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
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.
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!
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?
Yes, please. Can this issue be re-opened?
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.
Will add pytype_proto_library
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.
Still in the need for this. So would appreciate to keep this FR open.
@anandolee did you have time to look into this?
ping to prevent next inactive tag
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.
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
@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.
+1 This has been very needed for more than 2 years.
Is there any progress on this front?