Skip to content

Commit fd51dc7

Browse files
MarkDaoustfacaiy
authored andcommitted
Add standard flags to build_docs.py (#518)
* Add standard flags to build_docs.py * ran autoformat * Readability improvements.
1 parent a6c53b0 commit fd51dc7

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

tools/docs/build_docs.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,45 @@
4949

5050
flags.DEFINE_string(
5151
'git_branch',
52-
default='master',
52+
default=None,
5353
help='The name of the corresponding branch on github.')
5454

55-
flags.DEFINE_string(
56-
'output_dir',
57-
default='docs/api_docs/python/',
58-
help='Where to write the resulting docs to.')
55+
CODE_PREFIX_TEMPLATE = "https://github.com/tensorflow/addons/tree/{git_branch}/tensorflow_addons"
56+
flags.DEFINE_string("code_url_prefix", None,
57+
"The url prefix for links to the code.")
58+
flags.mark_flags_as_mutual_exclusive(['code_url_prefix', 'git_branch'])
59+
60+
flags.DEFINE_string("output_dir", "/tmp/addons_api",
61+
"Where to output the docs")
62+
63+
flags.DEFINE_bool("search_hints", True,
64+
"Include metadata search hints in the generated files")
65+
66+
flags.DEFINE_string("site_path", "addons/api_docs/python",
67+
"Path prefix in the _toc.yaml")
5968

6069

6170
def main(argv):
6271
if argv[1:]:
6372
raise ValueError('Unrecognized arguments: {}'.format(argv[1:]))
6473

65-
code_url_prefix = ('https://github.com/tensorflow/addons/tree/'
66-
'{git_branch}/tensorflow_addons'.format(
67-
git_branch=FLAGS.git_branch))
74+
if FLAGS.code_url_prefix:
75+
code_url_prefix = FLAGS.code_url_prefix
76+
elif FLAGS.git_branch:
77+
code_url_prefix = CODE_PREFIX_TEMPLATE.format(
78+
git_branch=FLAGS.git_branch)
79+
else:
80+
code_url_prefix = CODE_PREFIX_TEMPLATE.format(git_branch='master')
6881

6982
doc_generator = generate_lib.DocGenerator(
7083
root_title=PROJECT_FULL_NAME,
71-
# Replace `tensorflow_docs` with your module, here.
7284
py_modules=[(PROJECT_SHORT_NAME, tfa)],
7385
code_url_prefix=code_url_prefix,
7486
private_map={'tfa': ['__version__', 'utils', 'version']},
75-
# This callback cleans up a lot of aliases caused by internal imports.
76-
callbacks=[public_api.local_definitions_filter])
87+
# This callback usually cleans up a lot of aliases caused by internal imports.
88+
callbacks=[public_api.local_definitions_filter],
89+
search_hints=FLAGS.search_hints,
90+
site_path=FLAGS.site_path)
7791

7892
doc_generator.build(FLAGS.output_dir)
7993

0 commit comments

Comments
 (0)