Skip to content

Commit

Permalink
Added python build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyotoko committed Sep 28, 2024
1 parent 4c42a33 commit 67d2d3e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Project

- Removed Sonatype
- Added python build scripts

## v0.1.2

Expand Down
37 changes: 37 additions & 0 deletions compile.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
setlocal EnableDelayedExpansion

rem Remove the 'stubs' directory if it exists, and create a new one
if exist stubs (
rd /s /q stubs
)
mkdir stubs

rem Base directory to start the search
set baseDir=src\main\proto

rem Find all .proto files in the specified directory and subdirectories
set "protoFiles="
for /r %baseDir% %%f in (*.proto) do (
rem Get the relative path from the base directory
set "relativePath=%%f"
set "relativePath=!relativePath:%CD%\=!"
set "protoFiles=!protoFiles! !relativePath!"
)

rem Run the grpc_tools.protoc command
python -m grpc_tools.protoc ^
--python_out=stubs ^
--grpc_python_out=stubs ^
--proto_path=%baseDir% ^
--mypy_out=stubs ^
--experimental_allow_proto3_optional ^
!protoFiles!

rem Invoke protol to fix broken imports
protol ^
--create-package ^
--in-place ^
--python-out stubs ^
protoc --proto-path=%baseDir% !protoFiles! --experimental_allow_proto3_optional

endlocal
31 changes: 31 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

echo Checkout pip requirements
python -m venv venv
venv/bin/pip install -r requirements.txt

echo Search for proto files
mapfile -d '' proto_src_files < <(find src/main/proto -name '*.proto' -print0)

echo Remove old api files
rm -rf api
mkdir api

echo Compile proto files
venv/bin/python -m grpc_tools.protoc \
--python_out=api \
--grpc_python_out=api \
--proto_path=src/main/proto \
--plugin=protoc-gen-mypy=venv/bin/protoc-gen-mypy \
--mypy_out=api \
--experimental_allow_proto3_optional \
"${proto_src_files[@]}"

# invoke proletariat to fix broken imports

echo Fix paths
venv/bin/protol \
--create-package \
--in-place \
--python-out api \
protoc --proto-path=src/main/proto "${proto_src_files[@]}" --experimental_allow_proto3_optional
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
protoletariat==3.2.19
mypy-protobuf==3.4.0
grpclib==0.4.6
grpcio-tools==1.59.3
protobuf==4.23.2

0 comments on commit 67d2d3e

Please sign in to comment.