forked from modal-labs/modal-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_for_pypi.sh
More file actions
executable file
·103 lines (86 loc) · 3.2 KB
/
Copy pathbuild_for_pypi.sh
File metadata and controls
executable file
·103 lines (86 loc) · 3.2 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Build script to generate protobuf files before packaging for PyPI
# Fixed to use grpclib instead of grpcio
set -e
echo "================================================"
echo " Building rfmodal for PyPI (grpclib version)"
echo "================================================"
# Ensure we're in the right directory
cd "$(dirname "$0")"
# Check if protoc is installed
if ! command -v protoc &> /dev/null; then
echo "ERROR: protoc (Protocol Buffer compiler) is not installed!"
echo ""
echo "Please install it using one of these methods:"
echo " - macOS: brew install protobuf"
echo " - Ubuntu/Debian: sudo apt-get install protobuf-compiler"
echo " - Other: https://grpc.io/docs/protoc-installation/"
exit 1
fi
echo "Found protoc: $(protoc --version)"
# Install required tools
echo "Installing required tools..."
pip3 install -q protobuf grpclib
# Clean old generated files
echo "Cleaning old generated files..."
rm -f modal_proto/*_pb2.py modal_proto/*_pb2_grpc.py modal_proto/*_grpc.py modal_proto/*_grpclib.py 2>/dev/null || true
# Generate Python protobuf files (messages only)
echo "Generating protobuf Python message files..."
protoc -I. --python_out=. modal_proto/api.proto modal_proto/options.proto
# Create grpclib plugin wrapper if it doesn't exist
if [ ! -f "grpclib_plugin.py" ]; then
echo "Creating grpclib plugin wrapper..."
cat > grpclib_plugin.py << 'EOF'
#!/usr/bin/env python3
import sys
from grpclib.plugin.main import main
if __name__ == '__main__':
main()
EOF
chmod +x grpclib_plugin.py
fi
# Generate grpclib service stubs
echo "Generating grpclib service stubs..."
protoc --plugin=protoc-gen-grpclib_python=./grpclib_plugin.py \
--grpclib_python_out=. -I. modal_proto/api.proto
# Generate modal-specific grpc wrapper if available
echo "Generating modal-specific gRPC wrapper..."
if [ -f "protoc_plugin_wrapper.py" ]; then
chmod +x protoc_plugin_wrapper.py
protoc --plugin=protoc-gen-modal-grpclib-python=./protoc_plugin_wrapper.py \
--modal-grpclib-python_out=. -I . modal_proto/api.proto || echo "Warning: modal-specific wrapper generation failed"
else
echo "Warning: protoc_plugin_wrapper.py not found, skipping modal-specific wrapper"
fi
echo "================================================"
echo "Protobuf generation complete!"
echo "================================================"
# List generated files
echo "Generated files in modal_proto:"
ls -la modal_proto/*.py 2>/dev/null | grep -v __pycache__ || echo "No .py files found"
# Verify critical files exist
echo ""
echo "Verifying critical files..."
MISSING_FILES=0
for file in modal_proto/api_pb2.py modal_proto/options_pb2.py modal_proto/api_grpc.py; do
if [ -f "$file" ]; then
size=$(wc -c < "$file")
if [ $size -gt 0 ]; then
echo "✓ $file exists ($(wc -l < $file) lines)"
else
echo "✗ $file is empty!"
MISSING_FILES=1
fi
else
echo "✗ $file is missing!"
MISSING_FILES=1
fi
done
if [ $MISSING_FILES -eq 1 ]; then
echo ""
echo "ERROR: Some critical files are missing or empty!"
exit 1
fi
echo ""
echo "✅ Ready to build package for PyPI!"
echo "Run: python3 -m build"