Skip to content

Commit

Permalink
py3-grpcio-tools: python multiversioning (#34780)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannf authored Nov 26, 2024
1 parent c1c9202 commit a3c17a9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 53 deletions.
5 changes: 1 addition & 4 deletions pipelines/py/pip-build-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ inputs:
dest:
description: the destination
default: ${{targets.contextdir}}
source:
description: directory containing the python package source
default: .
needs-exe-named-python3:
description: Does the build actually need 'python3' in its PATH
default: false
Expand Down Expand Up @@ -110,7 +107,7 @@ pipeline:
mkdir -p "$distwheelsd"
echo "$py is $pyver with site_packages dir '$sitepkgd'"
vr $py -m pip wheel --verbose "--wheel-dir=$wd" \
"--find-links=$distwheelsd" --no-index --no-build-isolation --no-deps "${{inputs.source}}"
"--find-links=$distwheelsd" --no-index --no-build-isolation --no-deps .
vr $py -m pip install --verbose \
"--find-links=$distwheelsd" --no-index --no-build-isolation --no-deps \
--force-reinstall --no-compile --prefix=/usr "--root=$root" "$wd"/*.whl
Expand Down
5 changes: 3 additions & 2 deletions py3-grpcio-gcp.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package:
name: py3-grpcio-gcp
version: 0.2.2
epoch: 3
epoch: 4
description: gRPC extensions for Google Cloud Platform
copyright:
- license: Apache-2.0
Expand All @@ -26,6 +26,7 @@ environment:
- py3-grpcio-tools
- py3-supported-build-base
- py3-supported-setuptools
- python3

pipeline:
- uses: git-checkout
Expand Down Expand Up @@ -57,7 +58,7 @@ subpackages:
- uses: py/pip-build-install
with:
python: python${{range.key}}
source: ./src
working-directory: ./src
- uses: strip
test:
pipeline:
Expand Down
137 changes: 90 additions & 47 deletions py3-grpcio-tools.yaml
Original file line number Diff line number Diff line change
@@ -1,83 +1,126 @@
# Generated from https://pypi.org/project/grpcio-tools/
package:
name: py3-grpcio-tools
version: 1.67.1
epoch: 1
version: 1.68.0
epoch: 0
description: Protobuf code generator for gRPC
copyright:
- license: Apache-2.0
dependencies:
runtime:
- py3-protobuf
- py3-grpcio
- py3-setuptools
- python3
provider-priority: 0

vars:
pypi-package: grpcio-tools
import: grpc_tools.protoc

data:
- name: py-versions
items:
3.10: '310'
3.11: '311'
3.12: '312'
3.13: '300'

environment:
contents:
packages:
- build-base
- busybox
- ca-certificates-bundle
- cython
- git
- openssf-compiler-options
- py3-setuptools
- py3-wheel
- py3-supported-build-base
- py3-supported-cython
- py3-supported-python-dev
- py3-supported-setuptools
- python3
- python3-dev
- wolfi-base
environment:
# https://github.com/wolfi-dev/os/issues/34075
GCC_SPEC_FILE: /dev/null
GRPC_PYTHON_BUILD_WITH_CYTHON: 1

pipeline:
- uses: git-checkout
with:
repository: https://github.com/grpc/grpc
tag: v${{package.version}}
expected-commit: d3286610f703a339149c3f9be69f0d7d0abb130a
expected-commit: 6b49ae626bc9cd7033e062f89dbe0e0576b1110e

- runs: |
git submodule update --init
cd tools/distrib/python/grpcio_tools
python ../make_grpcio_tools.py
export GRPC_PYTHON_BUILD_WITH_CYTHON=1
python setup.py install --prefix=/usr --root="${{targets.destdir}}"
python3 ../make_grpcio_tools.py
- uses: strip

subpackages:
- range: py-versions
name: py${{range.key}}-${{vars.pypi-package}}
description: python${{range.key}} version of ${{vars.pypi-package}}
dependencies:
provider-priority: ${{range.value}}
provides:
- py3-${{vars.pypi-package}}
runtime:
- py${{range.key}}-grpcio
- py${{range.key}}-protobuf
pipeline:
- uses: py/pip-build-install
with:
python: python${{range.key}}
working-directory: tools/distrib/python/grpcio_tools
- uses: strip
test:
pipeline:
- name: Verify Installation
uses: python/import
with:
python: python${{range.key}}
imports: |
import ${{vars.import}}
- name: Test Protobuf Compilation
runs: |
# Create a temporary directory for testing
mkdir -p /home/build/test-grpcio-tools
cd /home/build/test-grpcio-tools
# Create a sample .proto file for testing
echo 'syntax = "proto3"; package test; message TestMessage { string test_field = 1; }' > test.proto
# Compile the .proto file using grpcio-tools
python${{range.key}} -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. test.proto || exit 1
echo "Protobuf file compiled successfully."
# Check if Python files were generated
if [ ! -f test_pb2.py ] || [ ! -f test_pb2_grpc.py ]; then
echo "Generated Python files not found!"
exit 1
fi
echo "Generated Python files found."
- name: Clean Up
runs: |
# Clean up the test files after the test
rm -rf /home/build/test-grpcio-tools
- name: py3-supported-${{vars.pypi-package}}
description: meta package providing ${{vars.pypi-package}} for supported python versions.
dependencies:
runtime:
- py3.10-${{vars.pypi-package}}
- py3.11-${{vars.pypi-package}}
- py3.12-${{vars.pypi-package}}
- py3.13-${{vars.pypi-package}}

test:
pipeline:
- name: Verify Installation
uses: python/import
with:
import: ${{vars.import}}

update:
enabled: true
github:
identifier: grpc/grpc
strip-prefix: v
use-tag: true

test:
pipeline:
- name: Verify Installation
runs: |
# Ensure that grpcio-tools is installed
python3 -c "import grpc_tools.protoc" || exit 1
echo "grpcio-tools package is installed."
- name: Test Protobuf Compilation
runs: |
# Create a temporary directory for testing
mkdir -p /home/build/test-grpcio-tools
cd /home/build/test-grpcio-tools
# Create a sample .proto file for testing
echo 'syntax = "proto3"; package test; message TestMessage { string test_field = 1; }' > test.proto
# Compile the .proto file using grpcio-tools
python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. test.proto || exit 1
echo "Protobuf file compiled successfully."
# Check if Python files were generated
if [ ! -f test_pb2.py ] || [ ! -f test_pb2_grpc.py ]; then
echo "Generated Python files not found!"
exit 1
fi
echo "Generated Python files found."
- name: Clean Up
runs: |
# Clean up the test files after the test
rm -rf /home/build/test-grpcio-tools

0 comments on commit a3c17a9

Please sign in to comment.