Skip to content

Commit 24f612c

Browse files
Merge pull request #1541 from michael-berlin/fix_grpc_python
Fix gRPC Python issue since switch to 0.13.
2 parents 262ece6 + c995349 commit 24f612c

File tree

5 files changed

+70
-46
lines changed

5 files changed

+70
-46
lines changed

bootstrap.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function zk_patch_mac() {
3535

3636
go version 2>&1 >/dev/null || fail "Go is not installed or is not on \$PATH"
3737

38-
. ./dev.env
38+
# Set up the proper GOPATH for go get below.
39+
source ./dev.env
3940

4041
mkdir -p $VTROOT/dist
4142
mkdir -p $VTROOT/bin
@@ -75,22 +76,13 @@ else
7576
if [[ `uname -s` == "Darwin" && "$(brew list -1 | grep google-protobuf)" ]]; then
7677
brew unlink grpc/grpc/google-protobuf
7778
fi
78-
# protobuf used to be a separate package, now we use the gRPC one
79+
80+
# protobuf used to be a separate package, now we use the gRPC one.
7981
rm -rf $VTROOT/dist/protobuf
80-
rm -rf $grpc_dist
81-
mkdir -p $grpc_dist/usr/local/bin
82-
mkdir -p $grpc_dist/usr/local/lib/python2.7/dist-packages
83-
# The directory may not have existed yet, so it may not have been
84-
# picked up by dev.env yet, but the install needs it to be in
85-
# PYTHONPATH.
86-
export PYTHONPATH=$(prepend_path $PYTHONPATH $grpc_dist/usr/local/lib/python2.7/dist-packages)
87-
export PATH=$(prepend_path $PATH $grpc_dist/usr/local/bin)
88-
export LD_LIBRARY_PATH=$(prepend_path $LD_LIBRARY_PATH $grpc_dist/usr/local/lib)
8982

90-
if [ `uname -s` == "Darwin" ]; then
91-
# on OSX tox is installed in the following path
92-
export PATH=$(prepend_path $PATH /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin)
93-
fi
83+
# Cleanup any existing data and re-create the directory.
84+
rm -rf $grpc_dist
85+
mkdir -p $grpc_dist
9486

9587
./travis/install_grpc.sh $grpc_dist || fail "gRPC build failed"
9688
echo "$grpc_ver" > $grpc_dist/.build_finished
@@ -99,6 +91,11 @@ else
9991
if [[ `uname -s` == "Darwin" && "$(brew list -1 | grep google-protobuf)" ]]; then
10092
brew link grpc/grpc/google-protobuf
10193
fi
94+
95+
# Add newly installed Python code to PYTHONPATH such that other Python module
96+
# installations can reuse it. (Once bootstrap.sh has finished, run
97+
# source dev.env instead to set the correct PYTHONPATH.)
98+
export PYTHONPATH=$(prepend_path $PYTHONPATH $grpc_dist/usr/local/lib/python2.7/dist-packages)
10299
fi
103100

104101
ln -nfs $VTTOP/third_party/go/launchpad.net $VTROOT/src

dev.env

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
# Use of this source code is governed by a BSD-style license that can
33
# be found in the LICENSE file.
44

5+
# Import prepend_path function.
6+
dir="$(dirname "${BASH_SOURCE[0]}")"
7+
source "${dir}/tools/shell_functions.inc"
8+
if [ $? -ne 0 ]; then
9+
echo "failed to load tools/shell_functions.inc"
10+
return 1
11+
fi
12+
13+
514
export VTTOP=$(pwd)
615
export VTROOT="${VTROOT:-${VTTOP/\/src\/github.com\/youtube\/vitess/}}"
716
# VTTOP sanity check
@@ -16,19 +25,6 @@ mkdir -p $VTDATAROOT
1625

1726
export VTPORTSTART=15000
1827

19-
function prepend_path()
20-
{
21-
# $1 path variable
22-
# $2 path to add
23-
if [ -d "$2" ] && [[ ":$1:" != *":$2:"* ]]; then
24-
echo "$2:$1"
25-
else
26-
echo "$1"
27-
fi
28-
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
29-
export PATH="$1:$PATH"
30-
fi
31-
}
3228

3329
for pypath in $(find $VTROOT/dist -name site-packages -or -name dist-packages | grep -v src/python/grpcio/.tox/py27/lib/python2.7/site-packages)
3430
do

docker/bootstrap/Dockerfile.common

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ RUN curl -sL --connect-timeout 10 --retry 3 \
3333
https://bootstrap.pypa.io/get-pip.py | python
3434

3535
# Install PHP modules for running tests
36-
RUN mkdir -p /vt/bin && \
36+
RUN export MAKEFLAGS="-j$(nproc)" && \
37+
mkdir -p /vt/bin && \
3738
curl -sL --connect-timeout 10 --retry 3 \
3839
https://phar.phpunit.de/phpunit-4.8.9.phar > /vt/bin/phpunit && \
3940
chmod +x /vt/bin/phpunit && \
@@ -46,7 +47,7 @@ RUN mkdir -p /vt/bin && \
4647
RUN mkdir -p /vt/dist && \
4748
cd /vt/dist && \
4849
curl -sL --connect-timeout 10 --retry 3 \
49-
http://www.carfab.com/apachesoftware/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz | tar -xz && \
50+
http://www-us.apache.org/dist/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz | tar -xz && \
5051
mv apache-maven-3.3.3 maven
5152

5253
# Install etcd v2.0
@@ -84,7 +85,8 @@ COPY travis /vt/src/github.com/youtube/vitess/travis
8485
COPY composer.json composer.lock /vt/src/github.com/youtube/vitess/
8586

8687
# Install gRPC (and protobuf) as root
87-
RUN cd /vt/dist && \
88+
RUN export MAKEFLAGS="-j$(nproc)" && \
89+
cd /vt/dist && \
8890
INSTALL_GRPC_PHP=`php-config --extension-dir` $VTTOP/travis/install_grpc.sh && \
8991
echo 'extension=grpc.so' > /etc/php5/cli/conf.d/20-grpc.ini && \
9092
rm -rf /vt/dist/grpc

tools/shell_functions.inc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ function goversion_min() {
1717
[ "$gotminor" -lt "$wantminor" ] && return 1
1818
return 0
1919
}
20+
21+
# prepend_path returns $2 prepended the colon separated path $1.
22+
# If it's already part of the path, it won't be added again.
23+
# If $1 is a directory, it will also be prepended to $PATH.
24+
function prepend_path() {
25+
# $1 path variable
26+
# $2 path to add
27+
if [ -d "$2" ] && [[ ":$1:" != *":$2:"* ]]; then
28+
echo "$2:$1"
29+
else
30+
echo "$1"
31+
fi
32+
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
33+
export PATH="$1:$PATH"
34+
fi
35+
}

travis/install_grpc.sh

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@
55
# as root in the image.
66
set -ex
77

8+
# Import prepend_path function.
9+
dir="$(dirname "${BASH_SOURCE[0]}")"
10+
source "${dir}/../tools/shell_functions.inc"
11+
if [ $? -ne 0 ]; then
12+
echo "failed to load ../tools/shell_functions.inc"
13+
return 1
14+
fi
15+
816
# grpc_dist can be empty, in which case we just install to the default paths
917
grpc_dist="$1"
1018
if [ -n "$grpc_dist" ]; then
1119
cd $grpc_dist
1220
fi
1321

14-
# for python, we'll need the latest virtualenv and tox.
15-
# running gRPC requires the six package, version >=1.10.
22+
# Python requires a very recent version of virtualenv.
1623
if [ -n "$grpc_dist" ]; then
1724
# Create a virtualenv, which also creates a virualenv-boxed pip.
1825
virtualenv $grpc_dist/usr/local
19-
$grpc_dist/usr/local/bin/pip install --upgrade --ignore-installed virtualenv tox six
26+
$grpc_dist/usr/local/bin/pip install --upgrade --ignore-installed virtualenv
2027
else
21-
pip install --upgrade --ignore-installed virtualenv tox six
28+
# system wide installations require an explicit upgrade of
29+
# certain gRPC Python dependencies e.g. "six" on Debian Jessie.
30+
pip install --upgrade --ignore-installed six
2231
fi
2332

2433
# clone the repository, setup the submodules
@@ -48,25 +57,29 @@ else
4857
make install
4958
fi
5059

51-
# build and install python protobuf side
52-
cd python
53-
if [ -n "$grpc_dist" ]; then
54-
python setup.py build --cpp_implementation
55-
python setup.py install --cpp_implementation --prefix=$grpc_dist/usr/local
56-
else
57-
python setup.py build --cpp_implementation
58-
python setup.py install --cpp_implementation
59-
fi
60-
6160
# now install grpc itself
62-
cd ../../..
61+
cd ../..
6362
if [ -n "$grpc_dist" ]; then
6463
make install prefix=$grpc_dist/usr/local
64+
65+
# Add bin directory to the path such that gRPC python won't complain that
66+
# it cannot find "grpc_python_plugin".
67+
export PATH=$(prepend_path $PATH $grpc_dist/usr/local/bin)
6568
else
6669
make install
6770
fi
6871

72+
# Pin the protobuf python dependency to a specific version which is >=3.0.0a3.
73+
#
74+
# This prevents us from running into the bug that the protobuf package with the
75+
# version "3.0.0-alpha-1" is treated as newer than "3.0.0a3" (alpha-3).
76+
# See: https://github.com/google/protobuf/issues/855
77+
# Also discussed here: https://github.com/grpc/grpc/issues/5534
78+
# In particular, we hit this issue on Travis.
79+
sed -i -e 's/protobuf>=3.0.0a3/protobuf==3.0.0a3/' setup.py
80+
6981
# and now build and install gRPC python libraries
82+
# (Dependencies like protobuf python will be installed automatically.)
7083
if [ -n "$grpc_dist" ]; then
7184
$grpc_dist/usr/local/bin/pip install .
7285
else

0 commit comments

Comments
 (0)