simplify _toc.yaml generation
PiperOrigin-RevId: 209439461
This commit is contained in:
parent
82a0d16be3
commit
468288f3b6
@ -31,11 +31,6 @@ if __name__ == '__main__':
|
|||||||
doc_generator = generate_lib.DocGenerator()
|
doc_generator = generate_lib.DocGenerator()
|
||||||
doc_generator.add_output_dir_argument()
|
doc_generator.add_output_dir_argument()
|
||||||
doc_generator.add_src_dir_argument()
|
doc_generator.add_src_dir_argument()
|
||||||
doc_generator.argument_parser.add_argument(
|
|
||||||
'--site_api_path',
|
|
||||||
type=str, default='api_docs/python',
|
|
||||||
help='The path from the site-root to api_docs'
|
|
||||||
'directory for this project')
|
|
||||||
|
|
||||||
# This doc generator works on the TensorFlow codebase. Since this script lives
|
# This doc generator works on the TensorFlow codebase. Since this script lives
|
||||||
# at tensorflow/tools/docs, and all code is defined somewhere inside
|
# at tensorflow/tools/docs, and all code is defined somewhere inside
|
||||||
|
@ -58,7 +58,7 @@ def write_docs(output_dir,
|
|||||||
yaml_toc,
|
yaml_toc,
|
||||||
root_title='TensorFlow',
|
root_title='TensorFlow',
|
||||||
search_hints=True,
|
search_hints=True,
|
||||||
site_api_path=None):
|
site_api_path=''):
|
||||||
"""Write previously extracted docs to disk.
|
"""Write previously extracted docs to disk.
|
||||||
|
|
||||||
Write a docs page for each symbol included in the indices of parser_config to
|
Write a docs page for each symbol included in the indices of parser_config to
|
||||||
@ -76,8 +76,8 @@ def write_docs(output_dir,
|
|||||||
root_title: The title name for the root level index.md.
|
root_title: The title name for the root level index.md.
|
||||||
search_hints: (bool) include meta-data search hints at the top of each
|
search_hints: (bool) include meta-data search hints at the top of each
|
||||||
output file.
|
output file.
|
||||||
site_api_path: Used to write the api-duplicates _redirects.yaml file. if
|
site_api_path: The output path relative to the site root. Used in the
|
||||||
None (the default) the file is not generated.
|
`_toc.yaml` and `_redirects.yaml` files.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: if `output_dir` is not an absolute path
|
ValueError: if `output_dir` is not an absolute path
|
||||||
@ -161,7 +161,6 @@ def write_docs(output_dir,
|
|||||||
raise OSError(
|
raise OSError(
|
||||||
'Cannot write documentation for %s to %s' % (full_name, directory))
|
'Cannot write documentation for %s to %s' % (full_name, directory))
|
||||||
|
|
||||||
if site_api_path:
|
|
||||||
duplicates = parser_config.duplicates.get(full_name, [])
|
duplicates = parser_config.duplicates.get(full_name, [])
|
||||||
if not duplicates:
|
if not duplicates:
|
||||||
continue
|
continue
|
||||||
@ -171,12 +170,13 @@ def write_docs(output_dir,
|
|||||||
for dup in duplicates:
|
for dup in duplicates:
|
||||||
from_path = os.path.join(site_api_path, dup.replace('.', '/'))
|
from_path = os.path.join(site_api_path, dup.replace('.', '/'))
|
||||||
to_path = os.path.join(site_api_path, full_name.replace('.', '/'))
|
to_path = os.path.join(site_api_path, full_name.replace('.', '/'))
|
||||||
redirects.append((from_path, to_path))
|
redirects.append((
|
||||||
|
os.path.join('/', from_path),
|
||||||
|
os.path.join('/', to_path)))
|
||||||
|
|
||||||
if site_api_path and redirects:
|
|
||||||
redirects = sorted(redirects)
|
redirects = sorted(redirects)
|
||||||
template = ('- from: /{}\n'
|
template = ('- from: {}\n'
|
||||||
' to: /{}\n')
|
' to: {}\n')
|
||||||
redirects = [template.format(f, t) for f, t in redirects]
|
redirects = [template.format(f, t) for f, t in redirects]
|
||||||
api_redirects_path = os.path.join(output_dir, '_redirects.yaml')
|
api_redirects_path = os.path.join(output_dir, '_redirects.yaml')
|
||||||
with open(api_redirects_path, 'w') as redirect_file:
|
with open(api_redirects_path, 'w') as redirect_file:
|
||||||
@ -211,7 +211,8 @@ def write_docs(output_dir,
|
|||||||
'- title: ' + title,
|
'- title: ' + title,
|
||||||
' section:',
|
' section:',
|
||||||
' - title: Overview',
|
' - title: Overview',
|
||||||
' path: /TARGET_DOC_ROOT/VERSION/' + symbol_to_file[module]]
|
' path: ' + os.path.join('/', site_api_path,
|
||||||
|
symbol_to_file[module])]
|
||||||
header = ''.join([indent+line+'\n' for line in header])
|
header = ''.join([indent+line+'\n' for line in header])
|
||||||
f.write(header)
|
f.write(header)
|
||||||
|
|
||||||
@ -222,7 +223,8 @@ def write_docs(output_dir,
|
|||||||
for full_name in symbols_in_module:
|
for full_name in symbols_in_module:
|
||||||
item = [
|
item = [
|
||||||
' - title: ' + full_name[len(module) + 1:],
|
' - title: ' + full_name[len(module) + 1:],
|
||||||
' path: /TARGET_DOC_ROOT/VERSION/' + symbol_to_file[full_name]]
|
' path: ' + os.path.join('/', site_api_path,
|
||||||
|
symbol_to_file[full_name])]
|
||||||
item = ''.join([indent+line+'\n' for line in item])
|
item = ''.join([indent+line+'\n' for line in item])
|
||||||
f.write(item)
|
f.write(item)
|
||||||
|
|
||||||
@ -533,6 +535,12 @@ class DocGenerator(object):
|
|||||||
action='store_false',
|
action='store_false',
|
||||||
default=True)
|
default=True)
|
||||||
|
|
||||||
|
self.argument_parser.add_argument(
|
||||||
|
'--site_api_path',
|
||||||
|
type=str, default='',
|
||||||
|
help='The path from the site-root to api_docs'
|
||||||
|
'directory for this project')
|
||||||
|
|
||||||
def add_output_dir_argument(self):
|
def add_output_dir_argument(self):
|
||||||
self.argument_parser.add_argument(
|
self.argument_parser.add_argument(
|
||||||
'--output_dir',
|
'--output_dir',
|
||||||
@ -649,7 +657,7 @@ class DocGenerator(object):
|
|||||||
yaml_toc=self.yaml_toc,
|
yaml_toc=self.yaml_toc,
|
||||||
root_title=root_title,
|
root_title=root_title,
|
||||||
search_hints=getattr(flags, 'search_hints', True),
|
search_hints=getattr(flags, 'search_hints', True),
|
||||||
site_api_path=getattr(flags, 'site_api_path', None))
|
site_api_path=getattr(flags, 'site_api_path', ''))
|
||||||
|
|
||||||
# Replace all the @{} references in files under `FLAGS.src_dir`
|
# Replace all the @{} references in files under `FLAGS.src_dir`
|
||||||
replace_refs(flags.src_dir, flags.output_dir, reference_resolver, '*.md')
|
replace_refs(flags.src_dir, flags.output_dir, reference_resolver, '*.md')
|
||||||
|
Loading…
Reference in New Issue
Block a user