From a18f0de47c2c650f5c57e6cca80ee3bded76b19a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 14 Oct 2024 07:43:08 -0700 Subject: [PATCH] Load Python rules everywhere in protobuf Bazel 8's autoloads don't work in repositories where they load from. Protobuf thus needs to load Python rules. PiperOrigin-RevId: 685703304 --- python/internal.bzl | 4 +++- python/pb_unit_tests/pyproto_test_wrapper.bzl | 4 +++- python/py_extension.bzl | 3 ++- upb/cmake/build_defs.bzl | 5 +++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/python/internal.bzl b/python/internal.bzl index 8f99becec4ce..dbd16a288550 100644 --- a/python/internal.bzl +++ b/python/internal.bzl @@ -2,6 +2,8 @@ Internal helpers for building the Python protobuf runtime. """ +load("@rules_python//python:py_test.bzl", "py_test") + def _remove_cross_repo_path(path): components = path.split("/") if components[0] == "..": @@ -123,7 +125,7 @@ def internal_py_test(deps = [], **kwargs): deps: any additional dependencies of the test. **kwargs: arguments forwarded to py_test. """ - native.py_test( + py_test( imports = ["."], deps = deps + ["//python:python_test_lib"], target_compatible_with = select({ diff --git a/python/pb_unit_tests/pyproto_test_wrapper.bzl b/python/pb_unit_tests/pyproto_test_wrapper.bzl index b5f474d3ddc5..1e2b5daa2db5 100644 --- a/python/pb_unit_tests/pyproto_test_wrapper.bzl +++ b/python/pb_unit_tests/pyproto_test_wrapper.bzl @@ -1,8 +1,10 @@ """Wrapper for another py_test to run with upb, possibly with a set of expected failures.""" +load("@rules_python//python:py_test.bzl", "py_test") + def pyproto_test_wrapper(name, deps = []): src = name + "_wrapper.py" - native.py_test( + py_test( name = name, srcs = [src], legacy_create_init = False, diff --git a/python/py_extension.bzl b/python/py_extension.bzl index 9a2828b950d3..2741cdf6ec31 100644 --- a/python/py_extension.bzl +++ b/python/py_extension.bzl @@ -1,6 +1,7 @@ """Macro to support py_extension """ load("@bazel_skylib//lib:selects.bzl", "selects") +load("@rules_python//python:py_library.bzl", "py_library") def py_extension(name, srcs, copts, deps = [], **kwargs): """Creates a C++ library to extend python @@ -50,7 +51,7 @@ def py_extension(name, srcs, copts, deps = [], **kwargs): visibility = ["//python:__subpackages__"], ) - native.py_library( + py_library( name = name, data = [output_file], imports = ["."], diff --git a/upb/cmake/build_defs.bzl b/upb/cmake/build_defs.bzl index 325189c7f11f..09e5c15db9ac 100644 --- a/upb/cmake/build_defs.bzl +++ b/upb/cmake/build_defs.bzl @@ -4,9 +4,10 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file or at # https://developers.google.com/open-source/licenses/bsd - """Bazel support functions related to CMake support.""" +load("@rules_python//python:py_test.bzl", "py_test") + def staleness_test(name, outs, generated_pattern, target_files = None, tags = [], **kwargs): """Tests that checked-in file(s) match the contents of generated file(s). @@ -46,7 +47,7 @@ def staleness_test(name, outs, generated_pattern, target_files = None, tags = [] "sed -i.bak -e 's|INSERT_FILE_LIST_HERE|" + "\\\n ".join(file_list) + "|' $@", ) - native.py_test( + py_test( name = name, srcs = [script_name], data = existing_outs + [generated_pattern % file for file in outs],