#!/bin/bash # Generate Python gRPC stubs from proto file for hyperparameter_tuner.py # Run from ml_training_service directory: ./scripts/generate_python_proto.sh set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SERVICE_DIR="$(dirname "$SCRIPT_DIR")" echo "==> Generating Python gRPC stubs from proto file..." # Install Python dependencies if needed if ! python3 -c "import grpc_tools" 2>/dev/null; then echo "==> Installing grpcio-tools..." pip3 install grpcio-tools fi # Create proto output directory mkdir -p "$SERVICE_DIR/proto" touch "$SERVICE_DIR/proto/__init__.py" # Generate Python stubs python3 -m grpc_tools.protoc \ --proto_path="$SERVICE_DIR/proto" \ --python_out="$SERVICE_DIR/proto" \ --grpc_python_out="$SERVICE_DIR/proto" \ "$SERVICE_DIR/proto/ml_training.proto" echo "==> Python gRPC stubs generated successfully" echo " - proto/ml_training_pb2.py" echo " - proto/ml_training_pb2_grpc.py" # Fix import paths in generated files (Python relative imports) sed -i 's/^import ml_training_pb2/from . import ml_training_pb2/' \ "$SERVICE_DIR/proto/ml_training_pb2_grpc.py" 2>/dev/null || true echo "==> Done! Python modules ready for import."