From 56f78340f50fc26675faf7b3bc2de5f95bd57794 Mon Sep 17 00:00:00 2001 From: Antonia Elsen Date: Fri, 28 Feb 2025 20:15:58 -0800 Subject: [PATCH 1/6] build: remove Makefile, add setup.sh --- Makefile | 22 +++++--------- README.md | 2 +- setup.sh | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 16 deletions(-) create mode 100755 setup.sh diff --git a/Makefile b/Makefile index 49d4ec51..459a39be 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,16 @@ -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 + \ No newline at end of file diff --git a/README.md b/README.md index c7a59b2e..e4db43c0 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Dependencies: git submodule update --init pip install -r requirements.txt - make + ./setup.sh all To build and install in development mode: diff --git a/setup.sh b/setup.sh new file mode 100755 index 00000000..1199f21c --- /dev/null +++ b/setup.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +# Define variables +PROTOC="python -m grpc_tools.protoc" +PROTO_DIR_SYNAPSE_API="./synapse-api" +PROTO_OUT_SYNAPSE_API="./synapse" + +find_protos() { + local input_proto_dir="$1" + find "${input_proto_dir}" -name "*.proto" | sed "s|${input_proto_dir}/||" +} + +clean() { + echo "Cleaning up..." + rm -rf bin "${PROTO_OUT_SYNAPSE_API}/api"* +} + +generate() { + 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 +} + +run_tests() { + echo "Running tests..." + pytest -v +} + +# Main script logic +case "$1" in + "clean") + clean + ;; + "generate") + generate "${PROTO_DIR_SYNAPSE_API}" "${PROTO_OUT_SYNAPSE_API}" "api/synapse.proto" + ;; + "test") + run_tests + ;; + "all") + clean + generate "${PROTO_DIR_SYNAPSE_API}" "${PROTO_OUT_SYNAPSE_API}" "api/synapse.proto" + ;; + *) + 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 \ No newline at end of file From 9b4b40d7c2116043b9a12b1870a1df34bbdbc2af Mon Sep 17 00:00:00 2001 From: Antonia Elsen Date: Fri, 28 Feb 2025 20:21:48 -0800 Subject: [PATCH 2/6] chore: lint --- setup.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/setup.sh b/setup.sh index 1199f21c..62c8f8fb 100755 --- a/setup.sh +++ b/setup.sh @@ -5,17 +5,12 @@ PROTOC="python -m grpc_tools.protoc" PROTO_DIR_SYNAPSE_API="./synapse-api" PROTO_OUT_SYNAPSE_API="./synapse" -find_protos() { - local input_proto_dir="$1" - find "${input_proto_dir}" -name "*.proto" | sed "s|${input_proto_dir}/||" -} - clean() { echo "Cleaning up..." rm -rf bin "${PROTO_OUT_SYNAPSE_API}/api"* } -generate() { +generate_protos() { local input_proto_dir="$1" local output_proto_dir="$2" local service_proto="$3" @@ -59,6 +54,10 @@ generate() { 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 @@ -70,14 +69,14 @@ case "$1" in clean ;; "generate") - generate "${PROTO_DIR_SYNAPSE_API}" "${PROTO_OUT_SYNAPSE_API}" "api/synapse.proto" + generate ;; "test") run_tests ;; "all") clean - generate "${PROTO_DIR_SYNAPSE_API}" "${PROTO_OUT_SYNAPSE_API}" "api/synapse.proto" + generate ;; *) echo "Usage: $0 {clean|generate|test|all}" From 7af89edfa82ac6a336304c8111d89d07220f3756 Mon Sep 17 00:00:00 2001 From: antonia Date: Fri, 14 Mar 2025 13:28:05 -0700 Subject: [PATCH 3/6] chore: update setup.sh --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 62c8f8fb..b4c6adfb 100755 --- a/setup.sh +++ b/setup.sh @@ -85,4 +85,4 @@ case "$1" in ;; esac -exit 0 \ No newline at end of file +exit 0 From 76b6c604467d2e67ae5d158d9cfb787b34a4f049 Mon Sep 17 00:00:00 2001 From: antonia Date: Fri, 14 Mar 2025 13:28:45 -0700 Subject: [PATCH 4/6] chore: update Makefile --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 459a39be..dc2328ca 100644 --- a/Makefile +++ b/Makefile @@ -12,5 +12,4 @@ generate: .PHONY: test test: - ./setup.sh test - \ No newline at end of file + ./setup.sh test \ No newline at end of file From 1925f76c013bb9143a7bf2cfe784b216b728977f Mon Sep 17 00:00:00 2001 From: antonia Date: Fri, 14 Mar 2025 13:29:04 -0700 Subject: [PATCH 5/6] chore: update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dc2328ca..ad32cc13 100644 --- a/Makefile +++ b/Makefile @@ -12,4 +12,4 @@ generate: .PHONY: test test: - ./setup.sh test \ No newline at end of file + ./setup.sh test From d51004879ffb2f92399206b13f48464dca6686c5 Mon Sep 17 00:00:00 2001 From: Antonia Elsen Date: Mon, 7 Apr 2025 17:03:48 -0700 Subject: [PATCH 6/6] chore: update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e4db43c0..9469d181 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,8 @@ Dependencies: git submodule update --init pip install -r requirements.txt ./setup.sh all + # or + make all To build and install in development mode: