xolstice / protobuf-maven-plugin

Maven Plugin that executes the Protocol Buffers (protoc) compiler
https://www.xolstice.org/protobuf-maven-plugin/
Other
232 stars 76 forks source link

pure rpc stub for python #71

Closed mueller-jens closed 4 years ago

mueller-jens commented 4 years ago

Is your feature request related to a problem? Please describe. I want to generate a purerpc stub from a proto file. On command line we use the following command python -m grpc_tools.protoc --purerpc_out=. --python_out=. -I. <filename>.proto

Is it possible withe the actual plugin version? If not is it on your road map? Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context about the feature request here.

sergei-ivanov commented 4 years ago

Looking at the purerpc documentation, I think it should work out of the box, as long as purerpc is installed and protoc-gen-purerpc executable is in the PATH.

Let's try the following configuration:

<project>
  ...
  <properties>
    <protobufVersion>3.11.1</protobufVersion>
  </properties>
  ...
  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.6.1</version>
      </extension>
    </extensions>
    <plugins>
      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.6.1</version>
         <configuration>
          <!-- Common configuration, used by all goals -->
          <protocArtifact>
            com.google.protobuf:protoc:${protobufVersion}:exe:${os.detected.classifier}
          </protocArtifact>
        </configuration>
        <executions>
          <execution>
            <id>protoc-python</id>
            <goals>
              <goal>compile-python</goal>
            </goals>
          </execution>
          <execution>
            <id>protoc-purerpc</id>
            <goals>
              <goal>compile-custom</goal>
            </goals>
            <configuration>
              <!-- Configuration for a specific goal -->
              <pluginId>purerpc</pluginId>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>
mueller-jens commented 4 years ago

Thanks sergei. It doesn't work, becuase the protoc-gen-purerpc is not found. Looks like protocArtifact doesn't look in the entire PATH for the protoc-gen-purerpc

sergei-ivanov commented 4 years ago

It probably depends on how you install it. If you are using virtualenv, then it's probably not going to be visible to maven, unless you run maven inside, for example, pipenv run or pipenv shell (or the equivalents if you are not using pipenv).

I did a test in a docker container (python:buster), where I installed purerpc at the system level via pip, downloaded protoc and a sampled greeter.proto, and then the following command line worked:

protoc --purerpc_out=. --python_out=. -I. greeter.proto

So you either need to do pip install purerpc or pip install --user purerpc to make protoc-gen-purerpc available on the PATH. Maven is not aware of virtual python environments, and it won't be able to find executables, unless they are on the PATH.

mueller-jens commented 4 years ago

I have installed it in my environment with pip, it is available if i call prototoc-gen-purerpc on commandline bu not in maven. But looks like it is an issue with my environment. So I close ths issue. Thanks for your time. Best regards Jens