Skip to content

Commit 5ed8fbe

Browse files
MarkDaoustcopybara-github
authored andcommitted
Fix doc-gen scripts for TF2.15+
- filter_builtin_modules was not compatible with keras lazy loaders. - but it's redundant now, totally covered by the base_dir filters. - Add logging. - Remove the path-checks in generate2, these mostly give false-positive errors > not worth it. PiperOrigin-RevId: 597382362
1 parent 8246c1c commit 5ed8fbe

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

tools/tensorflow_docs/api_generator/doc_generator_visitor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ def build(self):
421421
duplicates = {}
422422

423423
for path, node in self.path_tree.items():
424+
_LOGGER.debug('DocGeneratorVisitor.build')
425+
_LOGGER.debug(' path: %s', path)
426+
424427
if not path:
425428
continue
426429
full_name = node.full_name

tools/tensorflow_docs/api_generator/generate_lib.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"""Generate tensorflow.org style API Reference docs for a Python module."""
1616

1717
import collections
18+
import logging
1819
import os
1920
import pathlib
2021
import shutil
2122
import tempfile
22-
2323
from typing import Any, Optional, Sequence, Type, Union
2424

2525
from tensorflow_docs.api_generator import config
@@ -29,11 +29,8 @@
2929
from tensorflow_docs.api_generator import reference_resolver as reference_resolver_lib
3030
from tensorflow_docs.api_generator import toc as toc_lib
3131
from tensorflow_docs.api_generator import traverse
32-
3332
from tensorflow_docs.api_generator.pretty_docs import docs_for_object
34-
3533
from tensorflow_docs.api_generator.report import utils
36-
3734
import yaml
3835

3936
# Used to add a collections.OrderedDict representer to yaml so that the
@@ -42,6 +39,9 @@
4239
# Using a normal dict doesn't preserve the order of the input dictionary.
4340
_mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG
4441

42+
# To see the logs pass: --logger_levels=tensorflow_docs:DEBUG --alsologtostderr
43+
_LOGGER = logging.getLogger(__name__)
44+
4545

4646
def dict_representer(dumper, data):
4747
return dumper.represent_dict(data.items())
@@ -121,6 +121,9 @@ def write_docs(
121121
# Parse and write Markdown pages, resolving cross-links (`tf.symbol`).
122122
num_docs_output = 0
123123
for api_node in parser_config.api_tree.iter_nodes():
124+
_LOGGER.debug('generate_lib.write_docs')
125+
_LOGGER.debug(' full_name: %s', api_node.full_name)
126+
124127
full_name = api_node.full_name
125128

126129
if api_node.output_type() is api_node.OutputType.FRAGMENT:
@@ -391,7 +394,6 @@ def make_default_filters(self) -> list[public_api.ApiFilter]:
391394
public_api.FailIfNestedTooDeep(10),
392395
public_api.filter_module_all,
393396
public_api.add_proto_fields,
394-
public_api.filter_builtin_modules,
395397
public_api.filter_private_symbols,
396398
public_api.FilterBaseDirs(self._base_dir),
397399
public_api.FilterPrivateMap(self._private_map),

tools/tensorflow_docs/api_generator/public_api.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -489,27 +489,3 @@ def add_proto_fields(path: Sequence[str], parent: Any,
489489
children = sorted(children.items(), key=lambda item: item[0])
490490

491491
return children
492-
493-
494-
def filter_builtin_modules(path: Sequence[str], parent: Any,
495-
children: Children) -> Children:
496-
"""Filters module children to remove builtin modules.
497-
498-
Args:
499-
path: API to this symbol
500-
parent: The object
501-
children: A list of (name, object) pairs.
502-
503-
Returns:
504-
`children` with all builtin modules removed.
505-
"""
506-
del path
507-
del parent
508-
# filter out 'builtin' modules
509-
filtered_children = []
510-
for name, child in children:
511-
# Do not descend into built-in modules
512-
if inspect.ismodule(child) and child.__name__ in sys.builtin_module_names:
513-
continue
514-
filtered_children.append((name, child))
515-
return filtered_children

0 commit comments

Comments
 (0)