def doctree_read(app, doctree):
    """Run during Sphinx `doctree-read` phase.

    Remove the items listed in `docs_to_remove` from the table of contents.
    """
    from sphinx import addnodes
    for toc_tree_node in doctree.traverse(addnodes.toctree):
        for e in toc_tree_node['entries']:
            if _to_be_removed(str(e[1])):
                toc_tree_node['entries'].remove(e)
Run during Sphinx `doctree-read` phase.

    Remove the items listed in `docs_to_remove` from the table of contents.
    
docs/conf.py