|
1 | 1 | """ |
2 | 2 | Build rule for open source tf.text libraries. |
3 | 3 | """ |
| 4 | +load("@rules_python//python:py_library.bzl", "py_library") |
| 5 | + |
4 | 6 |
|
5 | 7 | def py_tf_text_library( |
6 | 8 | name, |
@@ -85,7 +87,7 @@ def py_tf_text_library( |
85 | 87 | }), |
86 | 88 | ) |
87 | 89 |
|
88 | | - native.py_library( |
| 90 | + py_library( |
89 | 91 | name = name, |
90 | 92 | srcs = srcs, |
91 | 93 | srcs_version = "PY2AND3", |
@@ -139,6 +141,12 @@ def tf_cc_library( |
139 | 141 | oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/time") |
140 | 142 | oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/types:variant") |
141 | 143 | oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/functional:any_invocable") |
| 144 | + oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/log:check") |
| 145 | + oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/log:log") |
| 146 | + oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/log:absl_check") |
| 147 | + oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/log:absl_log") |
| 148 | + oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/container:btree") |
| 149 | + oss_deps = oss_deps + _dedupe(deps, "@com_google_absl//absl/container:flat_hash_set") |
142 | 150 | deps += select({ |
143 | 151 | "@org_tensorflow//tensorflow:mobile": [ |
144 | 152 | "@org_tensorflow//tensorflow/core:portable_tensorflow_lib_lite", |
@@ -227,49 +235,3 @@ def extra_py_deps(): |
227 | 235 | "@pypi_tensorflow_datasets//:pkg", |
228 | 236 | "@pypi_tensorflow_metadata//:pkg", |
229 | 237 | ] |
230 | | - |
231 | | -def _py_deps_profile_impl(ctx): |
232 | | - is_switch = False |
233 | | - for var_name, var_val in ctx.attr.switch.items(): |
234 | | - is_switch = is_switch or ctx.os.environ.get(var_name, "") == var_val |
235 | | - |
236 | | - prefix = ctx.attr.pip_repo_name |
237 | | - reqirements_name = ctx.attr.requirements_in.name |
238 | | - requirements_in_substitutions = {} |
239 | | - build_content = ['exports_files(["{}"])'.format(reqirements_name)] |
240 | | - for k, v in ctx.attr.deps_map.items(): |
241 | | - repo_name = v[0] if is_switch else k |
242 | | - requirements_in_substitutions[k + "\n"] = repo_name + "\n" |
243 | | - requirements_in_substitutions[k + "\r\n"] = repo_name + "\r\n" |
244 | | - aliased_targets = ["pkg"] + v[1:] |
245 | | - norm_repo_name = repo_name.replace("-", "_") |
246 | | - norm_alas_name = k.replace("-", "_") |
247 | | - for target in aliased_targets: |
248 | | - alias_name = "{}_{}".format(norm_alas_name, target) |
249 | | - alias_value = "@{}_{}//:{}".format(prefix, norm_repo_name, target) |
250 | | - build_content.append(""" |
251 | | -alias( |
252 | | - name = "{}", |
253 | | - actual = "{}", |
254 | | - visibility = ["//visibility:public"] |
255 | | -) |
256 | | -""".format(alias_name, alias_value)) |
257 | | - |
258 | | - ctx.file("BUILD", "".join(build_content)) |
259 | | - ctx.template( |
260 | | - reqirements_name, |
261 | | - ctx.attr.requirements_in, |
262 | | - executable = False, |
263 | | - substitutions = requirements_in_substitutions, |
264 | | - ) |
265 | | - |
266 | | -py_deps_profile = repository_rule( |
267 | | - implementation = _py_deps_profile_impl, |
268 | | - attrs = { |
269 | | - "requirements_in": attr.label(mandatory = True), |
270 | | - "deps_map": attr.string_list_dict(mandatory = True), |
271 | | - "pip_repo_name": attr.string(mandatory = True), |
272 | | - "switch": attr.string_dict(mandatory = True), |
273 | | - }, |
274 | | - local = True, |
275 | | -) |
0 commit comments