aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/docs
diff options
context:
space:
mode:
authorGravatar Mark Daoust <markdaoust@google.com>2018-09-06 08:45:54 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-09-06 08:49:50 -0700
commit35f28c57da8aad4a79503db955b11fed63b1fe34 (patch)
treee9f587775d3eeb76cbe0ad5ced9da7e2bd73b85e /tensorflow/tools/docs
parent04f3ddac5b69c85558657db5c1b409059716fdb7 (diff)
Add a command line option to serialize api-reference resolver.
PiperOrigin-RevId: 211813852
Diffstat (limited to 'tensorflow/tools/docs')
-rw-r--r--tensorflow/tools/docs/generate_lib.py10
-rw-r--r--tensorflow/tools/docs/parser.py7
2 files changed, 16 insertions, 1 deletions
diff --git a/tensorflow/tools/docs/generate_lib.py b/tensorflow/tools/docs/generate_lib.py
index 483921fc2f..7db89f7d24 100644
--- a/tensorflow/tools/docs/generate_lib.py
+++ b/tensorflow/tools/docs/generate_lib.py
@@ -548,6 +548,13 @@ class DocGenerator(object):
help='The path from the site-root to api_docs'
'directory for this project')
+ self.argument_parser.add_argument(
+ '--api_cache_out_path',
+ type=str,
+ default=None,
+ help='Path to store a json-serialized api-index, so links can be '
+ 'inserted into docs without rebuilding the api_docs')
+
def add_output_dir_argument(self):
self.argument_parser.add_argument(
'--output_dir',
@@ -648,6 +655,9 @@ class DocGenerator(object):
visitor = self.run_extraction()
reference_resolver = self.make_reference_resolver(visitor, doc_index)
+ if getattr(flags, 'api_cache_out_path', None):
+ reference_resolver.to_json_file(flags.api_cache_out_path)
+
# Build the guide_index for the api_docs back links.
root_title = getattr(flags, 'root_title', 'TensorFlow')
guide_index = _build_guide_index(
diff --git a/tensorflow/tools/docs/parser.py b/tensorflow/tools/docs/parser.py
index 549056c6c4..4afb61e365 100644
--- a/tensorflow/tools/docs/parser.py
+++ b/tensorflow/tools/docs/parser.py
@@ -153,6 +153,7 @@ class ReferenceResolver(object):
self._doc_index = doc_index
self._is_class = is_class
self._is_module = is_module
+
self._all_names = set(is_class.keys())
self._py_module_names = py_module_names
@@ -210,6 +211,10 @@ class ReferenceResolver(object):
Args:
filepath: The file path to write the json to.
"""
+ try:
+ os.makedirs(os.path.dirname(filepath))
+ except OSError:
+ pass
json_dict = {}
for key, value in self.__dict__.items():
# Drop these two fields. `_doc_index` is not serializable. `_all_names` is
@@ -223,7 +228,7 @@ class ReferenceResolver(object):
json_dict[key.lstrip('_')] = value
with open(filepath, 'w') as f:
- json.dump(json_dict, f)
+ json.dump(json_dict, f, indent=2, sort_keys=True)
def replace_references(self, string, relative_path_to_root):
"""Replace "@{symbol}" references with links to symbol's documentation page.