def _dfs()

in tools/tensorflow_docs/api_generator/generate_lib.py [0:0]


  def _dfs(self, mod, visited, is_parent_deprecated):
    """Does a dfs traversal on the graph generated.

    This creates a nested dictionary structure which is then dumped as .yaml
    file. Each submodule's dictionary of title and path is nested under its
    parent module.

    For example, `tf.keras.app.net` will be nested under `tf.keras.app` which
    will be nested under `tf.keras`. Here's how the nested dictionaries will
    look when its dumped as .yaml.

    ```
    - title: tf.keras
      section:
      - title: Overview
        path: /tf/keras
      - title: app
        section:
        - title: Overview
          path: /tf/keras/app
        - title: net
          section:
          - title: Overview
            path: /tf/keras/app/net
    ```

    The above nested structure is what the dfs traversal will create in form
    of lists of dictionaries.

    Args:
      mod: A module object.
      visited: A dictionary of modules visited by the dfs traversal.
      is_parent_deprecated: Bool, Whether any parent is deprecated or not.

    Returns:
      A dictionary containing the nested data structure.
    """

    visited[mod.full_name] = True

    # parent_exp is set to the current module because the current module is
    # the parent for its children.
    children_list = self._generate_children(
        mod, is_parent_deprecated or mod.deprecated)

    # generate for submodules within the submodule.
    for submod in mod.submodules:
      if not visited[submod.full_name]:
        sub_mod_dict = self._dfs(submod, visited, is_parent_deprecated or
                                 mod.deprecated)
        children_list.append(sub_mod_dict)

    # If the parent module is not experimental, then add the experimental
    # status to the submodule.
    submod_yaml_content = [('title', mod.title), ('section', children_list)]

    # If the parent module is not deprecated, then add the deprecated
    # status to the submodule. If the parent is deprecated, then setting its
    # status to deprecated in _toc.yaml propagates to all its children and
    # submodules.
    if mod.deprecated and not is_parent_deprecated:
      submod_yaml_content.insert(1, ('status', 'deprecated'))
    elif mod.experimental:
      submod_yaml_content.insert(1, ('status', 'experimental'))

    return collections.OrderedDict(submod_yaml_content)