-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathbuild_docs.py
More file actions
113 lines (88 loc) · 3.36 KB
/
build_docs.py
File metadata and controls
113 lines (88 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# coding=utf-8
# Copyright 2026 TF.Text Authors.
#
# 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.
# Copyright 2024 TF.Text Authors.
#
# 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.
r"""Tool to generate external api_docs.
python build_docs.py --output_dir=/tmp/text_api
"""
import os
from absl import app
from absl import flags
import tensorflow as tf
from tensorflow_docs.api_generator import doc_controls
from tensorflow_docs.api_generator import generate_lib
from tensorflow_docs.api_generator import public_api
import tensorflow_text as text
PROJECT_SHORT_NAME = "text"
PROJECT_FULL_NAME = "TensorFlow Text"
FLAGS = flags.FLAGS
flags.DEFINE_string(
"output_dir",
default="/tmp/text_api",
help="Where to write the resulting docs to.")
flags.DEFINE_string(
"code_url_prefix",
"http://github.com/tensorflow/text/blob/master/tensorflow_text",
"The url prefix for links to code.")
flags.DEFINE_bool("search_hints", True,
"Include metadata search hints in the generated files")
flags.DEFINE_string("site_path", "/text/api_docs/python",
"Path prefix in the _toc.yaml")
def _hide_layer_and_module_methods():
"""Hide methods and properties defined in the base classes of keras layers."""
# __dict__ only sees attributes defined in *this* class, not on parent classes
# Needed to ignore redudant subclass documentation
module_contents = list(tf.Module.__dict__.items())
layer_contents = list(tf.keras.layers.Layer.__dict__.items())
for name, obj in module_contents + layer_contents:
if name == "__init__":
continue
if isinstance(obj, property):
obj = obj.fget
if isinstance(obj, (staticmethod, classmethod)):
obj = obj.__func__
try:
doc_controls.do_not_doc_in_subclasses(obj)
except AttributeError:
pass
def build_docs():
"""Build api docs for tensorflow_text."""
_hide_layer_and_module_methods()
del text.keras # keras is empty.
doc_generator = generate_lib.DocGenerator(
root_title="TensorFlow Text",
py_modules=[("text", text)],
base_dir=os.path.dirname(text.__file__),
search_hints=True,
code_url_prefix=FLAGS.code_url_prefix,
site_path="text/api_docs/python",
callbacks=[public_api.explicit_package_contents_filter])
doc_generator.build(FLAGS.output_dir)
def main(_):
# Build API docs
build_docs()
if __name__ == "__main__":
app.run(main)