# Copyright 2026 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

# Description:
# Scripts used to generate TensorFlow Python API.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@xla//third_party/rules_python/python:py_library.bzl", "py_library")
load("//tensorflow:tensorflow.bzl", "py_test")
load("//tensorflow/python/tools/api/generator:api_gen.bzl", "TENSORFLOW_API_GEN_PACKAGES")
load("//tensorflow/python/tools/api/generator:api_init_files.bzl", "KERAS_API_INIT_FILES", "TENSORFLOW_API_INIT_FILES")
load("//tensorflow/python/tools/api/generator:api_init_files_v1.bzl", "KERAS_API_INIT_FILES_V1", "TENSORFLOW_API_INIT_FILES_V1")

package(
    # copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
    licenses = ["notice"],
)

exports_files(
    [
        "create_python_api.py",
    ],
)

py_library(
    name = "create_python_api",
    srcs = ["create_python_api.py"],
    strict_deps = True,
    visibility = ["//visibility:public"],
    deps = [
        ":doc_srcs",
        "//tensorflow/python/util:tf_decorator_py",
        "//tensorflow/python/util:tf_export",
    ],
)

py_library(
    name = "doc_srcs",
    srcs = ["doc_srcs.py"],
    strict_deps = True,
    visibility = ["//visibility:public"],
    deps = [
        "//tensorflow/python/util:tf_export",
    ],
)

py_test(
    name = "create_python_api_test",
    srcs = ["create_python_api_test.py"],
    strict_deps = True,
    deps = [
        ":create_python_api",
        # copybara:uncomment "//third_party/py/google/protobuf:use_fast_cpp_protos",
        "//tensorflow/python/platform:client_testlib",
        "//tensorflow/python/util:tf_decorator_py",
        "//tensorflow/python/util:tf_export",
    ],
)

py_test(
    name = "tensorflow_doc_srcs_test",
    srcs = ["doc_srcs_test.py"],
    args = [
        "--package=tensorflow.python",
        "--api_name=tensorflow",
    ] + KERAS_API_INIT_FILES + KERAS_API_INIT_FILES_V1 + TENSORFLOW_API_INIT_FILES + TENSORFLOW_API_INIT_FILES_V1,
    main = "doc_srcs_test.py",
    strict_deps = True,
    deps = [
        ":doc_srcs",
        # copybara:uncomment "//third_party/py/google/protobuf:use_fast_cpp_protos",
        "//tensorflow/python:no_contrib",
        "//tensorflow/python/platform:client_testlib",
    ],
)

py_test(
    name = "output_init_files_test",
    srcs = ["output_init_files_test.py"],
    args = [
        "--packages=" + ",".join(TENSORFLOW_API_GEN_PACKAGES),
    ],
    data = [
        "api_init_files.bzl",
        "api_init_files_v1.bzl",
    ],
    strict_deps = True,
    tags = [
        "no_pip",
    ],
    deps = [
        # copybara:uncomment "//third_party/py/google/protobuf:use_fast_cpp_protos",
        "//tensorflow/dtensor/python:dtensor",
        "//tensorflow/lite/python:analyzer",
        "//tensorflow/lite/python:lite",
        "//tensorflow/lite/python/authoring",
        "//tensorflow/python:modules_with_exports",
        "//tensorflow/python/platform:client_testlib",
        "//tensorflow/python/platform:resource_loader",
        "//tensorflow/python/util:tf_decorator_py",
    ],
)

bzl_library(
    name = "api_init_files",
    srcs = ["api_init_files.bzl"],
    visibility = ["//tensorflow/python/tools/api/generator2:__subpackages__"],
)
