-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_pbs.sh
executable file
·51 lines (42 loc) · 1.65 KB
/
generate_pbs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -e
current_path="$PWD"
TF_URL="https://github.com/tensorflow/tensorflow.git"
TF_SERVING_URL="https://github.com/tensorflow/serving.git"
TF_COMMIT=$1
# Retrieve tensorflow and tensorflow_serving repos
mkdir -p /tmp/scratch
cd /tmp/scratch
git clone --branch "v$TF_COMMIT" "$TF_URL"
git clone --branch "$TF_COMMIT" "$TF_SERVING_URL"
cd ..
# Reorganize contents to make it easy to compile protos.
# This way the final results will have correct relative paths
# to each other.
mkdir -p workspace
mv /tmp/scratch/tensorflow/tensorflow /tmp/workspace/
mv /tmp/scratch/serving/tensorflow_serving /tmp/workspace/
# Install prerequisite packages
. ~/.virtualenvs/grpc-build/bin/activate
# UNCOMMENT TO USE PYENV-VIRTUALENV
# eval "$(pyenv init -)"
# eval "$(pyenv virtualenv-init -)"
# pyenv activate grpc-build
pip install --upgrade pip protobuf grpcio grpcio-tools mypy-protobuf
# Create the python package of pb2 interfaces
mkdir -p /tmp/tensorflow_proto
cd /tmp/workspace
## Compile protobufs
find . -name '*.proto' -exec \
python -m grpc_tools.protoc -I./ \
--python_out=../tensorflow_proto/ \
--grpc_python_out=../tensorflow_proto/ \
--mypy_out=../tensorflow_proto/ \
{} ';'
find /tmp/tensorflow_proto/ -type d -exec touch {}/__init__.py ';'
find /tmp/tensorflow_proto/ -name '*.py' -exec sed -i -- 's/from tensorflow\./from pythie_serving.tensorflow_proto.tensorflow./g' {} ';'
find /tmp/tensorflow_proto/ -name '*.py' -exec sed -i -- 's/from tensorflow_serving\./from pythie_serving.tensorflow_proto.tensorflow_serving./g' {} ';'
mv /tmp/tensorflow_proto/ "$current_path"
rm -rf /tmp/workspace
rm -rf /tmp/scratch
rm -rf /tmp/tensorflow_proto