From 7d27935be6ca350babca29c214833110a2964745 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Thu, 15 Oct 2026 18:14:48 -0700 Subject: [PATCH] Fix tf-text OSS nightly and presubmit builds against current tf-nightly. 1. When `IS_NIGHTLY=nightly`, `oss_scripts/configure.sh` runs `bazel run //oss_scripts/pip_package:requirements.update -- --upgrade` (`pip-compile`) on `@release_or_nightly//:requirements.in`. Because `tf-keras-nightly` on PyPI currently declares `Requires-Dist: tf-nightly~=2.21.0.dev` (with no other dependencies), `pip-compile` downgrades `tf-nightly` from `2.23.0.dev` back to `2.21.0.dev20260203` (Feb 2026). Subsequent `prepare_tf_dep.sh` then pins `@org_tensorflow` in `WORKSPACE` to that Feb 2026 commit, which predates `@rules_cc` in `tf_workspace3()` and breaks the build with `Failed to load Starlark extension '@@rules_cc//cc:extensions.bzl'`. - Exclude `tf-keras` from `@release_or_nightly//:requirements.in` in `py_deps_profile.bzl` (while keeping the `@release_or_nightly//:tf_keras_pkg` target alias and adding `IS_NIGHTLY` to `environ`). - Persist `HERMETIC_PYTHON_VERSION` and `IS_NIGHTLY` via `build --repo_env` in `oss_scripts/configure.sh` and append the latest `tf-keras-nightly` pin and sha256 hash from PyPI directly to `requirements_lock_.txt` after `requirements.update` so `pip_parse` still populates `@pypi_tf_keras_nightly`. 2. Add `common --features=-external_include_paths` and `common --host_features=-external_include_paths` in `oss_scripts/configure.sh` (matching TensorFlow `master`'s `.bazelrc`) so TFLite targets (`@@org_tensorflow//tensorflow/compiler/mlir/lite/schema:schema_utils`) build cleanly with the updated `rules_ml_toolchain` when `prepare_tf_dep.sh` pins `WORKSPACE` to a newer TensorFlow commit than `v2.22.0-rc0`. 3. Mark `tokenizers_benchmarks` and `ops_benchmarks` with `tags = ["manual"]` so `bazel test tensorflow_text:all` does not run them without `--benchmark_filter` and fail with `NO TESTS RAN` (exit code 5) under Python 3.12+. PiperOrigin-RevId: 1000522266 --- oss_scripts/configure.sh | 21 +++++++++++++++++++++ tensorflow_text/BUILD | 2 ++ third_party/bazel/py_deps_profile.bzl | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/oss_scripts/configure.sh b/oss_scripts/configure.sh index 29b26dfa9..3e6acf2ee 100755 --- a/oss_scripts/configure.sh +++ b/oss_scripts/configure.sh @@ -63,6 +63,8 @@ sed -i -e 's/build --noincompatible_remove_legacy_whole_archive//' .bazelrc write_to_bazelrc "build:manylinux2014 --config=release_cpu_linux" write_to_bazelrc "test --test_env=TF_USE_LEGACY_KERAS=1" +write_to_bazelrc "common --features=-external_include_paths" +write_to_bazelrc "common --host_features=-external_include_paths" if [ -z "$HERMETIC_PYTHON_VERSION" ]; then if [ -n "$PY_VERSION" ]; then @@ -73,9 +75,28 @@ if [ -z "$HERMETIC_PYTHON_VERSION" ]; then fi export HERMETIC_PYTHON_VERSION +if [[ -n "$HERMETIC_PYTHON_VERSION" ]]; then + write_to_bazelrc "build --repo_env=HERMETIC_PYTHON_VERSION=${HERMETIC_PYTHON_VERSION}" +fi +if [[ -n "$IS_NIGHTLY" ]]; then + write_to_bazelrc "build --repo_env=IS_NIGHTLY=${IS_NIGHTLY}" +fi + # Only auto-upgrade requirements for nightly. if [[ "$IS_NIGHTLY" == "nightly" ]]; then bazel run //oss_scripts/pip_package:requirements.update -- --upgrade + # Append tf-keras-nightly directly to the lockfile so its lagging + # Requires-Dist constraint on tf-nightly does not downgrade tf-nightly during + # pip-compile, while still providing @pypi_tf_keras_nightly for pip_parse. + $installed_python -c ' +import json, sys, urllib.request +lock_path, pkg = sys.argv[1], sys.argv[2] +data = json.loads(urllib.request.urlopen(f"https://pypi.org/pypi/{pkg}/json").read()) +ver = data["info"]["version"] +hashes = [" --hash=sha256:" + u["digests"]["sha256"] for u in data["urls"] if "sha256" in u.get("digests", {})] +with open(lock_path, "a") as f: + f.write(f"\n{pkg}=={ver} \\\n" + " \\\n".join(hashes) + "\n") +' "oss_scripts/pip_package/requirements_lock_${HERMETIC_PYTHON_VERSION//./_}.txt" "tf-keras-nightly" fi TF_ABIFLAG=$(bazel run //oss_scripts/pip_package:tensorflow_build_info -- abi) diff --git a/tensorflow_text/BUILD b/tensorflow_text/BUILD index 48ec8ef88..b41b5fdba 100644 --- a/tensorflow_text/BUILD +++ b/tensorflow_text/BUILD @@ -1711,6 +1711,7 @@ py_test( ":test_data_segmenter_hub_module", ], strict_deps = False, + tags = ["manual"], deps = [ ":benchmark_utils", ":ops", @@ -1729,6 +1730,7 @@ py_test( size = "medium", srcs = ["python/benchmarks/ops_benchmarks.py"], strict_deps = False, + tags = ["manual"], deps = [ ":benchmark_utils", ":ops", diff --git a/third_party/bazel/py_deps_profile.bzl b/third_party/bazel/py_deps_profile.bzl index 72d63240c..2f60d3487 100644 --- a/third_party/bazel/py_deps_profile.bzl +++ b/third_party/bazel/py_deps_profile.bzl @@ -13,8 +13,15 @@ def _py_deps_profile_impl(ctx): build_content = ['exports_files(["{}"])'.format(requirements_name)] for k, v in ctx.attr.deps_map.items(): repo_name = v[0] if is_switch else k - requirements_in_substitutions[k + "\n"] = repo_name + "\n" - requirements_in_substitutions[k + "\r\n"] = repo_name + "\r\n" + if k == "tf-keras": + # Exclude tf-keras / tf-keras-nightly from requirements.in so its + # lagging Requires-Dist on tensorflow / tf-nightly does not + # downgrade or block pip-compile during requirements.update. + requirements_in_substitutions[k + "\n"] = "" + requirements_in_substitutions[k + "\r\n"] = "" + else: + requirements_in_substitutions[k + "\n"] = repo_name + "\n" + requirements_in_substitutions[k + "\r\n"] = repo_name + "\r\n" aliased_targets = ["pkg"] + v[1:] norm_repo_name = repo_name.replace("-", "_") norm_alas_name = k.replace("-", "_") @@ -45,5 +52,8 @@ py_deps_profile = repository_rule( "pip_repo_name": attr.string(mandatory = True), "switch": attr.string_dict(mandatory = True), }, + environ = [ + "IS_NIGHTLY", + ], local = True, )