From 0b56f871d620371e1deb66822aa8fb6df68dc568 Mon Sep 17 00:00:00 2001
From: wangjiezhe <wangjiezhe@gmail.com>
Date: Fri, 22 Dec 2023 21:23:14 +0800
Subject: [PATCH 13/13] build: use non-hermetic python

---
 WORKSPACE                                     | 69 -------------------
 tensorflow/BUILD                              |  2 -
 tensorflow/compiler/mlir/glob_lit_test.bzl    |  1 -
 tensorflow/compiler/mlir/tfr/BUILD            |  2 -
 tensorflow/dtensor/python/tests/BUILD         |  1 -
 tensorflow/lite/python/BUILD                  |  1 -
 tensorflow/python/BUILD                       |  1 -
 tensorflow/python/autograph/converters/BUILD  | 11 ---
 tensorflow/python/autograph/core/BUILD        |  1 -
 tensorflow/python/autograph/pyct/BUILD        | 23 -------
 .../autograph/pyct/common_transformers/BUILD  |  2 -
 .../autograph/pyct/static_analysis/BUILD      |  6 --
 .../python/autograph/pyct/testing/BUILD       |  1 -
 tensorflow/python/client/BUILD                |  1 -
 tensorflow/python/compiler/tensorrt/BUILD     |  1 -
 .../experimental/kernel_tests/service/BUILD   |  1 -
 tensorflow/python/data/util/BUILD             |  2 -
 tensorflow/python/debug/lib/BUILD             |  1 -
 tensorflow/python/distribute/BUILD            |  5 --
 .../python/distribute/experimental/rpc/BUILD  |  1 -
 .../python/distribute/failure_handling/BUILD  |  2 -
 tensorflow/python/eager/BUILD                 |  2 -
 tensorflow/python/estimator/BUILD             |  4 +-
 tensorflow/python/framework/BUILD             |  7 --
 tensorflow/python/keras/BUILD                 |  1 -
 tensorflow/python/keras/engine/BUILD          |  1 -
 tensorflow/python/keras/saving/BUILD          |  1 -
 tensorflow/python/ops/BUILD                   |  2 -
 tensorflow/python/profiler/BUILD              |  1 -
 .../python/profiler/integration_test/BUILD    |  1 -
 tensorflow/python/summary/BUILD               |  1 -
 tensorflow/python/trackable/BUILD             |  1 -
 tensorflow/python/types/BUILD                 |  2 -
 tensorflow/python/util/BUILD                  |  3 -
 tensorflow/tools/docs/BUILD                   |  3 -
 third_party/xla/xla/glob_lit_test.bzl         |  5 --
 third_party/xla/xla/mlir_hlo/tests/BUILD      |  1 -
 37 files changed, 2 insertions(+), 169 deletions(-)

diff --git a/WORKSPACE b/WORKSPACE
index c10a2c4a482..3626ae4e805 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -11,75 +11,6 @@ http_archive(
     ],
 )
 
-# We must initialize hermetic python first.
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
-    name = "bazel_skylib",
-    sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
-    urls = [
-        "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
-        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
-    ],
-)
-
-http_archive(
-    name = "rules_python",
-    sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b",
-    strip_prefix = "rules_python-0.26.0",
-    url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz",
-)
-
-load("@rules_python//python:repositories.bzl", "py_repositories")
-
-py_repositories()
-
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
-load(
-    "//tensorflow/tools/toolchains/python:python_repo.bzl",
-    "python_repository",
-)
-
-python_repository(name = "python_version_repo")
-
-load("@python_version_repo//:py_version.bzl", "HERMETIC_PYTHON_VERSION")
-
-python_register_toolchains(
-    name = "python",
-    ignore_root_user_error = True,
-    python_version = HERMETIC_PYTHON_VERSION,
-)
-
-load("@python//:defs.bzl", "interpreter")
-load("@rules_python//python:pip.bzl", "package_annotation", "pip_parse")
-
-NUMPY_ANNOTATIONS = {
-    "numpy": package_annotation(
-        additive_build_content = """\
-filegroup(
-    name = "includes",
-    srcs = glob(["site-packages/numpy/core/include/**/*.h"]),
-)
-cc_library(
-    name = "numpy_headers",
-    hdrs = [":includes"],
-    strip_include_prefix="site-packages/numpy/core/include/",
-)
-""",
-    ),
-}
-
-pip_parse(
-    name = "pypi",
-    annotations = NUMPY_ANNOTATIONS,
-    python_interpreter_target = interpreter,
-    requirements = "//:requirements_lock_" + HERMETIC_PYTHON_VERSION.replace(".", "_") + ".txt",
-)
-
-load("@pypi//:requirements.bzl", "install_deps")
-
-install_deps()
-
 # Initialize the TensorFlow repository and all dependencies.
 #
 # The cascade of load() statements and tf_workspace?() calls works around the
