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 702a5c5

Browse filesBrowse files
authored
refactor: move all re-exports to private/reexports.bzl (#739)
1 parent 4ae8f57 commit 702a5c5
Copy full SHA for 702a5c5

File tree

2 files changed

+75
-58
lines changed
Filter options

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,35 +12,28 @@
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")
21+
load(
22+
"//python/private:reexports.bzl",
23+
"internal_PyInfo",
24+
"internal_PyRuntimeInfo",
25+
_py_binary = "py_binary",
26+
_py_library = "py_library",
27+
_py_runtime = "py_runtime",
28+
_py_test = "py_test",
29+
)
2530

2631
# Exports of native-defined providers.
2732

2833
PyInfo = internal_PyInfo
2934

3035
PyRuntimeInfo = internal_PyRuntimeInfo
3136

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-
4437
def _current_py_toolchain_impl(ctx):
4538
toolchain = ctx.toolchains[ctx.attr._toolchain]
4639

@@ -84,36 +77,6 @@ current_py_toolchain = rule(
8477
],
8578
)
8679

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-
11780
def _py_import_impl(ctx):
11881
# See https://github.com/bazelbuild/bazel/blob/0.24.0/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java#L104 .
11982
import_paths = [
@@ -164,18 +127,16 @@ py_import = rule(
164127
},
165128
)
166129

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-
177130
# Re-exports of Starlark-defined symbols in @bazel_tools//tools/python.
178131

179132
py_runtime_pair = _py_runtime_pair
180133

181134
find_requirements = _find_requirements
135+
136+
py_library = _py_library
137+
138+
py_binary = _py_binary
139+
140+
py_test = _py_test
141+
142+
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.