forked from hatchet-dev/hatchet-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·78 lines (59 loc) · 3.13 KB
/
generate.sh
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
#!/bin/bash
#
# Builds python auto-generated protobuf files
set -eux
ROOT_DIR=$(pwd)
# deps
version=7.3.0
openapi-generator-cli version || npm install @openapitools/openapi-generator-cli -g
# if [ "$(openapi-generator-cli version)" != "$version" ]; then
# version-manager set "$version"
# fi
# generate deps from hatchet repo
cd hatchet/ && sh ./hack/oas/generate-server.sh && cd $ROOT_DIR
# generate python rest client
dst_dir=./hatchet_sdk/clients/rest
mkdir -p $dst_dir
tmp_dir=./tmp
# generate into tmp folder
openapi-generator-cli generate -i ./hatchet/bin/oas/openapi.yaml -g python -o ./tmp --skip-validate-spec \
--library asyncio \
--global-property=apiTests=false \
--global-property=apiDocs=true \
--global-property=modelTests=false \
--global-property=modelDocs=true \
--package-name hatchet_sdk.clients.rest
mv $tmp_dir/hatchet_sdk/clients/rest/api_client.py $dst_dir/api_client.py
mv $tmp_dir/hatchet_sdk/clients/rest/configuration.py $dst_dir/configuration.py
mv $tmp_dir/hatchet_sdk/clients/rest/api_response.py $dst_dir/api_response.py
mv $tmp_dir/hatchet_sdk/clients/rest/exceptions.py $dst_dir/exceptions.py
mv $tmp_dir/hatchet_sdk/clients/rest/__init__.py $dst_dir/__init__.py
mv $tmp_dir/hatchet_sdk/clients/rest/rest.py $dst_dir/rest.py
openapi-generator-cli generate -i ./hatchet/bin/oas/openapi.yaml -g python -o . --skip-validate-spec \
--library asyncio \
--global-property=apis,models \
--global-property=apiTests=false \
--global-property=apiDocs=false \
--global-property=modelTests=false \
--global-property=modelDocs=false \
--package-name hatchet_sdk.clients.rest
# copy the __init__ files from tmp to the destination since they are not generated for some reason
cp $tmp_dir/hatchet_sdk/clients/rest/models/__init__.py $dst_dir/models/__init__.py
cp $tmp_dir/hatchet_sdk/clients/rest/api/__init__.py $dst_dir/api/__init__.py
# remove tmp folder
rm -rf $tmp_dir
poetry run python -m grpc_tools.protoc --proto_path=hatchet/api-contracts/dispatcher --python_out=./hatchet_sdk/contracts --pyi_out=./hatchet_sdk/contracts --grpc_python_out=./hatchet_sdk/contracts dispatcher.proto
poetry run python -m grpc_tools.protoc --proto_path=hatchet/api-contracts/events --python_out=./hatchet_sdk/contracts --pyi_out=./hatchet_sdk/contracts --grpc_python_out=./hatchet_sdk/contracts events.proto
poetry run python -m grpc_tools.protoc --proto_path=hatchet/api-contracts/workflows --python_out=./hatchet_sdk/contracts --pyi_out=./hatchet_sdk/contracts --grpc_python_out=./hatchet_sdk/contracts workflows.proto
# Fix relative imports in _grpc.py files
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
find ./hatchet_sdk/contracts -type f -name '*_grpc.py' -print0 | xargs -0 sed -i '' 's/^import \([^ ]*\)_pb2/from . import \1_pb2/'
else
# Linux and others
find ./hatchet_sdk/contracts -type f -name '*_grpc.py' -print0 | xargs -0 sed -i 's/^import \([^ ]*\)_pb2/from . import \1_pb2/'
fi
# ensure that pre-commit is applied without errors
pre-commit run --all-files || pre-commit run --all-files
# apply patch to openapi-generator generated code
patch -p1 --no-backup-if-mismatch <./openapi_patch.patch