Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fae219

Browse filesBrowse files
committed
refactor: move all re-exports to private/reexports.bzl (bazel-contrib#739)
1 parent eb83c43 commit 1fae219
Copy full SHA for 1fae219

File tree

Expand file treeCollapse file tree

2 files changed

+75
-58
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+75
-58
lines changed

‎python/defs.bzl

Copy file name to clipboardExpand all lines: python/defs.bzl
+19-58Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,29 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Core rules for building Python projects.
16-
17-
Currently the definitions here are re-exports of the native rules, "blessed" to
18-
work under `--incompatible_load_python_rules_from_bzl`. As the native rules get
19-
migrated to Starlark, their implementations will be moved here.
15+
"""
16+
Core rules for building Python projects.
2017
"""
2118

2219
load("@bazel_tools//tools/python:srcs_version.bzl", _find_requirements = "find_requirements")
2320
load("@bazel_tools//tools/python:toolchain.bzl", _py_runtime_pair = "py_runtime_pair")
24-
load("//python/private:reexports.bzl", "internal_PyInfo", "internal_PyRuntimeInfo")
2521
load("//python/py_pytest_main:def.bzl", _py_pytest_main = "py_pytest_main")
22+
load(
23+
"//python/private:reexports.bzl",
24+
"internal_PyInfo",
25+
"internal_PyRuntimeInfo",
26+
_py_binary = "py_binary",
27+
_py_library = "py_library",
28+
_py_runtime = "py_runtime",
29+
_py_test = "py_test",
30+
)
2631

2732
# Exports of native-defined providers.
2833

2934
PyInfo = internal_PyInfo
3035

3136
PyRuntimeInfo = internal_PyRuntimeInfo
3237

33-
# The implementation of the macros and tagging mechanism follows the example
34-
# set by rules_cc and rules_java.
35-
36-
_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
37-
38-
def _add_tags(attrs):
39-
if "tags" in attrs and attrs["tags"] != None:
40-
attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]
41-
else:
42-
attrs["tags"] = [_MIGRATION_TAG]
43-
return attrs
44-
4538
def _current_py_toolchain_impl(ctx):
4639
toolchain = ctx.toolchains[ctx.attr._toolchain]
4740

@@ -85,36 +78,6 @@ current_py_toolchain = rule(
8578
],
8679
)
8780

88-
def py_library(**attrs):
89-
"""See the Bazel core [py_library](https://docs.bazel.build/versions/master/be/python.html#py_library) documentation.
90-
91-
Args:
92-
**attrs: Rule attributes
93-
"""
94-
95-
# buildifier: disable=native-python
96-
native.py_library(**_add_tags(attrs))
97-
98-
def py_binary(**attrs):
99-
"""See the Bazel core [py_binary](https://docs.bazel.build/versions/master/be/python.html#py_binary) documentation.
100-
101-
Args:
102-
**attrs: Rule attributes
103-
"""
104-
105-
# buildifier: disable=native-python
106-
native.py_binary(**_add_tags(attrs))
107-
108-
def py_test(**attrs):
109-
"""See the Bazel core [py_test](https://docs.bazel.build/versions/master/be/python.html#py_test) documentation.
110-
111-
Args:
112-
**attrs: Rule attributes
113-
"""
114-
115-
# buildifier: disable=native-python
116-
native.py_test(**_add_tags(attrs))
117-
11881
def _py_import_impl(ctx):
11982
# See https://github.com/bazelbuild/bazel/blob/0.24.0/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java#L104 .
12083
import_paths = [
@@ -165,20 +128,18 @@ py_import = rule(
165128
},
166129
)
167130

168-
def py_runtime(**attrs):
169-
"""See the Bazel core [py_runtime](https://docs.bazel.build/versions/master/be/python.html#py_runtime) documentation.
170-
171-
Args:
172-
**attrs: Rule attributes
173-
"""
174-
175-
# buildifier: disable=native-python
176-
native.py_runtime(**_add_tags(attrs))
177-
178131
# Re-exports of Starlark-defined symbols in @bazel_tools//tools/python.
179132

180133
py_runtime_pair = _py_runtime_pair
181134

182135
find_requirements = _find_requirements
183136

184137
py_pytest_main = _py_pytest_main
138+
139+
py_library = _py_library
140+
141+
py_binary = _py_binary
142+
143+
py_test = _py_test
144+
145+
py_runtime = _py_runtime

‎python/private/reexports.bzl

Copy file name to clipboardExpand all lines: python/private/reexports.bzl
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
"""Internal re-exports of built-in symbols.
1616
17+
Currently the definitions here are re-exports of the native rules, "blessed" to
18+
work under `--incompatible_load_python_rules_from_bzl`. As the native rules get
19+
migrated to Starlark, their implementations will be removed from here.
20+
1721
We want to re-export a built-in symbol as if it were defined in a Starlark
1822
file, so that users can for instance do:
1923
@@ -33,6 +37,18 @@ different name. Then we can load it from defs.bzl and export it there under
3337
the original name.
3438
"""
3539

40+
# The implementation of the macros and tagging mechanism follows the example
41+
# set by rules_cc and rules_java.
42+
43+
_MIGRATION_TAG = "__PYTHON_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
44+
45+
def _add_tags(attrs):
46+
if "tags" in attrs and attrs["tags"] != None:
47+
attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]
48+
else:
49+
attrs["tags"] = [_MIGRATION_TAG]
50+
return attrs
51+
3652
# Don't use underscore prefix, since that would make the symbol local to this
3753
# file only. Use a non-conventional name to emphasize that this is not a public
3854
# symbol.
@@ -41,3 +57,43 @@ internal_PyInfo = PyInfo
4157

4258
# buildifier: disable=name-conventions
4359
internal_PyRuntimeInfo = PyRuntimeInfo
60+
61+
def py_library(**attrs):
62+
"""See the Bazel core [py_library](https://docs.bazel.build/versions/master/be/python.html#py_library) documentation.
63+
64+
Args:
65+
**attrs: Rule attributes
66+
"""
67+
68+
# buildifier: disable=native-python
69+
native.py_library(**_add_tags(attrs))
70+
71+
def py_binary(**attrs):
72+
"""See the Bazel core [py_binary](https://docs.bazel.build/versions/master/be/python.html#py_binary) documentation.
73+
74+
Args:
75+
**attrs: Rule attributes
76+
"""
77+
78+
# buildifier: disable=native-python
79+
native.py_binary(**_add_tags(attrs))
80+
81+
def py_test(**attrs):
82+
"""See the Bazel core [py_test](https://docs.bazel.build/versions/master/be/python.html#py_test) documentation.
83+
84+
Args:
85+
**attrs: Rule attributes
86+
"""
87+
88+
# buildifier: disable=native-python
89+
native.py_test(**_add_tags(attrs))
90+
91+
def py_runtime(**attrs):
92+
"""See the Bazel core [py_runtime](https://docs.bazel.build/versions/master/be/python.html#py_runtime) documentation.
93+
94+
Args:
95+
**attrs: Rule attributes
96+
"""
97+
98+
# buildifier: disable=native-python
99+
native.py_runtime(**_add_tags(attrs))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.