Skip to content

Commit 5acf342

Browse files
committed
Add stub @rules_python to third_party/
This stub contains only one relevant file, @rules_python//python:defs.bzl, which mimics the file at the same path in bazelbuild/rules_python. Having this repo gives us a way to inject this defs.bzl file into our protobuf dependency, which is loaded as a separate (local) external repo and therefore cannot access the existing //tools/python:private/defs.bzl in Bazel's own workspace. It also means we'll be compatible with the future upstream migration to fix protobuf for bazelbuild#9006. A separate PR will add this to the Bazel root WORKSPACE file (since third_party/ must be updated in a separate commit). Break-out of bazelbuild#9019. Work toward bazelbuild#9006. RELNOTES: None
1 parent 299e3f0 commit 5acf342

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

third_party/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ filegroup(
3535
"//third_party/py/gflags:srcs",
3636
"//third_party/py/mock:srcs",
3737
"//third_party/py/six:srcs",
38+
"//third_party/rules_python:srcs",
3839
"//third_party/zlib:srcs",
3940
"//third_party/nanopb:srcs",
4041
"//third_party/def_parser:srcs",

third_party/rules_python/BUILD

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
filegroup(
2+
name = "srcs",
3+
srcs = glob(["**"]) + ["//third_party/rules_python/python:srcs"],
4+
visibility = ["//visibility:public"],
5+
)

third_party/rules_python/python/BUILD

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
filegroup(
2+
name = "srcs",
3+
srcs = glob(["**"]),
4+
visibility = ["//visibility:public"],
5+
)
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2019 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""This file is selectively copied from //tools/python:private/defs.bzl."""
16+
17+
_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
18+
19+
def _add_tags(attrs):
20+
if "tags" in attrs and attrs["tags"] != None:
21+
attrs["tags"] += [_MIGRATION_TAG]
22+
else:
23+
attrs["tags"] = [_MIGRATION_TAG]
24+
return attrs
25+
26+
def py_library(**attrs):
27+
native.py_library(**_add_tags(attrs))
28+
29+
def py_binary(**attrs):
30+
native.py_binary(**_add_tags(attrs))
31+
32+
def py_test(**attrs):
33+
native.py_test(**_add_tags(attrs))
34+
35+
def py_runtime(**attrs):
36+
native.py_runtime(**_add_tags(attrs))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# A stub version of bazelbuild/rules_python that contains only the defs.bzl
2+
# file, which is needed to access native Python rules under
3+
# --incompatible_load_python_rules_from_bzl (#9006).
4+
#
5+
# TODO(#9029): Maybe replace this with the real thing.
6+
7+
workspace(name = "rules_python")

0 commit comments

Comments
 (0)