Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
./setup.sh test
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
88 changes: 88 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -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}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this generate helper doesn't take arguments anymore.

echo "For generate: $0 generate [input_proto_dir] [output_proto_dir] [service_proto]"
exit 1
;;
esac

exit 0