-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add load() statements for Python rules in third_party
This replaces all direct uses of the native Python rules underneath the third_party/ directory with load()s of the internal wrapper macros. These macros are needed for compatibility with `--incompatible_load_python_rules_from_bzl`. Work toward #9006. RELNOTES: None
- Loading branch information
Showing
13 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//tools/python:private/defs.bzl", "py_test") | ||
|
||
licenses(["notice"]) # 3-clause BSD | ||
|
||
package( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""This is a Bazel-internal file; do not load() it! | ||
The incompatible change `--incompatible_load_python_rules_from_bzl` (#9006) | ||
makes it so the four native Python rules cannot be used unless a magic tag is | ||
present. It is intended that only `@rules_python` (bazelbuild/rules_python) | ||
uses this tag, and all other uses access the native rules via the wrapper | ||
macros defined in `@rules_python`. | ||
However, `@bazel_tools` is not allowed to depend on any other repos. Therefore, | ||
we replicate the behavior of `@rules_python`'s wrapper macros in this file, for | ||
use by Bazel only. | ||
This gets a bit tricky with the third_party/ directory. Some of its | ||
subdirectories are full-blown workspaces that cannot directly reference this | ||
file's label. For these cases we currently copy this file into those trees | ||
under the name `python_defs.bzl`. | ||
TODO(#9029): Currently all uses of Python in Bazel's source tree use this file, | ||
but in principle only `@bazel_tools` needs to. The rest should use the real | ||
`@rules_python`, or for third_party/ packages that get mirrored into | ||
`@bazel_tools`, a dummy version of the repo that contains only this file under | ||
label `@rules_python//python:defs.bzl`. | ||
""" | ||
|
||
_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" | ||
|
||
def _add_tags(attrs): | ||
if "tags" in attrs and attrs["tags"] != None: | ||
attrs["tags"] += [_MIGRATION_TAG] | ||
else: | ||
attrs["tags"] = [_MIGRATION_TAG] | ||
return attrs | ||
|
||
def py_library(**attrs): | ||
native.py_library(**_add_tags(attrs)) | ||
|
||
def py_binary(**attrs): | ||
native.py_binary(**_add_tags(attrs)) | ||
|
||
def py_test(**attrs): | ||
native.py_test(**_add_tags(attrs)) | ||
|
||
def py_runtime(**attrs): | ||
native.py_runtime(**_add_tags(attrs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//tools/python:private/defs.bzl", "py_library") | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//tools/python:private/defs.bzl", "py_library") | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//tools/python:private/defs.bzl", "py_library") | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//tools/python:private/defs.bzl", "py_library") | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
load("//tools/python:private/defs.bzl", "py_library") | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# A stub version of bazelbuild/rules_python that contains only the defs.bzl | ||
# file needed to access native Python rules under | ||
# --incompatible_load_python_rules_from_bzl. | ||
# | ||
# TODO(#9029): Replace this with the real thing (probably). | ||
|
||
workspace(name = "rules_python") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# This file intentionally left blank. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2019 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Internal copy of //tools/python:private/defs.bzl.""" | ||
|
||
_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" | ||
|
||
def _add_tags(attrs): | ||
if "tags" in attrs and attrs["tags"] != None: | ||
attrs["tags"] += [_MIGRATION_TAG] | ||
else: | ||
attrs["tags"] = [_MIGRATION_TAG] | ||
return attrs | ||
|
||
def py_library(**attrs): | ||
native.py_library(**_add_tags(attrs)) | ||
|
||
def py_binary(**attrs): | ||
native.py_binary(**_add_tags(attrs)) | ||
|
||
def py_test(**attrs): | ||
native.py_test(**_add_tags(attrs)) | ||
|
||
def py_runtime(**attrs): | ||
native.py_runtime(**_add_tags(attrs)) |