0

When I generate grpc files from python (running python -m grpc_tools.protoc), I get 2 files for each one of the X proto files, X_pb2.py and X_pb2_grpc.py.

However by using compile-python maven goal from protobuf-maven-plugin (0.6.1), I only get the X_pb2.py files and not the grpc files. The problem that I have with this is that the services are missing from the pb2.py files. So how can I get the grpc.py files to be built?

From pip list

grpcio          1.23.0 
grpcio-tools    1.23.0 
protobuf        3.9.1  
$ python --version
Python 3.7.3
$ pip --version
pip 19.2.3 from /blahblahblah/lib/python3.7/site-packages/pip (python 3.7)
eftshift0
  • 26,375
  • 3
  • 36
  • 60

2 Answers2

1

It doesn't look like the xolstice Maven plugin supports this out of the box. gRPC code generation requires a plugin to the protoc compiler. This plugin is baked into the grpcio-tools package on PyPI. You'll have to compile the Python gRPC protoc plugin and supply it to protobuf-maven-plugin to make it work. The protocPlugin parameter looks like it should do what you want.

But at a higher level, is there a reason why you're using Maven to build Python artifacts?

Richard Belleville
  • 1,445
  • 5
  • 7
  • Thanks for your feedback. It's a mostly-java-based project built on maven.... so, proto files are created and, **previously**, we generated java-only files... I added the support for the python files because I'm dealing with python stuff. – eftshift0 Sep 04 '19 at 19:26
0

I have had great success with putting the compile command in a script and using the exec-maven-plugin to execute the script during compile.

I used a shell script to run a variation of the compile command from gRPC Quick Start. A little note is that no matter where you place the script, it will be run from project root unless you navigate to another folder inside the script.

Goju Ryu
  • 101