uber / prototool

Your Swiss Army Knife for Protocol Buffers
MIT License
5.05k stars 345 forks source link

Prototool doesn't generate all the needed files for python #555

Open popadi opened 4 years ago

popadi commented 4 years ago

Hello!

I am trying to use prototool to generate the appropriate files for a python project. For a .proto service description containing gRPC services, the plain protoc generated code is synthesized in a _pb2.py file, and the gRPC-specifc code lands in a _grpc_pb2.py file. The latter python module imports the former. If you look at one of the python tutorials, you can see that after you run the protoc command you end up with two files: helloworld_pb2 and helloworld_pb2_grpc.

The command I use with a personal project to have both of them (so I can properly create the service and the client):

 python -m grpc_tools.protoc -I . --python_out ./build --grpc_python_out ./build quickstat2.proto

However, with --dry-run prototool does:

/home/[...]/protoc -I /home/[...]/protobuf/3.11.0/include -I . --python_out=/home/[...]/python /home/[..]/quickstat2.proto

So the --grpc_python_out flag is missing and my extra file is not properly generated. The documentation doesn't seem to say anything about this.

Is there a way to obtain the 2nd file by modifying something in the prototool configuration file? Thank you!

popadi commented 4 years ago

Nevermind, this is a duplicate of https://github.com/uber/prototool/issues/239. Sorry for not paying enough attention. You can also find info about it here: https://github.com/google/protobuf-gradle-plugin/issues/250.

However, at this point you can't really build the plugin yourself using make grpc_python_plugin -j12 anymore as described in some comments (that are 2 years old). If you want to generate the other file, you need to use python -m grpc_tools.protoc and I'm not sure how I am supposed to do this from the prototool configuration file. It's not really something "you can add to the path" since (as I previously said) it's not installed separately.

Wherever you search something related to generating python classes for python, they don't use protoc but the python module (python -m grpc_tools.protoc). Using the path of the python module as the path for the plugin also doesn't work.

Anyone has any ideas or fixes that would easily work (hopefully) directly in the uber/prototools docker image? I can also build my own, but I'm not sure how can I achieve the desired results. Thank you!