Skip to content

Commit

Permalink
Load Python rules everywhere in protobuf
Browse files Browse the repository at this point in the history
Bazel 8's autoloads don't work in repositories where they load from. Protobuf thus needs to load Python rules.

PiperOrigin-RevId: 685703304
  • Loading branch information
protobuf-github-bot authored and comius committed Oct 15, 2024
1 parent a748b10 commit a18f0de
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion python/internal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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] == "..":
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 3 additions & 1 deletion python/pb_unit_tests/pyproto_test_wrapper.bzl
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion python/py_extension.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = ["."],
Expand Down
5 changes: 3 additions & 2 deletions upb/cmake/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit a18f0de

Please sign in to comment.