diff --git a/tensorflow/BUILD b/tensorflow/BUILD
index ffbe65fdc61..cd9d61797e8 100644
--- a/tensorflow/BUILD
+++ b/tensorflow/BUILD
@@ -1712,8 +1712,6 @@ py_library(
         "//tensorflow/lite/python:lite",
         "//tensorflow/lite/python/authoring",
         "//tensorflow/python:no_contrib",
-        "@pypi_keras//:pkg",
-        "@pypi_tensorboard//:pkg",
     ],
 )
 # copybara:comment_end
diff --git a/tensorflow/compiler/mlir/glob_lit_test.bzl b/tensorflow/compiler/mlir/glob_lit_test.bzl
index e689b4c0b31..f65c86b727b 100644
--- a/tensorflow/compiler/mlir/glob_lit_test.bzl
+++ b/tensorflow/compiler/mlir/glob_lit_test.bzl
@@ -58,7 +58,6 @@ def _run_lit_test(name, data, size, tags, driver, features, exec_properties):
             "@llvm-project//llvm:count",
             "@llvm-project//llvm:not",
         ],
-        deps = ["@pypi_lit//:pkg"],
         size = size,
         main = "lit.py",
         exec_properties = exec_properties,
diff --git a/tensorflow/compiler/mlir/tfr/BUILD b/tensorflow/compiler/mlir/tfr/BUILD
index f8dfcd1c0a6..9f13d2eb068 100644
--- a/tensorflow/compiler/mlir/tfr/BUILD
+++ b/tensorflow/compiler/mlir/tfr/BUILD
@@ -387,7 +387,6 @@ py_strict_library(
         "//tensorflow/python/framework:op_def_registry",
         "//tensorflow/python/platform:tf_logging",
         "//tensorflow/python/util:tf_inspect",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -421,7 +420,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:transpiler",
         "//tensorflow/python/framework:op_def_registry",
         "//tensorflow/python/util:tf_inspect",
-        "@pypi_gast//:pkg",
     ],
 )
 
diff --git a/tensorflow/dtensor/python/tests/BUILD b/tensorflow/dtensor/python/tests/BUILD
index 498642cb5ff..e4482821869 100644
--- a/tensorflow/dtensor/python/tests/BUILD
+++ b/tensorflow/dtensor/python/tests/BUILD
@@ -326,7 +326,6 @@ pytype_strict_library(
         ":test_util",
         "//tensorflow/python/platform:client_testlib",
         "@absl_py//absl/flags",
-        "@pypi_portpicker//:pkg",
     ],
 )
 
