From a3c17a9cf5f3782ae237373cb45b20c9852e87bb Mon Sep 17 00:00:00 2001 From: dann frazier Date: Mon, 25 Nov 2024 18:19:33 -0700 Subject: [PATCH] py3-grpcio-tools: python multiversioning (#34780) --- pipelines/py/pip-build-install.yaml | 5 +- py3-grpcio-gcp.yaml | 5 +- py3-grpcio-tools.yaml | 137 ++++++++++++++++++---------- 3 files changed, 94 insertions(+), 53 deletions(-) diff --git a/pipelines/py/pip-build-install.yaml b/pipelines/py/pip-build-install.yaml index 793b93ecb27..8cfa9d5a513 100644 --- a/pipelines/py/pip-build-install.yaml +++ b/pipelines/py/pip-build-install.yaml @@ -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 @@ -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 diff --git a/py3-grpcio-gcp.yaml b/py3-grpcio-gcp.yaml index 7f1056d9602..6c7a267b134 100644 --- a/py3-grpcio-gcp.yaml +++ b/py3-grpcio-gcp.yaml @@ -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 @@ -26,6 +26,7 @@ environment: - py3-grpcio-tools - py3-supported-build-base - py3-supported-setuptools + - python3 pipeline: - uses: git-checkout @@ -57,7 +58,7 @@ subpackages: - uses: py/pip-build-install with: python: python${{range.key}} - source: ./src + working-directory: ./src - uses: strip test: pipeline: diff --git a/py3-grpcio-tools.yaml b/py3-grpcio-tools.yaml index 82b221690be..1476186955a 100644 --- a/py3-grpcio-tools.yaml +++ b/py3-grpcio-tools.yaml @@ -1,17 +1,24 @@ -# 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: @@ -19,65 +26,101 @@ environment: - 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