-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathgenerate_proto.sh
More file actions
executable file
·29 lines (23 loc) · 771 Bytes
/
generate_proto.sh
File metadata and controls
executable file
·29 lines (23 loc) · 771 Bytes
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
#!/usr/bin/env bash
# Generate Python gRPC stubs from proto definitions.
# Requires: pip install grpcio-tools
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
PROTO_DIR="$ROOT_DIR/proto"
OUT_DIR="$ROOT_DIR/src/bernstein/core/grpc_gen"
mkdir -p "$OUT_DIR"
python -m grpc_tools.protoc \
-I"$PROTO_DIR" \
--python_out="$OUT_DIR" \
--pyi_out="$OUT_DIR" \
--grpc_python_out="$OUT_DIR" \
"$PROTO_DIR"/bernstein/v1/tasks.proto \
"$PROTO_DIR"/bernstein/v1/cluster.proto
# Fix relative imports in generated code.
for f in "$OUT_DIR"/*.py; do
sed -i.bak 's/^from bernstein\.v1 import/from . import/' "$f"
rm -f "$f.bak"
done
touch "$OUT_DIR/__init__.py"
echo "Generated gRPC stubs in $OUT_DIR"