Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"tensorflow_datasets",
"-vv",
"--continue-on-collection-errors",
"--ignore=tensorflow_datasets/testing/test_utils.py"
"--ignore=tensorflow_datasets/testing/test_utils.py",
"--ignore=tensorflow_datasets/scripts/documentation/build_api_docs_test.py"
],
"files.watcherExclude": {
"**/.git/**": true,
Expand Down
4 changes: 3 additions & 1 deletion tensorflow_datasets/core/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def f():
```

The functions exposed below are dummy decorators. This allows not having to load
TensorFlow.
TensorFlow. The functions are monkey patched when needed in
scripts/documentation/build_api_docs.py with actual TensorFlow documentation
decorators.
"""

from typing import Any, TypeVar
Expand Down
91 changes: 91 additions & 0 deletions tensorflow_datasets/scripts/documentation/build_api_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# coding=utf-8
# Copyright 2026 The TensorFlow Datasets 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.

"""generates api_docs for tensorflow_datasets."""
import os

from absl import app
from absl import flags
from absl import logging

import tensorflow_datasets as tfds
# Testing is lazily imported, so we first force its import.
from tensorflow_datasets.testing import * # pylint: disable=wildcard-import
from tensorflow_docs.api_generator import generate_lib

from tensorflow.tools.docs import doc_controls # pylint: disable=g-direct-tensorflow-import

# Force the definition of all documentation decorators declared in
# third_party/py/tensorflow_datasets/core/utils/docs.py to TensorFlow decorators
try:
tfds.core.utils.docs.deprecated = doc_controls.set_deprecated
tfds.core.utils.docs.doc_private = doc_controls.doc_private
tfds.core.utils.docs.do_not_doc = doc_controls.do_not_generate_docs
# Same as `do_not_doc`, but also applied to children
tfds.core.utils.docs.do_not_doc_inheritable = (
doc_controls.do_not_doc_inheritable
)
# Document the parent, but not the children
tfds.core.utils.docs.do_not_doc_in_subclasses = (
doc_controls.do_not_doc_in_subclasses
)
except AttributeError:
logging.info("Could not set TensorFlow documentation decorators.")

FLAGS = flags.FLAGS

flags.DEFINE_string(
"output_dir", "/tmp/datasets_api", "Where to output the docs"
)
flags.DEFINE_string(
"code_url_prefix",
"https://github.com/tensorflow/datasets/tree/master/tensorflow_datasets/",
"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", "datasets/api_docs/python", "Path prefix in the _toc.yaml"
)


def execute(output_dir, code_url_prefix, search_hints, site_path):
"""Builds API docs for tensorflow_datasets."""
doc_generator = generate_lib.DocGenerator(
root_title="TensorFlow Datasets",
py_modules=[("tfds", tfds)],
base_dir=os.path.dirname(tfds.__file__),
search_hints=search_hints,
code_url_prefix=code_url_prefix,
site_path=site_path,
)

doc_generator.build(output_dir)


def main(unused_argv):
execute(
FLAGS.output_dir,
FLAGS.code_url_prefix,
FLAGS.search_hints,
FLAGS.site_path,
)


if __name__ == "__main__":
app.run(main)
Loading