diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index c04e388c31..369fea12a9 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -93,9 +93,45 @@ jobs: run: pip install -vvv --no-index --find-links wheels protobuf protobuftests - name: Test that module is importable run: python -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)' + if: ${{ !matrix.pure_python }} - name: Run the unit tests run: | TESTS=$(pip show -f protobuftests | grep pb_unit_tests.*py$ | sed 's,/,.,g' | sed 's,\\,.,g' | sed -E 's,.py$,,g') for test in $TESTS; do python -m unittest -v $test done + + test_pure_python_wheels: + name: Test Pure Python Wheels + needs: build_wheels + strategy: + fail-fast: false # Don't cancel all jobs if one fails. + matrix: + python-version: ["3.7", "3.10"] + runs-on: ubuntu-latest + + steps: + - name: Download Wheels + uses: actions/download-artifact@v3 + with: + name: python-wheels + path: wheels + - name: Delete Binary Wheels + run: find wheels -type f | grep -v none-any | xargs rm + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Setup Python venv + run: | + python -m pip install --upgrade pip + python -m venv env + source env/bin/activate + echo "VIRTUAL ENV:" $VIRTUAL_ENV + - name: Install Protobuf Wheels + run: pip install -vvv --no-index --find-links wheels protobuf protobuftests + - name: Run the unit tests + run: | + TESTS=$(pip show -f protobuftests | grep _test.py | sed 's,/,.,g' | sed -E 's,.py$,,g') + for test in $TESTS; do + python -m unittest -v $test + done diff --git a/python/dist/BUILD.bazel b/python/dist/BUILD.bazel index acc3e1834e..9c10a81458 100644 --- a/python/dist/BUILD.bazel +++ b/python/dist/BUILD.bazel @@ -119,9 +119,22 @@ py_wheel( deps = [ ":message_mod", ":well_known_proto_py_pb2", - #TODO(https://github.com/protocolbuffers/upb/issues/503): currently - # this includes the unit tests. We should filter these out so we are - # only distributing true source files. + "@com_google_protobuf//:python_srcs", + ], +) + +py_wheel( + name = "pure_python_wheel", + abi = "none", + distribution = "protobuf", + platform = "any", + python_tag = "py3", + strip_path_prefixes = [ + "python/", + ], + version = PROTOBUF_VERSION, + deps = [ + ":well_known_proto_py_pb2", "@com_google_protobuf//:python_srcs", ], ) @@ -170,5 +183,6 @@ py_dist( "osx-aarch_64": "37", "osx-x86_64": "37", }, + pure_python_wheel = ":pure_python_wheel", tags = ["manual"], ) diff --git a/python/dist/dist.bzl b/python/dist/dist.bzl index fc725f3387..2ddaba3bc2 100644 --- a/python/dist/dist.bzl +++ b/python/dist/dist.bzl @@ -114,9 +114,11 @@ _py_dist_transition = transition( ) def _py_dist_impl(ctx): + binary_files = [dep[DefaultInfo].files for dep in ctx.attr.binary_wheel] + pure_python_files = [ctx.attr.pure_python_wheel[DefaultInfo].files] return [ DefaultInfo(files = depset( - transitive = [dep[DefaultInfo].files for dep in ctx.attr.binary_wheel], + transitive = binary_files + pure_python_files, )), ] @@ -127,6 +129,7 @@ py_dist = rule( mandatory = True, cfg = _py_dist_transition, ), + "pure_python_wheel": attr.label(mandatory = True), "limited_api_wheels": attr.string_dict(), "full_api_versions": attr.string_list(), "full_api_cpus": attr.string_list(),