8000 refactor: move all re-exports to private/reexports.bzl · bazel-contrib/rules_python@9ddafd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ddafd0

Browse files
committed
refactor: move all re-exports to private/reexports.bzl
1 parent 5c6661e commit 9ddafd0

File tree

2 files changed

+69
-53
lines changed

2 files changed

+69
-53
lines changed

python/defs.bzl

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,22 @@ migrated to Starlark, their implementations will be moved here.
2121

2222
load("@bazel_tools//tools/python:srcs_version.bzl", _find_requirements = "find_requirements")
2323
load("@bazel_tools//tools/python:toolchain.bzl", _py_runtime_pair = "py_runtime_pair")
24-
load("//python/private:reexports.bzl", "internal_PyInfo", "internal_PyRuntimeInfo")
24+
load(
25+
"//python/private:reexports.bzl",
26+
"internal_PyInfo",
27+
"internal_PyRuntimeInfo",
28+
_py_binary = "py_binary",
29+
_py_library = "py_library",
30+
_py_runtime = "py_runtime",
31+
_py_test = "py_test",
32+
)
2533

2634
# Exports of native-defined providers.
2735

2836
PyInfo = internal_PyInfo
2937

3038
PyRuntimeInfo = internal_PyRuntimeInfo
3139

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

@@ -84,36 +80,6 @@ current_py_toolchain = rule(
8480
],
8581
)
8682

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

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

179135
py_runtime_pair = _py_runtime_pair
180136

181137
find_requirements = _find_requirements
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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ different name. Then we can load it from defs.bzl and export it there under
3333
the original name.
3434
"""
3535

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

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

0 commit comments

Comments
 (0)
0