From 1b412edc891b0d2cf98dbd2291d871d5ee67a0fb Mon Sep 17 00:00:00 2001 From: Lu Wang <luwa@google.com> Date: Mon, 15 Jun 2020 15:09:29 -0700 Subject: [PATCH] Create the script to generate TFLite Java API documentation. PiperOrigin-RevId: 316553983 Change-Id: I08888ba83f5335d38ba588ed632c2471dcfa2d9f --- tensorflow/lite/g3doc/tools/BUILD | 11 ++++ .../lite/g3doc/tools/build_java_api_docs.py | 66 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tensorflow/lite/g3doc/tools/build_java_api_docs.py diff --git a/tensorflow/lite/g3doc/tools/BUILD b/tensorflow/lite/g3doc/tools/BUILD index f2c6d8efedc..5c891a67128 100644 --- a/tensorflow/lite/g3doc/tools/BUILD +++ b/tensorflow/lite/g3doc/tools/BUILD @@ -13,3 +13,14 @@ py_binary( "@absl_py//absl/flags", ], ) + +py_binary( + name = "build_java_api_docs", + srcs = ["build_java_api_docs.py"], + python_version = "PY3", + srcs_version = "PY3", + deps = [ + "@absl_py//absl:app", + "@absl_py//absl/flags", + ], +) diff --git a/tensorflow/lite/g3doc/tools/build_java_api_docs.py b/tensorflow/lite/g3doc/tools/build_java_api_docs.py new file mode 100644 index 00000000000..9c598ad8ec5 --- /dev/null +++ b/tensorflow/lite/g3doc/tools/build_java_api_docs.py @@ -0,0 +1,66 @@ +# Lint as: python3 +# Copyright 2020 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. +# ============================================================================== +"""Generate TensorFlow Lite Java reference docs for TensorFlow.org.""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import pathlib +import shutil +import tempfile + +from absl import app +from absl import flags + +from tensorflow_docs.api_generator import gen_java + +FLAGS = flags.FLAGS + +# These flags are required by infrastructure, not all of them are used. +flags.DEFINE_string('output_dir', '/tmp/lite_api/', + ("Use this branch as the root version and don't" + ' create in version directory')) + +flags.DEFINE_string('site_path', 'lite/api_docs/java', + 'Path prefix in the _toc.yaml') + +flags.DEFINE_string('code_url_prefix', None, + '[UNUSED] The url prefix for links to code.') + +flags.DEFINE_bool( + 'search_hints', True, + '[UNUSED] Include metadata search hints in the generated files') + +# __file__ is the path to this file +DOCS_TOOLS_DIR = pathlib.Path(__file__).resolve().parent +TENSORFLOW_ROOT = DOCS_TOOLS_DIR.parents[3] +SOURCE_PATH = TENSORFLOW_ROOT / 'tensorflow/lite/java/src/main/java/' + + +def main(unused_argv): + merged_source = pathlib.Path(tempfile.mkdtemp()) + shutil.copytree(SOURCE_PATH, merged_source / 'java') + + gen_java.gen_java_docs( + package='org.tensorflow.lite', + source_path=merged_source / 'java', + output_dir=pathlib.Path(FLAGS.output_dir), + site_path=pathlib.Path(FLAGS.site_path)) + + +if __name__ == '__main__': + flags.mark_flags_as_required(['output_dir']) + app.run(main)