Skip to content

Use real rules_python #17545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Bazel - Google's Build System

load("//tools/distributions:distribution_rules.bzl", "distrib_jar_filegroup")
load("//tools/python:private/defs.bzl", "py_binary")
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_license//rules:license.bzl", "license")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

Expand Down
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ bazel_dep(name = "rules_cc", version = "0.0.6")
bazel_dep(name = "rules_java", version = "5.4.1")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_jvm_external", version = "4.5")
bazel_dep(name = "rules_python", version = "0.18.1")

single_version_override(
module_name = "rules_jvm_external",
patch_strip = 1,
Expand Down Expand Up @@ -50,3 +52,5 @@ local_path_override(
module_name = "googleapis",
path = "./third_party/googleapis",
)

register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")
24 changes: 12 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,6 @@ dist_http_archive(
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
)

# This is a mock version of bazelbuild/rules_python that contains only
# @rules_python//python:defs.bzl. It is used by protobuf.
# TODO(#9029): We could potentially replace this with the real @rules_python.
new_local_repository(
name = "rules_python",
build_file = "//third_party/rules_python:BUILD",
path = "./third_party/rules_python",
workspace_file = "//third_party/rules_python:rules_python.WORKSPACE",
)

local_repository(
name = "googleapis",
path = "./third_party/googleapis/",
Expand Down Expand Up @@ -214,6 +204,16 @@ dist_http_archive(
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
)

dist_http_archive(
name = "rules_python",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

dist_http_archive(
name = "zstd-jni",
build_file = "//third_party:zstd-jni/zstd-jni.BUILD",
Expand Down Expand Up @@ -713,11 +713,11 @@ maven_install(
"com.google.protobuf:protobuf-java",
"com.google.protobuf:protobuf-javalite",
],
fail_if_repin_required = True,
maven_install_json = "//:maven_install.json",
repositories = [
"https://repo1.maven.org/maven2",
],
maven_install_json = "//:maven_install.json",
fail_if_repin_required = True,
strict_visibility = True,
)

Expand Down
7 changes: 7 additions & 0 deletions distdir_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ DIST_DEPS = {
],
"package_version": "4.5",
},
"rules_python": {
"sha256": "29a801171f7ca190c543406f9894abf2d483c206e14d6acbd695623662320097",
"strip_prefix": "rules_python-0.18.1",
"urls": ["https://github.com/bazelbuild/rules_python/releases/download/0.18.1/rules_python-0.18.1.tar.gz"],
"archive": "rules_python-0.18.1.tar.gz",
"used_in": ["additional_distfiles", "test_WORKSPACE_files"],
},
"desugar_jdk_libs": {
# Commit 5847d6a06302136d95a14b4cbd4b55a9c9f1436e of 2021-03-10
"archive": "5847d6a06302136d95a14b4cbd4b55a9c9f1436e.zip",
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//tools/python:private/defs.bzl", "py_binary", "py_library")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")

BUILD_SCM_REV_CMD = "$$(grep BUILD_SCM_REVISION bazel-out/volatile-status.txt | sed 's/^BUILD_SCM_REVISION //')"

Expand Down
2 changes: 1 addition & 1 deletion src/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Packaging

load("//tools/python:private/defs.bzl", "py_binary", "py_library")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load(":embedded_tools.bzl", "srcsfile")
load(":rule_size_test.bzl", "rule_size_test")
load("//src:release_archive.bzl", "release_archive")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ gen_workspace_stanza(
"rules_cc",
"rules_java",
"rules_proto",
"rules_python",
"remotejdk11_linux",
"remotejdk11_linux_aarch64",
"remotejdk11_linux_ppc64le",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,10 @@ maybe(
{rules_proto}
)

# Needed only because of proguard_allowlister in java_tools.
maybe(
http_archive,
{rules_python}
)

register_toolchains("@bazel_tools//tools/jdk:all")
11 changes: 3 additions & 8 deletions src/main/protobuf/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
load("@rules_python//python:proto.bzl", "py_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//third_party/grpc:build_defs.bzl", "java_grpc_library")
load("//third_party/grpc/bazel:cc_grpc_library.bzl", "cc_grpc_library")
Expand Down Expand Up @@ -47,10 +47,7 @@ proto_library(

py_proto_library(
name = "analysis_v2_py_proto",
srcs = ["analysis_v2.proto"],
default_runtime = "//third_party/protobuf:protobuf_python",
protoc = "//third_party/protobuf:protoc",
deps = [":build_pb_py"],
deps = [":analysis_v2_proto"],
)

java_proto_library(
Expand Down Expand Up @@ -187,9 +184,7 @@ cc_grpc_library(

py_proto_library(
name = "build_pb_py",
srcs = ["build.proto"],
default_runtime = "//third_party/protobuf:protobuf_python",
protoc = "//third_party/protobuf:protoc",
deps = [":build_proto"],
)

java_library_srcs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class DefaultToolsSetup implements ToolsSetup {

private static ImmutableList<String> repos =
ImmutableList.<String>builder().add("rules_cc").add("rules_proto").add("rules_java").build();
ImmutableList.<String>builder().add("rules_cc").add("rules_proto").add("rules_java").add("rules_python").build();

private ImmutableList<String> getRepositoryOverrides() {
String sharedRepoHome = System.getenv("TEST_REPOSITORY_HOME");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gen_workspace_stanza(
repos = [
"rules_cc",
"rules_proto",
"rules_python",
],
visibility = ["//visibility:private"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void setup(MockToolsConfig config) throws IOException {
addTool(config, "tools/python/srcs_version.bzl");
addTool(config, "tools/python/toolchain.bzl");
addTool(config, "tools/python/utils.bzl");
addTool(config, "tools/python/private/defs.bzl");
addTool(config, "tools/python/python_bootstrap_template.txt");

config.create(
Expand Down
3 changes: 2 additions & 1 deletion src/test/py/bazel/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//:distdir_deps.bzl", "gen_workspace_stanza")
load("//tools/python:private/defs.bzl", "py_library", "py_test")
load("@rules_python//python:defs.bzl", "py_library", "py_test")

package(default_visibility = ["//visibility:private"])

Expand Down Expand Up @@ -43,6 +43,7 @@ gen_workspace_stanza(
repos = [
"rules_license",
"rules_cc",
"rules_python",
],
)

Expand Down
1 change: 1 addition & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TestBase(unittest.TestCase):
'rules_cc',
'rules_java',
'rules_proto',
'rules_python',
'remotejdk11_linux_for_testing',
'remotejdk11_linux_aarch64_for_testing',
'remotejdk11_linux_ppc64le_for_testing',
Expand Down
3 changes: 2 additions & 1 deletion src/test/shell/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//:distdir_deps.bzl", "gen_workspace_stanza")
load("//tools/python:private/defs.bzl", "py_test")
load("@rules_python//python:defs.bzl", "py_test")

package(default_visibility = ["//visibility:private"])

Expand Down Expand Up @@ -31,6 +31,7 @@ gen_workspace_stanza(
"rules_license",
"rules_pkg",
"rules_proto",
"rules_python",
],
template = "testenv.sh.tmpl",
visibility = ["//visibility:public"],
Expand Down
15 changes: 1 addition & 14 deletions src/test/shell/bazel/bazel_proto_library_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ function write_workspace() {
mkdir -p "$workspace"
fi

cat >> "$workspace"WORKSPACE << EOF
# TODO(#9029): May require some adjustment if/when we depend on the real
# @rules_python in the real source tree, since this third_party/ package won't
# be available.
new_local_repository(
name = "rules_python",
path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))",
build_file = "$(rlocation io_bazel/third_party/rules_python/BUILD)",
workspace_file = "$(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE)",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
EOF
cat $(rlocation io_bazel/src/tests/shell/bazel/rules_proto_stanza.txt) >> "$workspace"WORKSPACE
cat >> "$workspace"WORKSPACE << EOF
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
Expand All @@ -70,7 +57,7 @@ rules_proto_toolchains()
# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib.
new_local_repository(
name = "io_bazel",
path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))/../..",
path = "$(dirname $(rlocation io_bazel/third_party/zlib))/..",
build_file_content = "# Intentionally left empty.",
workspace_file_content = "workspace(name = 'io_bazel')",
)
Expand Down
1 change: 1 addition & 0 deletions src/test/shell/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ gen_workspace_stanza(
out = "rules_proto_stanza.txt",
repos = [
"rules_proto",
"rules_python"
],
)

Expand Down
14 changes: 1 addition & 13 deletions src/test/shell/integration/modify_execution_info_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ Genrule=+requires-a,CppCompile=+requires-b,CppCompile=+requires-c \

function test_modify_execution_info_various_types() {
if [[ "$PRODUCT_NAME" = "bazel" ]]; then
# proto_library requires this external workspace.
cat >> WORKSPACE << EOF
# TODO(#9029): May require some adjustment if/when we depend on the real
# @rules_python in the real source tree, since this third_party/ package won't
# be available.
new_local_repository(
name = "rules_python",
path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))",
build_file = "$(rlocation io_bazel/third_party/rules_python/BUILD)",
workspace_file = "$(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE)",
)
EOF
cat "$(rlocation "io_bazel/src/test/shell/integration/rules_proto_stanza.txt")" >>WORKSPACE
cat >> WORKSPACE << EOF
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
Expand All @@ -172,7 +160,7 @@ rules_proto_toolchains()
# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib.
new_local_repository(
name = "io_bazel",
path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))/../..",
path = "$(dirname $(rlocation io_bazel/third_party/zlib))/..",
build_file_content = "# Intentionally left empty.",
workspace_file_content = "workspace(name = 'io_bazel')",
)
Expand Down
9 changes: 9 additions & 0 deletions src/test/shell/testenv.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
EOF
}

function add_rules_python_to_workspace() {
cat >> "$1"<<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

{rules_python}
EOF
}

function create_workspace_with_default_repos() {
write_workspace_file "${1:-WORKSPACE}" "${2:-main}"
echo "$1"
Expand All @@ -572,6 +580,7 @@ EOF
add_rules_license_to_workspace "WORKSPACE"
add_rules_pkg_to_workspace "WORKSPACE"
add_rules_proto_to_workspace "WORKSPACE"
add_rules_python_to_workspace "WORKSPACE"

maybe_setup_python_windows_workspace
}
Expand Down
1 change: 0 additions & 1 deletion third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ filegroup(
"//third_party/py/frozendict:srcs",
"//third_party/py/mock:srcs",
"//third_party/py/six:srcs",
"//third_party/rules_python:srcs",
"//third_party/zlib:srcs",
"//third_party/upb:srcs",
"@googleapis//:srcs",
Expand Down
4 changes: 1 addition & 3 deletions third_party/def_parser/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Needed for #9006. Consider replacing label with @rules_python as per #9029 if
# merging from upstream becomes an issue.
load("//tools/python:private/defs.bzl", "py_test")
load("@rules_python//python:defs.bzl", "py_test")

licenses(["notice"]) # 3-clause BSD

Expand Down
4 changes: 1 addition & 3 deletions third_party/py/abseil/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Needed for #9006. Consider replacing label with @rules_python as per #9029 if
# merging from upstream becomes an issue.
load("//tools/python:private/defs.bzl", "py_library")
load("@rules_python//python:defs.bzl", "py_library")

licenses(["notice"])

Expand Down
4 changes: 1 addition & 3 deletions third_party/py/concurrent/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Needed for #9006. Consider replacing label with @rules_python as per #9029 if
# merging from upstream becomes an issue.
load("//tools/python:private/defs.bzl", "py_library")
load("@rules_python//python:defs.bzl", "py_library")

licenses(["notice"])

Expand Down
2 changes: 1 addition & 1 deletion third_party/py/frozendict/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//tools/python:private/defs.bzl", "py_library")
load("@rules_python//python:defs.bzl", "py_library")

licenses(["notice"])

Expand Down
4 changes: 1 addition & 3 deletions third_party/py/mock/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Needed for #9006. Consider replacing label with @rules_python as per #9029 if
# merging from upstream becomes an issue.
load("//tools/python:private/defs.bzl", "py_library")
load("@rules_python//python:defs.bzl", "py_library")

licenses(["notice"])

Expand Down
5 changes: 1 addition & 4 deletions third_party/py/six/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Needed for #9006. We can't easily replace this label with a @rules_python
# label (#9029) because this file is used in both @io_bazel and @bazel_tools,
# the latter of which can't reference other repos.
load("//tools/python:private/defs.bzl", "py_library")
load("@rules_python//python:defs.bzl", "py_library")

licenses(["notice"])

Expand Down
12 changes: 0 additions & 12 deletions third_party/rules_python/BUILD

This file was deleted.

5 changes: 0 additions & 5 deletions third_party/rules_python/python/BUILD

This file was deleted.

Loading