diff --git a/tensorflow/lite/python/BUILD b/tensorflow/lite/python/BUILD
index 3ac3bb20eba..c37bbc385f1 100644
--- a/tensorflow/lite/python/BUILD
+++ b/tensorflow/lite/python/BUILD
@@ -310,7 +310,6 @@ py_strict_test(
         "//tensorflow/python/trackable:autotrackable",
         "//third_party/py/numpy",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_jax//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/BUILD b/tensorflow/python/BUILD
index 9810f8acd2e..056534591a3 100644
--- a/tensorflow/python/BUILD
+++ b/tensorflow/python/BUILD
@@ -589,7 +589,6 @@ py_strict_library(
     deps = [
         ":keras_lib",
         "//third_party/py/numpy",
-        "@pypi_scipy//:pkg",
         "@six_archive//:six",
     ],
 )
diff --git a/tensorflow/python/autograph/converters/BUILD b/tensorflow/python/autograph/converters/BUILD
index 5624f7611f3..11bc2cd9deb 100644
--- a/tensorflow/python/autograph/converters/BUILD
+++ b/tensorflow/python/autograph/converters/BUILD
@@ -13,7 +13,6 @@ py_strict_library(
         "//tensorflow/python/autograph/core:converter",
         "//tensorflow/python/autograph/lang:directives",
         "//tensorflow/python/autograph/pyct:templates",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -39,7 +38,6 @@ py_strict_library(
         "//tensorflow/python/autograph/core:converter",
         "//tensorflow/python/autograph/pyct:parser",
         "//tensorflow/python/autograph/pyct:templates",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -65,7 +63,6 @@ py_strict_library(
         "//tensorflow/python/autograph/core:converter",
         "//tensorflow/python/autograph/pyct:parser",
         "//tensorflow/python/autograph/pyct:templates",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -80,7 +77,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:qual_names",
         "//tensorflow/python/autograph/pyct:templates",
         "//tensorflow/python/autograph/utils:ag_logging",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -93,7 +89,6 @@ py_strict_library(
         "//tensorflow/python/autograph/lang:directives",
         "//tensorflow/python/autograph/pyct:anno",
         "//tensorflow/python/util:tf_inspect",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -105,7 +100,6 @@ py_strict_library(
         "//tensorflow/python/autograph/core:converter",
         "//tensorflow/python/autograph/pyct:anno",
         "//tensorflow/python/autograph/pyct:templates",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -127,7 +121,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct/static_analysis:liveness",
         "//tensorflow/python/autograph/pyct/static_analysis:reaching_definitions",
         "//tensorflow/python/autograph/pyct/static_analysis:reaching_fndefs",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -143,7 +136,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:templates",
         "//tensorflow/python/autograph/pyct/static_analysis:activity",
         "//tensorflow/python/autograph/pyct/static_analysis:annos",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -160,7 +152,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:templates",
         "//tensorflow/python/autograph/pyct/static_analysis:activity",
         "//tensorflow/python/autograph/pyct/static_analysis:annos",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -176,7 +167,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:templates",
         "//tensorflow/python/autograph/pyct/static_analysis:activity",
         "//tensorflow/python/autograph/pyct/static_analysis:annos",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -187,7 +177,6 @@ py_strict_library(
     deps = [
         "//tensorflow/python/autograph/core:converter",
         "//tensorflow/python/autograph/pyct:templates",
-        "@pypi_gast//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/autograph/core/BUILD b/tensorflow/python/autograph/core/BUILD
index 46983ab39f0..3ccdc20293c 100644
--- a/tensorflow/python/autograph/core/BUILD
+++ b/tensorflow/python/autograph/core/BUILD
@@ -37,7 +37,6 @@ py_strict_library(
     visibility = ["//tensorflow:__subpackages__"],
     deps = [
         "//tensorflow/python/autograph/pyct:errors",
-        "@pypi_gast//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/autograph/pyct/BUILD b/tensorflow/python/autograph/pyct/BUILD
index 949d841e00c..31d4b026460 100644
--- a/tensorflow/python/autograph/pyct/BUILD
+++ b/tensorflow/python/autograph/pyct/BUILD
@@ -14,7 +14,6 @@ py_strict_library(
         ":ast_util",
         ":parser",
         ":qual_names",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -32,7 +31,6 @@ py_strict_library(
         ":templates",
         ":transformer",
         "//tensorflow/python/autograph/utils:ag_logging",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -44,7 +42,6 @@ py_strict_library(
         ":anno",
         ":parser",
         ":qual_names",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -62,7 +59,6 @@ py_strict_library(
     name = "gast_util",
     srcs = ["gast_util.py"],
     visibility = ["//visibility:public"],
-    deps = ["@pypi_gast//:pkg"],
 )
 
 py_strict_library(
@@ -79,8 +75,6 @@ py_strict_library(
         ":errors",
         ":inspect_utils",
         "//tensorflow/python/util:tf_inspect",
-        "@pypi_astunparse//:pkg",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -108,7 +102,6 @@ py_strict_library(
         ":parser",
         ":pretty_printer",
         "//tensorflow/python/util:tf_inspect",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -116,7 +109,6 @@ py_strict_library(
     name = "anno",
     srcs = ["anno.py"],
     visibility = ["//visibility:public"],
-    deps = ["@pypi_gast//:pkg"],
 )
 
 py_strict_library(
@@ -134,7 +126,6 @@ py_strict_library(
         ":parser",
         ":pretty_printer",
         ":templates",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -145,7 +136,6 @@ py_strict_library(
     deps = [
         ":anno",
         ":parser",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -155,8 +145,6 @@ py_strict_library(
     visibility = ["//visibility:public"],
     deps = [
         ":anno",
-        "@pypi_astunparse//:pkg",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -180,10 +168,6 @@ py_strict_library(
     name = "pretty_printer",
     srcs = ["pretty_printer.py"],
     visibility = ["//visibility:public"],
-    deps = [
-        "@pypi_gast//:pkg",
-        "@pypi_termcolor//:pkg",
-    ],
 )
 
 py_strict_test(
@@ -210,7 +194,6 @@ py_strict_test(
         ":pretty_printer",
         ":qual_names",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -234,7 +217,6 @@ py_strict_test(
         ":cfg",
         ":parser",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -250,7 +232,6 @@ py_strict_test(
         ":pretty_printer",
         "//tensorflow/python/platform:client_testlib",
         "//tensorflow/python/util:tf_inspect",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -325,7 +306,6 @@ py_strict_test(
         ":parser",
         ":pretty_printer",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -365,7 +345,6 @@ py_strict_test(
         ":templates",
         "//tensorflow/python/platform:client_testlib",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -380,7 +359,6 @@ py_strict_test(
         ":parser",
         ":transformer",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -393,6 +371,5 @@ py_strict_test(
         ":transformer",
         ":transpiler",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
diff --git a/tensorflow/python/autograph/pyct/common_transformers/BUILD b/tensorflow/python/autograph/pyct/common_transformers/BUILD
index 2be00498cf7..b9da2f210c9 100644
--- a/tensorflow/python/autograph/pyct/common_transformers/BUILD
+++ b/tensorflow/python/autograph/pyct/common_transformers/BUILD
@@ -16,7 +16,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:gast_util",
         "//tensorflow/python/autograph/pyct:templates",
         "//tensorflow/python/autograph/pyct:transformer",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -32,6 +31,5 @@ py_strict_test(
         "//tensorflow/python/autograph/pyct:parser",
         "//tensorflow/python/autograph/pyct:transformer",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
diff --git a/tensorflow/python/autograph/pyct/static_analysis/BUILD b/tensorflow/python/autograph/pyct/static_analysis/BUILD
index 4329523b056..9c643ccd63c 100644
--- a/tensorflow/python/autograph/pyct/static_analysis/BUILD
+++ b/tensorflow/python/autograph/pyct/static_analysis/BUILD
@@ -14,7 +14,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:anno",
         "//tensorflow/python/autograph/pyct:cfg",
         "//tensorflow/python/autograph/pyct:transformer",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -26,7 +25,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:anno",
         "//tensorflow/python/autograph/pyct:cfg",
         "//tensorflow/python/autograph/pyct:transformer",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -56,7 +54,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:anno",
         "//tensorflow/python/autograph/pyct:qual_names",
         "//tensorflow/python/autograph/pyct:transformer",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -71,7 +68,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:cfg",
         "//tensorflow/python/autograph/pyct:qual_names",
         "//tensorflow/python/autograph/pyct:transformer",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -83,7 +79,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct:anno",
         "//tensorflow/python/autograph/pyct:cfg",
         "//tensorflow/python/autograph/pyct:transformer",
-        "@pypi_gast//:pkg",
     ],
 )
 
@@ -107,7 +102,6 @@ py_strict_test(
         "//tensorflow/python/autograph/pyct:qual_names",
         "//tensorflow/python/autograph/pyct:transformer",
         "//tensorflow/python/platform:client_testlib",
-        "@pypi_gast//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/autograph/pyct/testing/BUILD b/tensorflow/python/autograph/pyct/testing/BUILD
index 21a6775b0fb..fcac2065ca0 100644
--- a/tensorflow/python/autograph/pyct/testing/BUILD
+++ b/tensorflow/python/autograph/pyct/testing/BUILD
@@ -15,7 +15,6 @@ py_strict_library(
     deps = [
         "//tensorflow/python/autograph/pyct:templates",
         "//third_party/py/numpy",
-        "@pypi_gast//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/client/BUILD b/tensorflow/python/client/BUILD
index c13a6122f41..77bc522a758 100644
--- a/tensorflow/python/client/BUILD
+++ b/tensorflow/python/client/BUILD
@@ -294,7 +294,6 @@ py_strict_library(
         "//tensorflow/python/util:nest",
         "//tensorflow/python/util:tf_export",
         "//third_party/py/numpy",
-        "@pypi_wrapt//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/compiler/tensorrt/BUILD b/tensorflow/python/compiler/tensorrt/BUILD
index f3ca24c9a4b..ee086bdaed2 100644
--- a/tensorflow/python/compiler/tensorrt/BUILD
+++ b/tensorflow/python/compiler/tensorrt/BUILD
@@ -69,7 +69,6 @@ py_strict_library(
         "//tensorflow/python/util:nest",
         "//tensorflow/python/util:tf_export",
         "//third_party/py/numpy",
-        "@pypi_packaging//:pkg",
         "@six_archive//:six",
     ],
 )
diff --git a/tensorflow/python/data/experimental/kernel_tests/service/BUILD b/tensorflow/python/data/experimental/kernel_tests/service/BUILD
index cfac30fe0db..355a558bc93 100644
--- a/tensorflow/python/data/experimental/kernel_tests/service/BUILD
+++ b/tensorflow/python/data/experimental/kernel_tests/service/BUILD
@@ -143,7 +143,6 @@ tf_py_strict_test(
         "//tensorflow/python/ops:array_ops",
         "//tensorflow/python/platform:client_testlib",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_portpicker//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/data/util/BUILD b/tensorflow/python/data/util/BUILD
index f7298a6f66b..cef29c3d992 100644
--- a/tensorflow/python/data/util/BUILD
+++ b/tensorflow/python/data/util/BUILD
@@ -94,7 +94,6 @@ py_strict_library(
         "//tensorflow/python/util:deprecation",
         "//tensorflow/python/util:nest_util",
         "//tensorflow/python/util:tf_export",
-        "@pypi_wrapt//:pkg",
     ],
 )
 
@@ -125,7 +124,6 @@ py_strict_test(
         "//tensorflow/python/util:compat",
         "//third_party/py/numpy",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_wrapt//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/debug/lib/BUILD b/tensorflow/python/debug/lib/BUILD
index 37c99b30dd2..012e349dffc 100644
--- a/tensorflow/python/debug/lib/BUILD
+++ b/tensorflow/python/debug/lib/BUILD
@@ -596,7 +596,6 @@ py_strict_library(
         "//tensorflow/python/lib/io:lib",
         "//tensorflow/python/ops:variables",
         "//tensorflow/python/util:compat",
-        "@pypi_portpicker//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/distribute/BUILD b/tensorflow/python/distribute/BUILD
index 0c233b2b4a4..19b496f427a 100644
--- a/tensorflow/python/distribute/BUILD
+++ b/tensorflow/python/distribute/BUILD
@@ -523,7 +523,6 @@ cuda_py_strict_test(
         "//tensorflow/python/ops:variable_scope",
         "//third_party/py/numpy",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_dill//:pkg",  # build_cleaner: keep
     ],
 )
 
@@ -1440,7 +1439,6 @@ cuda_py_strict_test(
         "//tensorflow/python/ops:math_ops",
         "//tensorflow/python/util:nest",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_dill//:pkg",  # build_cleaner: keep
     ],
 )
 
@@ -1764,7 +1762,6 @@ distribute_py_strict_test(
         "//tensorflow/python/ops:variable_v1",
         "//tensorflow/python/saved_model/model_utils:mode_keys",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_wrapt//:pkg",
     ],
 )
 
@@ -2295,8 +2292,6 @@ py_strict_library(
         "//tensorflow/python/framework:test_lib",
         "//tensorflow/python/util:tf_export",
         "@absl_py//absl/logging",
-        "@pypi_dill//:pkg",  # build_cleaner: keep
-        "@pypi_tblib//:pkg",  # build_cleaner: keep
         "@six_archive//:six",
     ],
 )
diff --git a/tensorflow/python/distribute/experimental/rpc/BUILD b/tensorflow/python/distribute/experimental/rpc/BUILD
index 3a3682cd6cf..8ed343db636 100644
--- a/tensorflow/python/distribute/experimental/rpc/BUILD
+++ b/tensorflow/python/distribute/experimental/rpc/BUILD
@@ -60,6 +60,5 @@ tf_py_strict_test(
         "//tensorflow/python/ops:variables",
         "//tensorflow/python/platform:client_testlib",
         "//tensorflow/python/util:nest",
-        "@pypi_portpicker//:pkg",
     ],
 )
diff --git a/tensorflow/python/distribute/failure_handling/BUILD b/tensorflow/python/distribute/failure_handling/BUILD
index c9af884fbb7..3aaad5eced1 100644
--- a/tensorflow/python/distribute/failure_handling/BUILD
+++ b/tensorflow/python/distribute/failure_handling/BUILD
@@ -47,7 +47,6 @@ py_strict_library(
     deps = [
         "//tensorflow/python/eager:context",
         "//tensorflow/python/platform:tf_logging",
-        "@pypi_requests//:pkg",
         "@six_archive//:six",
     ],
 )
@@ -134,7 +133,6 @@ tf_py_strict_test(
         "//tensorflow/python/platform:tf_logging",
         "//tensorflow/python/training:server_lib",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_dill//:pkg",  # build_cleaner: keep
     ],
 )
 
diff --git a/tensorflow/python/eager/BUILD b/tensorflow/python/eager/BUILD
index e72f54c48fd..057bce876fd 100644
--- a/tensorflow/python/eager/BUILD
+++ b/tensorflow/python/eager/BUILD
@@ -1180,7 +1180,6 @@ cuda_py_strict_test(
         "//tensorflow/python/training:server_lib",
         "//tensorflow/python/util:compat",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_portpicker//:pkg",
     ],
 )
 
@@ -1320,7 +1319,6 @@ py_strict_library(
         "//tensorflow/python/autograph/pyct/static_analysis:reaching_fndefs",
         "//tensorflow/python/framework:op_def_registry",
         "//tensorflow/python/framework:ops",
-        "@pypi_gast//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/estimator/BUILD b/tensorflow/python/estimator/BUILD
index 73afdd8b239..7e58789cee5 100644
--- a/tensorflow/python/estimator/BUILD
+++ b/tensorflow/python/estimator/BUILD
@@ -382,7 +382,7 @@ py_library(
     ],
 )
 
-alias(
+py_library(
     name = "expect_tensorflow_estimator_installed",
-    actual = "@pypi_tensorflow_estimator//:pkg",
+    srcs_version = "PY3",
 )
diff --git a/tensorflow/python/framework/BUILD b/tensorflow/python/framework/BUILD
index 9bfb9d2d9dd..19b43eab9ac 100644
--- a/tensorflow/python/framework/BUILD
+++ b/tensorflow/python/framework/BUILD
@@ -279,7 +279,6 @@ py_strict_library(
         "//tensorflow/python/eager:execute",
         "//tensorflow/security/fuzzing/py:annotation_types",
         "//tensorflow/tools/docs:doc_controls",
-        "@pypi_typing_extensions//:pkg",
     ],
 )
 
@@ -365,7 +364,6 @@ py_strict_library(
         "//tensorflow/python/util:deprecation",
         "//tensorflow/python/util:tf_export",
         "//third_party/py/numpy",
-        "@pypi_packaging//:pkg",
     ] + if_xla_available([
         "//tensorflow/python:_pywrap_tfcompile",
     ]),
@@ -1760,7 +1758,6 @@ py_strict_library(
     deps = [
         ":composite_tensor",
         "//tensorflow/python/util:nest",
-        "@pypi_typing_extensions//:pkg",
     ],
 )
 
@@ -1788,7 +1785,6 @@ py_strict_library(
         "//tensorflow/python/util:nest",
         "//tensorflow/python/util:tf_decorator",
         "//tensorflow/python/util:tf_export",
-        "@pypi_typing_extensions//:pkg",
     ],
 )
 
@@ -1932,7 +1928,6 @@ pytype_strict_library(
         "//tensorflow/python/lib/io:lib",
         "//tensorflow/python/platform:tf_logging",
         "//tensorflow/python/util:compat",
-        "@pypi_packaging//:pkg",
     ],
 )
 
@@ -2185,7 +2180,6 @@ py_strict_library(
         "//tensorflow/python/util/protobuf",
         "//third_party/py/numpy",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_portpicker//:pkg",
     ],
 )
 
@@ -2781,7 +2775,6 @@ tf_py_strict_test(
         "//tensorflow/python/util:nest",
         "//tensorflow/python/util:tf_decorator",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_typing_extensions//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/keras/BUILD b/tensorflow/python/keras/BUILD
index f9e31edae67..011cc3a73b8 100755
--- a/tensorflow/python/keras/BUILD
+++ b/tensorflow/python/keras/BUILD
@@ -44,7 +44,6 @@ py_library(
         "//tensorflow/python/saved_model",
         "//tensorflow/python/training",
         "//tensorflow/python/util:nest",
-        "@pypi_h5py//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/keras/engine/BUILD b/tensorflow/python/keras/engine/BUILD
index a24dc27b25f..1b95ca18d06 100644
--- a/tensorflow/python/keras/engine/BUILD
+++ b/tensorflow/python/keras/engine/BUILD
@@ -95,7 +95,6 @@ py_library(
         "//tensorflow/python/util:tf_decorator",
         "//tensorflow/python/util:tf_export",
         "//tensorflow/tools/docs:doc_controls",
-        "@pypi_h5py//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/keras/saving/BUILD b/tensorflow/python/keras/saving/BUILD
index db1d2d814ca..b37abc164b3 100644
--- a/tensorflow/python/keras/saving/BUILD
+++ b/tensorflow/python/keras/saving/BUILD
@@ -55,6 +55,5 @@ py_library(
         "//tensorflow/python/platform:tf_logging",
         "//tensorflow/python/saved_model",
         "//tensorflow/python/training:saver",
-        "@pypi_h5py//:pkg",
     ],
 )
diff --git a/tensorflow/python/ops/BUILD b/tensorflow/python/ops/BUILD
index b3a3d612a01..c242923f832 100644
--- a/tensorflow/python/ops/BUILD
+++ b/tensorflow/python/ops/BUILD
@@ -2780,7 +2780,6 @@ py_strict_library(
         "//tensorflow/python/util:dispatch",
         "//tensorflow/python/util:tf_export",
         "//third_party/py/numpy",
-        "@pypi_opt_einsum//:pkg",
     ],
 )
 
@@ -3872,7 +3871,6 @@ cuda_py_strict_test(
         "//tensorflow/python/platform:tf_logging",
         "//third_party/py/numpy",
         "@absl_py//absl/testing:parameterized",
-        "@pypi_opt_einsum//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/profiler/BUILD b/tensorflow/python/profiler/BUILD
index b1cfd6ea10c..9413aeeab8b 100644
--- a/tensorflow/python/profiler/BUILD
+++ b/tensorflow/python/profiler/BUILD
@@ -43,7 +43,6 @@ cuda_py_strict_test(
         "//tensorflow/python/eager:test",
         "//tensorflow/python/framework:errors",
         "//tensorflow/python/framework:test_lib",
-        "@pypi_portpicker//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/profiler/integration_test/BUILD b/tensorflow/python/profiler/integration_test/BUILD
index b20698ea6ea..e7060e5a315 100644
--- a/tensorflow/python/profiler/integration_test/BUILD
+++ b/tensorflow/python/profiler/integration_test/BUILD
@@ -35,6 +35,5 @@ cuda_py_strict_test(
         "//tensorflow/python/platform:tf_logging",
         "//tensorflow/python/profiler:profiler_client",
         "//tensorflow/python/profiler:profiler_v2",
-        "@pypi_portpicker//:pkg",
     ],
 )
diff --git a/tensorflow/python/summary/BUILD b/tensorflow/python/summary/BUILD
index 126fb6d31f7..b292e39356f 100644
--- a/tensorflow/python/summary/BUILD
+++ b/tensorflow/python/summary/BUILD
@@ -121,6 +121,5 @@ tf_py_strict_test(
         "//tensorflow/python/ops:summary_ops_v2",
         "//tensorflow/python/platform:client_testlib",
         "//tensorflow/python/training:training_util",
-        "@pypi_tensorboard//:pkg",
     ],
 )
diff --git a/tensorflow/python/trackable/BUILD b/tensorflow/python/trackable/BUILD
index 30efc64b5fd..2e2390a6643 100644
--- a/tensorflow/python/trackable/BUILD
+++ b/tensorflow/python/trackable/BUILD
@@ -225,7 +225,6 @@ py_strict_library(
         "//tensorflow/python/ops:variables",
         "//tensorflow/python/util:compat",
         "//tensorflow/python/util:tf_export",
-        "@pypi_wrapt//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/types/BUILD b/tensorflow/python/types/BUILD
index c04dc039153..43a030a051e 100644
--- a/tensorflow/python/types/BUILD
+++ b/tensorflow/python/types/BUILD
@@ -24,7 +24,6 @@ pytype_strict_library(
         "//tensorflow/python/util:_pywrap_utils",
         "//tensorflow/python/util:tf_export",
         "//third_party/py/numpy",
-        "@pypi_typing_extensions//:pkg",
     ],
 )
 
@@ -71,7 +70,6 @@ pytype_strict_library(
         ":core",
         "//tensorflow/python/util:tf_export",
         "//tensorflow/tools/docs:doc_controls",
-        "@pypi_typing_extensions//:pkg",
     ],
 )
 
diff --git a/tensorflow/python/util/BUILD b/tensorflow/python/util/BUILD
index d1e7d626a1d..248eb23bcfe 100644
--- a/tensorflow/python/util/BUILD
+++ b/tensorflow/python/util/BUILD
@@ -732,7 +732,6 @@ py_strict_library(
         # py_test because not all tensorflow tests use tensorflow.bzl's py_test.
         "//tensorflow/python:global_test_configuration",
         "@six_archive//:six",
-        "@pypi_wrapt//:pkg",
         "//tensorflow/python:pywrap_tensorflow",
         ":_pywrap_utils",
     ],
@@ -893,7 +892,6 @@ py_strict_library(
         # py_test because not all tensorflow tests use tensorflow.bzl's py_test.
         "//tensorflow/python:global_test_configuration",
         "//third_party/py/numpy",
-        "@pypi_wrapt//:pkg",
     ],
 )
 
@@ -1029,7 +1027,6 @@ py_strict_library(
         # py_test because not all tensorflow tests use tensorflow.bzl's py_test.
         "//tensorflow/python:global_test_configuration",
         ":tf_export",
-        "@pypi_wrapt//:pkg",
         ":_pywrap_utils",
         ":_pywrap_nest",
     ],
diff --git a/tensorflow/tools/docs/BUILD b/tensorflow/tools/docs/BUILD
index aa9490cf911..48e45b23a2a 100644
--- a/tensorflow/tools/docs/BUILD
+++ b/tensorflow/tools/docs/BUILD
@@ -137,7 +137,6 @@ py_strict_library(
     srcs = ["fenced_doctest_lib.py"],
     deps = [
         ":tf_doctest_lib",
-        "@pypi_astor//:pkg",
     ],
 )
 
@@ -178,7 +177,6 @@ py_strict_test(
         # copybara:uncomment "//third_party/py/tensorflow:tensorflow_estimator",
         "//tensorflow:tensorflow_py",
         "//tensorflow/python/platform:test",
-        "@pypi_packaging//:pkg",
     ],
 )
 
@@ -214,7 +212,6 @@ py_strict_library(
         "//tensorflow/python/util:tf_inspect",
         "@absl_py//absl:app",
         "@absl_py//absl/flags",
-        "@pypi_packaging//:pkg",
     ],
 )
 
diff --git a/third_party/xla/xla/glob_lit_test.bzl b/third_party/xla/xla/glob_lit_test.bzl
index 79b4adc3edd..5893eba46c2 100644
--- a/third_party/xla/xla/glob_lit_test.bzl
+++ b/third_party/xla/xla/glob_lit_test.bzl
@@ -52,10 +52,6 @@ def _run_lit_test(name, data, size, tags, driver, features, exec_properties):
     # can remove this logic. This is necessary to have these tests run on builds
     # using Python 3.11, but also to not include `@pypi_lit` in standalone xla
     # builds where it won't be found.
-    deps = []
-    if xla_root_dir == "tensorflow/compiler/xla/":
-        deps.append("@pypi_lit//:pkg")
-
     native.py_test(
         name = name,
         srcs = ["@llvm-project//llvm:lit"],
@@ -69,7 +65,6 @@ def _run_lit_test(name, data, size, tags, driver, features, exec_properties):
             "@llvm-project//llvm:count",
             "@llvm-project//llvm:not",
         ],
-        deps = deps,
         size = size,
         main = "lit.py",
         exec_properties = exec_properties,
diff --git a/third_party/xla/xla/mlir_hlo/tests/BUILD b/third_party/xla/xla/mlir_hlo/tests/BUILD
index 89c6533956f..771d337be08 100644
--- a/third_party/xla/xla/mlir_hlo/tests/BUILD
+++ b/third_party/xla/xla/mlir_hlo/tests/BUILD
@@ -27,7 +27,6 @@ package(
         tags = [
             "nomsan",  # The execution engine doesn't work with msan, see b/248097619.
         ],
-        deps = ["@pypi_lit//:pkg"],
     )
     for src in glob(["**/*.mlir"])
 ]
-- 
2.41.0

