Skip to content

Commit dee5cfc

Browse files
feat: VI-13156 Adds Python protoc.sh support
[VI-13156](https://outreach-io.atlassian.net/browse/VI-13156) Adds support for building Python protobuf client stubs. Adds pinned versions for the relevant tools in `versions.yaml`. This Python build script eschews fancier systems like `poetry` or `uv` in favor of managing its own virtualenv. It maintains a virtualenv under a `.venv-codegen` directory under the repo's root and installs the necessary tools (grpcio, betterproto) there. Also adds some placeholders for Python package building and publishing.
1 parent 68849b8 commit dee5cfc

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

shell/protoc.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,39 @@ if has_grpc_client "ruby"; then
293293
popd || exit 1
294294
fi
295295
fi
296+
297+
if has_grpc_client "python"; then
298+
info "Generating Python gRPC client"
299+
300+
# Create a dedicated virtualenv for codegen tools
301+
VENV_DIR="$HOME/.outreach/.cache/$(get_app_name)/venv-codegen"
302+
VENV_PYTHON="$VENV_DIR/bin/python"
303+
VENV_PIP="$VENV_DIR/bin/pip"
304+
305+
if [ ! -d "$VENV_DIR" ]; then
306+
info_sub "Creating virtualenv for code generation tools"
307+
python -m venv "$VENV_DIR"
308+
fi
309+
310+
info_sub "Ensuring Python protoc plugins are installed"
311+
312+
python_grpcio_tools_version="$(get_application_version "python-grpcio-tools")"
313+
betterproto_version="$(get_application_version "betterproto")"
314+
315+
"$VENV_PIP" install --quiet \
316+
"grpcio-tools==$python_grpcio_tools_version" \
317+
"betterproto[compiler]==$betterproto_version"
318+
319+
# Make python output directory if it doesn't exist.
320+
mkdir -p "$(get_repo_directory)$workDir/clients/python/src/$(get_app_name)_client/generated"
321+
322+
info_sub "Running Python protobuf generation"
323+
324+
python_args=("${default_args[@]}")
325+
python_args+=(
326+
--python_betterproto_out="$(get_repo_directory)$workDir/clients/python/src/$(get_app_name)_client/generated"
327+
--proto_path "$(get_repo_directory)$workDir$SUBDIR"
328+
)
329+
330+
"$VENV_PYTHON" -m grpc_tools.protoc "${python_args[@]}" "$(get_repo_directory)$workDir$SUBDIR/"*.proto
331+
fi

shell/python/build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Builds a python package
3+
4+
set -e
5+
6+
echo "TODO(VI-13156): Python packaging not yet implemented"
7+
exit 0

shell/python/publish.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Publishes a python package
3+
4+
set -e
5+
6+
echo "TODO(VI-13156): Python package publishing not yet implemented"
7+
exit 0

versions.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ node-grpc-tools: 1.11.2
2222
# https://github.com/getoutreach/stencil-golang/blob/main/templates/api/clients/ruby/client.gemspec.tpl
2323
ruby-grpc-tools: 1.72.0
2424
node-ts-grpc-tools: 5.3.2
25+
python-grpcio-tools: 1.76.0
26+
betterproto: 2.0.0-beta7
2527

2628
# latest Go protobuf modules
2729
protoc-gen-go-latest: 1.31.0

0 commit comments

Comments
 (0)