-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build python grpc? #52
Comments
The python code generator is in the main grpc repository. Unlike the Java gRPC code generator which provides precompiled artifacts, you will need to compile the python generator by yourself. Feel free to ask questions on grpc-io@googlegroups.com on how to do it. |
As an alternative, there's this plugin, which seems to support building for both java an python: https://github.com/andrewkroh/gradle-protobuf-plugin |
This would be a cool addition. Personally could use it for cpp. |
Is there an easy way to execute the Python gRPC generation using the Gradle plugin? I tried searching the forum, but did not find much of anything. Or, is there something similar to #177 for Python gRPC? |
@mkobit You can try this (haven't run it in awhile): project(":proto") {
apply plugin: "java"
apply plugin: "com.google.protobuf"
buildDir = "$rootProject.buildDir/proto"
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protoVersion}"
}
plugins {
grpc_java {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
grpc_python {
path = getPluginPath("python")
}
grpc_ruby {
path = getPluginPath("ruby")
}
grpc_cpp {
path = getPluginPath("cpp")
}
}
generateProtoTasks {
all()*.builtins {
java {}
python {}
ruby {}
cpp {}
}
all()*.plugins {
grpc_java {
outputSubDir = "java"
}
grpc_python {
outputSubDir = "python"
}
grpc_ruby {
outputSubDir = "ruby"
}
grpc_cpp {
outputSubDir = "cpp"
}
}
}
generatedFilesBaseDir = "$buildDir/generated/src"
}
dependencies {
compile "com.google.protobuf:protobuf-java:${protoVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
}
}
static def getPluginPath(name) {
def path = "which grpc_${name}_plugin".execute()
path.waitFor()
path = path.in.text.trim()
return path
} |
@mkobit Also looks like theres a Python example in the README.md Edit: Added the getPluginPath function definition above. |
@gnz00 thanks, the example you provided is helpful. Hopefully I can take that and run with it. I did see the Python in the README but haven't figured out yet how to get gRPC plugin-side of it to work. I'm looking through some Python gRPC documentation, but I am really struggling trying to find the path to the plugin that is installed. Everything I see is doing |
@mkobit RUN yum install -y autoconf \
automake \
build-essential \
gcc-c++ \
gflags-devel \
glibc-headers \
git \
java-1.8.0-openjdk-devel \
libtool \
make \
unzip \
wget \
&& yum -y clean all
ENV APP_DIR=...
ENV PROTOBUF_DIR=/opt/protobuf
ENV GRPC_DIR=/opt/grpc
ARG PROTOBUF_VERSION=3.4.0
ARG GRPC_VERSION=1.6.6
ARG GRADLE_VERSION=4.2.1
RUN wget https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip
RUN unzip -d /opt/gradle gradle-$GRADLE_VERSION-bin.zip
RUN git clone --depth 1 --branch v$PROTOBUF_VERSION https://github.com/google/protobuf $PROTOBUF_DIR
RUN git clone --depth 1 --branch v$GRPC_VERSION https://github.com/grpc/grpc/ $GRPC_DIR
ENV PATH=$PATH:/opt/gradle/gradle-$GRADLE_VERSION/bin/
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
ENV LD_LIBRARY_PATH=$LD_LIBARY_PATH:/usr/local/lib/
# Install protobuf
WORKDIR $PROTOBUF_DIR
RUN git submodule update --init --recursive
RUN ./autogen.sh
RUN ./configure
RUN make
RUN sudo make install
RUN sudo ldconfig
# Install GRPC
WORKDIR $GRPC_DIR
RUN git submodule update --init --recursive
RUN make
RUN sudo make install
RUN sudo ldconfig
COPY . $APP_DIR
WORKDIR $APP_DIR
# Build projects
RUN gradle :proto:build
RUN gradle build |
@mkobit You might just need: |
Thanks @gnz00 - if I install To give a summary of what I'm triyng to do - I'm attempting to generate Python server and client gRPC code as well as Java client code by using this Gradle plugin. I'm not having much luck doing them both, so I might just have to shell out to the Python gRPC tooling with |
It appears grpcio-tools uses an .so version of the plugin, not a normal binary. |
@mkobit As @ejona86 pointed out the Python |
would be nice if this played well with things like prototool, its difficult to generate stubs for a variety of languages with these off cases |
For people using this solution and would like something that doesn't require installing dependencies, only a valid docker environment, you can use something along the lines of
where an executable file is placed in your project at
I am unsure if Docker for Desktop on Windows will (1) add |
By using io.grpc:protoc-gen-grpc-java as an artifact for grpc plugin, I can generate grpc libraries in Java.
But I could not figure out how to generate python grpc libraries with protobuf-gradle-plugin.
Is it not supported yet?
The text was updated successfully, but these errors were encountered: