|
1 | 1 | #!/bin/bash
|
2 |
| - |
3 |
| -# Source the activate script to set up the PATH for this shell session |
4 |
| -source ./.venv/bin/activate |
| 2 | +set -e |
5 | 3 |
|
6 | 4 | hapi_version="v0.57.3"
|
7 | 5 | protos_dir=".protos"
|
8 | 6 | services_dir="src/hiero_sdk_python/hapi/services"
|
9 | 7 | mirror_dir="src/hiero_sdk_python/hapi/mirror"
|
10 | 8 |
|
11 |
| -# Step 1: Prepare directories |
12 | 9 | echo "Setting up directories..."
|
13 |
| -mkdir -p $protos_dir |
14 |
| -rm -rf $protos_dir/* |
15 |
| -rm -rf $services_dir/* |
16 |
| -rm -rf $mirror_dir/* |
17 |
| -mkdir -p $services_dir/auxiliary/tss |
18 |
| -mkdir -p $services_dir/event |
19 |
| -mkdir -p $mirror_dir |
20 |
| -touch $services_dir/__init__.py |
21 |
| -touch $mirror_dir/__init__.py |
| 10 | +mkdir -p "$protos_dir" |
| 11 | +rm -rf "$protos_dir"/* |
| 12 | +rm -rf "$services_dir"/* |
| 13 | +rm -rf "$mirror_dir"/* |
| 14 | +mkdir -p "$services_dir/auxiliary/tss" |
| 15 | +mkdir -p "$services_dir/event" |
| 16 | +mkdir -p "$mirror_dir" |
| 17 | +touch "$services_dir/__init__.py" |
| 18 | +touch "$mirror_dir/__init__.py" |
22 | 19 |
|
23 |
| -# Step 2: Download and extract protobuf files |
24 | 20 | echo "Downloading Hedera protobufs version $hapi_version..."
|
25 |
| -curl -sL "https://github.com/hashgraph/hedera-protobufs/archive/refs/tags/${hapi_version}.tar.gz" | tar -xz -C $protos_dir --strip-components=1 |
26 |
| -# Keep 'platform', 'services', and 'mirror', remove everything else |
27 |
| -find "$protos_dir" -mindepth 1 -maxdepth 1 ! -name platform ! -name services ! -name mirror -exec rm -r {} + |
| 21 | +curl -sL "https://github.com/hashgraph/hedera-protobufs/archive/refs/tags/${hapi_version}.tar.gz" \ |
| 22 | + | tar -xz -C "$protos_dir" --strip-components=1 |
| 23 | + |
| 24 | +find "$protos_dir" -mindepth 1 -maxdepth 1 \ |
| 25 | + ! -name platform ! -name services ! -name mirror -exec rm -r {} + |
28 | 26 |
|
29 |
| -# Step 3: Compile service and platform protobuf files |
30 | 27 | echo "Compiling service and platform protobuf files..."
|
31 | 28 | python -m grpc_tools.protoc \
|
32 |
| - --proto_path=$protos_dir/platform \ |
33 |
| - --proto_path=$protos_dir/services \ |
34 |
| - --pyi_out=./$services_dir \ |
35 |
| - --python_out=./$services_dir \ |
36 |
| - --grpc_python_out=./$services_dir \ |
37 |
| - $protos_dir/services/*.proto $protos_dir/services/auxiliary/tss/*.proto $protos_dir/platform/event/*.proto |
| 29 | + --proto_path="$protos_dir/platform" \ |
| 30 | + --proto_path="$protos_dir/services" \ |
| 31 | + --pyi_out="./$services_dir" \ |
| 32 | + --python_out="./$services_dir" \ |
| 33 | + --grpc_python_out="./$services_dir" \ |
| 34 | + "$protos_dir/services/"*.proto \ |
| 35 | + "$protos_dir/services/auxiliary/tss/"*.proto \ |
| 36 | + "$protos_dir/platform/event/"*.proto |
38 | 37 |
|
39 |
| -# Step 4: Adjust imports for service and platform protobuf files |
40 | 38 | echo "Adjusting imports for service and platform protobuf files..."
|
41 | 39 | if [[ "$OSTYPE" == "darwin"* ]]; then
|
42 |
| - find $services_dir -type f -name "*.py" -exec sed -i '' \ |
| 40 | + find "$services_dir" -type f -name "*.py" -exec sed -i '' \ |
43 | 41 | -e '/^import .*_pb2 as .*__pb2/s/^/from . /' \
|
44 | 42 | -e 's/^from auxiliary\.tss/from .auxiliary.tss/' \
|
45 | 43 | -e 's/^from event/from .event/' {} +
|
46 | 44 | else
|
47 |
| - find $services_dir -type f -name "*.py" -exec sed -i \ |
| 45 | + find "$services_dir" -type f -name "*.py" -exec sed -i \ |
48 | 46 | -e '/^import .*_pb2 as .*__pb2/s/^/from . /' \
|
49 | 47 | -e 's/^from auxiliary\.tss/from .auxiliary.tss/' \
|
50 | 48 | -e 's/^from event/from .event/' {} +
|
51 | 49 | fi
|
52 | 50 |
|
53 |
| -# Step 5: Compile mirror protobuf files |
54 | 51 | echo "Compiling mirror protobuf files..."
|
55 | 52 | python -m grpc_tools.protoc \
|
56 |
| - --proto_path=$protos_dir/mirror \ |
57 |
| - --proto_path=$protos_dir/services \ |
58 |
| - --python_out=$mirror_dir \ |
59 |
| - --grpc_python_out=$mirror_dir \ |
60 |
| - $protos_dir/mirror/*.proto |
| 53 | + --proto_path="$protos_dir/mirror" \ |
| 54 | + --proto_path="$protos_dir/services" \ |
| 55 | + --python_out="$mirror_dir" \ |
| 56 | + --grpc_python_out="$mirror_dir" \ |
| 57 | + "$protos_dir/mirror/"*.proto |
61 | 58 |
|
62 |
| -# Step 6: Adjust imports for mirror protobuf files |
63 | 59 | echo "Adjusting imports for mirror protobuf files..."
|
64 | 60 | if [[ "$OSTYPE" == "darwin"* ]]; then
|
65 |
| - find $mirror_dir -type f -name "*.py" -exec sed -i '' \ |
| 61 | + find "$mirror_dir" -type f -name "*.py" -exec sed -i '' \ |
66 | 62 | -e 's/^import basic_types_pb2 as/import hiero_sdk_python.hapi.services.basic_types_pb2 as/' \
|
67 | 63 | -e 's/^import timestamp_pb2 as/import hiero_sdk_python.hapi.services.timestamp_pb2 as/' \
|
68 | 64 | -e 's/^import consensus_submit_message_pb2 as/import hiero_sdk_python.hapi.services.consensus_submit_message_pb2 as/' \
|
69 | 65 | -e 's/^import consensus_service_pb2 as/import hiero_sdk_python.hapi.mirror.consensus_service_pb2 as/' \
|
70 | 66 | -e 's/^import mirror_network_service_pb2 as/import hiero_sdk_python.hapi.mirror.mirror_network_service_pb2 as/' {} +
|
71 | 67 | else
|
72 |
| - find $mirror_dir -type f -name "*.py" -exec sed -i \ |
| 68 | + find "$mirror_dir" -type f -name "*.py" -exec sed -i \ |
73 | 69 | -e 's/^import basic_types_pb2 as/import hiero_sdk_python.hapi.services.basic_types_pb2 as/' \
|
74 | 70 | -e 's/^import timestamp_pb2 as/import hiero_sdk_python.hapi.services.timestamp_pb2 as/' \
|
75 | 71 | -e 's/^import consensus_submit_message_pb2 as/import hiero_sdk_python.hapi.services.consensus_submit_message_pb2 as/' \
|
76 | 72 | -e 's/^import consensus_service_pb2 as/import hiero_sdk_python.hapi.mirror.consensus_service_pb2 as/' \
|
77 | 73 | -e 's/^import mirror_network_service_pb2 as/import hiero_sdk_python.hapi.mirror.mirror_network_service_pb2 as/' {} +
|
78 | 74 | fi
|
79 | 75 |
|
80 |
| -# Step 7: Confirm success |
81 |
| -if [ "$(ls -A $services_dir)" ] && [ "$(ls -A $mirror_dir)" ]; then |
| 76 | +if [ "$(ls -A "$services_dir")" ] && [ "$(ls -A "$mirror_dir")" ]; then |
82 | 77 | echo "All protobuf files have been generated and adjusted successfully!"
|
83 | 78 | else
|
84 | 79 | echo "Error: Protobuf file generation or adjustment failed."
|
|
0 commit comments