12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
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.
20
17
"""
21
18
22
19
load ("@bazel_tools//tools/python:srcs_version.bzl" , _find_requirements = "find_requirements" )
23
20
load ("@bazel_tools//tools/python:toolchain.bzl" , _py_runtime_pair = "py_runtime_pair" )
24
- load ("//python/private:reexports.bzl" , "internal_PyInfo" , "internal_PyRuntimeInfo" )
25
21
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
+ )
26
31
27
32
# Exports of native-defined providers.
28
33
29
34
PyInfo = internal_PyInfo
30
35
31
36
PyRuntimeInfo = internal_PyRuntimeInfo
32
37
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
-
45
38
def _current_py_toolchain_impl (ctx ):
46
39
toolchain = ctx .toolchains [ctx .attr ._toolchain ]
47
40
@@ -85,36 +78,6 @@ current_py_toolchain = rule(
85
78
],
86
79
)
87
80
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
-
118
81
def _py_import_impl (ctx ):
119
82
# See https://github.com/bazelbuild/bazel/blob/0.24.0/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java#L104 .
120
83
import_paths = [
@@ -165,20 +128,18 @@ py_import = rule(
165
128
},
166
129
)
167
130
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
-
178
131
# Re-exports of Starlark-defined symbols in @bazel_tools//tools/python.
179
132
180
133
py_runtime_pair = _py_runtime_pair
181
134
182
135
find_requirements = _find_requirements
183
136
184
137
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
0 commit comments