diff --git a/Makefile b/Makefile index 49d4ec5..ad32cc1 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,15 @@ -PROJECT_NAME := synapsectl -PROTOC := python -m grpc_tools.protoc -PROTO_DIR := ./synapse-api -PROTO_OUT := ./synapse -PROTOS := $(shell find ${PROTO_DIR} -name '*.proto' | sed 's|${PROTO_DIR}/||') - .PHONY: all -all: clean generate +all: + ./setup.sh all .PHONY: clean clean: - rm -rf bin ${PROTO_OUT}/api* + ./setup.sh clean .PHONY: generate generate: - mkdir -p bin - mkdir -p ${PROTO_OUT} - ${PROTOC} -I=${PROTO_DIR} --descriptor_set_out=bin/descriptors.binpb ${PROTOS} - ${PROTOC} -I=${PROTO_DIR} --python_out=${PROTO_OUT} ${PROTOS} - ${PROTOC} -I=${PROTO_DIR} --grpc_python_out=${PROTO_OUT} api/synapse.proto - protol --create-package --in-place --python-out ${PROTO_OUT} raw bin/descriptors.binpb + ./setup.sh generate +.PHONY: test test: - pytest -v \ No newline at end of file + ./setup.sh test diff --git a/README.md b/README.md index c7a59b2..9469d18 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,9 @@ Dependencies: git submodule update --init pip install -r requirements.txt - make + ./setup.sh all + # or + make all To build and install in development mode: diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..b4c6adf --- /dev/null +++ b/setup.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# Define variables +PROTOC="python -m grpc_tools.protoc" +PROTO_DIR_SYNAPSE_API="./synapse-api" +PROTO_OUT_SYNAPSE_API="./synapse" + +clean() { + echo "Cleaning up..." + rm -rf bin "${PROTO_OUT_SYNAPSE_API}/api"* +} + +generate_protos() { + local input_proto_dir="$1" + local output_proto_dir="$2" + local service_proto="$3" + + if [ -z "$input_proto_dir" ]; then + echo "Error: input proto directory is required" + exit 1 + fi + + if [ -z "$output_proto_dir" ]; then + echo "Error: output proto directory is required" + exit 1 + fi + + if [ -z "$service_proto" ]; then + echo "Error: service proto file is required" + exit 1 + fi + + echo "Generating protobuf files..." + echo "- input: ${input_proto_dir}" + echo "- output: ${output_proto_dir}" + echo "- service: ${service_proto}" + + mkdir -p bin + mkdir -p "${output_proto_dir}" + + # Store proto files in an array + PROTOS=($(find "${input_proto_dir}" -name "*.proto" | sed "s|${input_proto_dir}/||")) + + # Generate descriptor set + ${PROTOC} -I="${input_proto_dir}" --descriptor_set_out=bin/descriptors.binpb "${PROTOS[@]}" + + # Generate Python files + ${PROTOC} -I="${input_proto_dir}" --python_out="${output_proto_dir}" "${PROTOS[@]}" + + # Generate gRPC Python files + ${PROTOC} -I="${input_proto_dir}" --grpc_python_out="${output_proto_dir}" "${service_proto}" + + # Run protol + protol --create-package --in-place --python-out "${output_proto_dir}" raw bin/descriptors.binpb +} + +generate() { + generate_protos "${PROTO_DIR_SYNAPSE_API}" "${PROTO_OUT_SYNAPSE_API}" "api/synapse.proto" +} + +run_tests() { + echo "Running tests..." + pytest -v +} + +# Main script logic +case "$1" in + "clean") + clean + ;; + "generate") + generate + ;; + "test") + run_tests + ;; + "all") + clean + generate + ;; + *) + echo "Usage: $0 {clean|generate|test|all}" + echo "For generate: $0 generate [input_proto_dir] [output_proto_dir] [service_proto]" + exit 1 + ;; +esac + +exit 0