Skip to content

Commit 5e7c66a

Browse files
authored
Add docs generation script. (#192)
* Add docs generation script. * overlay files from tensorflow-core-api/src/gen/java/org/tensorflow
1 parent 61b9165 commit 5e7c66a

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tools/build_java_api_docs.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Lint as: python3
2+
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
"""Generate TensorFlow Lite Java reference docs for TensorFlow.org."""
17+
from __future__ import absolute_import
18+
from __future__ import division
19+
from __future__ import print_function
20+
21+
import pathlib
22+
import shutil
23+
import tempfile
24+
25+
from absl import app
26+
from absl import flags
27+
28+
from tensorflow_docs.api_generator import gen_java
29+
30+
FLAGS = flags.FLAGS
31+
32+
# These flags are required by infrastructure, not all of them are used.
33+
flags.DEFINE_string('output_dir', '/tmp/java_api/',
34+
("Use this branch as the root version and don't"
35+
' create in version directory'))
36+
37+
flags.DEFINE_string('site_path', 'java/api_docs/java',
38+
'Path prefix in the _toc.yaml')
39+
40+
flags.DEFINE_string('code_url_prefix', None,
41+
'[UNUSED] The url prefix for links to code.')
42+
43+
flags.DEFINE_bool(
44+
'search_hints', True,
45+
'[UNUSED] Include metadata search hints in the generated files')
46+
47+
# __file__ is the path to this file
48+
TOOLS_DIR = pathlib.Path(__file__).resolve().parent
49+
REPO_ROOT = TOOLS_DIR.parent
50+
51+
def overlay(from_root, to_root):
52+
for from_path in pathlib.Path(from_root).rglob('*'):
53+
relpath = from_path.relative_to(from_root)
54+
to_path = to_root/relpath
55+
if from_path.is_file():
56+
assert not to_path.exists()
57+
shutil.copyfile(from_path, to_path)
58+
else:
59+
to_path.mkdir(exist_ok=True)
60+
61+
def main(unused_argv):
62+
merged_source = pathlib.Path(tempfile.mkdtemp())
63+
(merged_source / 'java/org').mkdir(parents=True)
64+
65+
shutil.copytree(REPO_ROOT/'tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/',
66+
merged_source/'java/org/tensorflow')
67+
overlay(REPO_ROOT/'tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow',
68+
merged_source/'java/org/tensorflow')
69+
shutil.copytree(REPO_ROOT/'tensorflow-framework/src/main/java/org/tensorflow/framework',
70+
merged_source/'java/org/tensorflow/framework')
71+
shutil.copytree(REPO_ROOT/'ndarray/src/main/java/org/tensorflow/ndarray',
72+
merged_source/'java/org/tensorflow/ndarray')
73+
74+
gen_java.gen_java_docs(
75+
package='org.tensorflow',
76+
source_path=merged_source / 'java',
77+
output_dir=pathlib.Path(FLAGS.output_dir),
78+
site_path=pathlib.Path(FLAGS.site_path))
79+
80+
81+
if __name__ == '__main__':
82+
flags.mark_flags_as_required(['output_dir'])
83+
app.run(main)

0 commit comments

Comments
 (0)