Skip to content

Commit ea53711

Browse files
MarkDaoustyongtang
authored andcommitted
Add standard flags to build_docs.py (#487)
* Add standard flags to build_docs.py * Recursively import submodules.
1 parent 04fa3fb commit ea53711

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

tools/docs/build_docs.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@
4646
from tensorflow_docs.api_generator import generate_lib
4747
from tensorflow_docs.api_generator import parser
4848
from tensorflow_docs.api_generator import public_api
49+
from tensorflow_docs.api_generator import utils
4950

5051
from tensorflow.python.util import tf_inspect
5152

53+
54+
# tfio doesn't eagerly import submodules.
55+
utils.recursive_import(tfio)
56+
5257
# Use tensorflow's `tf_inspect`, which is aware of `tf_decorator`.
5358
parser.tf_inspect = tf_inspect
5459

@@ -59,22 +64,37 @@
5964

6065
flags.DEFINE_string(
6166
'git_branch',
62-
default='master',
67+
default=None,
6368
help='The name of the corresponding branch on github.')
6469

70+
flags.DEFINE_string("output_dir", "/tmp/io_api",
71+
"Where to output the docs")
72+
73+
CODE_PREFIX_TEMPLATE = "https://github.com/tensorflow/io/tree/{git_branch}/tensorflow_io"
6574
flags.DEFINE_string(
66-
'output_dir',
67-
default='docs/api_docs/python/',
68-
help='Where to write the resulting docs to.')
75+
"code_url_prefix", None,
76+
"The url prefix for links to the code.")
77+
78+
flags.DEFINE_bool("search_hints", True,
79+
"Include metadata search hints in the generated files")
80+
81+
flags.DEFINE_string("site_path", "io/api_docs/python",
82+
"Path prefix in the _toc.yaml")
83+
84+
flags.mark_flags_as_mutual_exclusive(['code_url_prefix', 'git_branch'])
85+
6986

7087

7188
def main(argv):
7289
if argv[1:]:
7390
raise ValueError('Unrecognized arguments: {}'.format(argv[1:]))
7491

75-
code_url_prefix = ('https://github.com/tensorflow/io/tree/'
76-
'{git_branch}/tensorflow_io'.format(
77-
git_branch=FLAGS.git_branch))
92+
if FLAGS.git_branch:
93+
code_url_prefix = CODE_PREFIX_TEMPLATE.format(git_branch=FLAGS.git_branch)
94+
elif FLAGS.code_url_prefix:
95+
code_url_prefix = FLAGS.code_url_prefix
96+
else:
97+
code_url_prefix = CODE_PREFIX_TEMPLATE.format(git_branch='master')
7898

7999
doc_generator = generate_lib.DocGenerator(
80100
root_title=PROJECT_FULL_NAME,
@@ -83,7 +103,9 @@ def main(argv):
83103
code_url_prefix=code_url_prefix,
84104
private_map={'tfio': ['__version__', 'utils', 'version']},
85105
# This callback cleans up a lot of aliases caused by internal imports.
86-
callbacks=[public_api.local_definitions_filter])
106+
callbacks=[public_api.local_definitions_filter],
107+
search_hints=FLAGS.search_hints,
108+
site_path=FLAGS.site_path)
87109

88110
doc_generator.build(FLAGS.output_dir)
89111

0 commit comments

Comments
 (0)