(app, doctree)
Inject AutoAPI into the TOC Tree dynamically.
Inject AutoAPI into the TOC Tree dynamically.
Inject AutoAPI into the TOC Tree dynamically .
def doctree_read(app, doctree):
    """
    Inject AutoAPI into the TOC Tree dynamically.
    """

    add_domain_to_toctree(app, doctree, app.env.docname)

    if app.env.docname == "index":
        all_docs = set()
        insert = True
        nodes = list(doctree.traverse(toctree))
        toc_entry = "%s/index" % app.config.autoapi_root
        add_entry = (
            nodes
            and app.config.autoapi_generate_api_docs
            and app.config.autoapi_add_toctree_entry
        )
        if not add_entry:
            return
        # Capture all existing toctree entries
        for node in nodes:
            for entry in node["entries"]:
                all_docs.add(entry[1])
        # Don't insert autoapi it's already present
        for doc in all_docs:
            if doc.find(app.config.autoapi_root) != -1:
                insert = False
        if insert and app.config.autoapi_add_toctree_entry:
            # Insert AutoAPI index
            nodes[-1]["entries"].append((None, u"%s/index" % app.config.autoapi_root))
            nodes[-1]["includefiles"].append(u"%s/index" % app.config.autoapi_root)
            message_prefix = bold("[AutoAPI] ")
            message = darkgreen(
                "Adding AutoAPI TOCTree [{0}] to index.rst".format(toc_entry)
            )
            LOGGER.info(message_prefix + message)
def doctree_read ( app , doctree ) : add_domain_to_toctree ( app , doctree , app . env . docname ) if app . env . docname == "index" : all_docs = set ( ) insert = True nodes = list ( doctree . traverse ( toctree ) ) toc_entry = "%s/index" % app . config . autoapi_root add_entry = ( nodes and app . config . autoapi_generate_api_docs and app . config . autoapi_add_toctree_entry ) if not add_entry : return # Capture all existing toctree entries for node in nodes : for entry in node [ "entries" ] : all_docs . add ( entry [ 1 ] ) # Don't insert autoapi it's already present for doc in all_docs : if doc . find ( app . config . autoapi_root ) != - 1 : insert = False if insert and app . config . autoapi_add_toctree_entry : # Insert AutoAPI index nodes [ - 1 ] [ "entries" ] . append ( ( None , u"%s/index" % app . config . autoapi_root ) ) nodes [ - 1 ] [ "includefiles" ] . append ( u"%s/index" % app . config . autoapi_root ) message_prefix = bold ( "[AutoAPI] " ) message = darkgreen ( "Adding AutoAPI TOCTree [{0}] to index.rst" . format ( toc_entry ) ) LOGGER . info ( message_prefix + message )