Fix "document isn't included" warning when using autoapi_add_toctree_entry

Closes #319
markdown
Ashley Whetter 1 year ago
parent 8ffcd0fd67
commit 1715dfe0b5

@ -207,8 +207,8 @@ def doctree_read(app, doctree):
insert = False
if insert and app.config.autoapi_add_toctree_entry:
# Insert AutoAPI index
nodes[-1]["entries"].append((None, f"{app.config.autoapi_root}/index"))
nodes[-1]["includefiles"].append(f"{app.config.autoapi_root}/index")
nodes[-1]["entries"].append((None, toc_entry))
nodes[-1]["includefiles"].append(toc_entry)
message_prefix = colorize("bold", "[AutoAPI] ")
message = colorize(
"darkgreen", f"Adding AutoAPI TOCTree [{toc_entry}] to index.rst"
@ -274,7 +274,10 @@ def viewcode_follow_imported(app, modname, attribute):
def setup(app):
app.connect("builder-inited", run_autoapi)
app.connect("source-read", source_read)
app.connect("doctree-read", doctree_read)
# Use a lower priority than the default to ensure that we can
# inject into the toctree before Sphinx tries to use it
# in another doctree-read transformer.
app.connect("doctree-read", doctree_read, priority=400)
app.connect("build-finished", build_finished)
if "viewcode-find-source" in app.events.events:
app.connect("viewcode-find-source", viewcode_find)

@ -0,0 +1 @@
Fix "document isn't included" warning when using autoapi_add_toctree_entry

@ -8,14 +8,8 @@ Welcome to pyexample's documentation!
.. toctree::
autoapi/index
manualapi
Contents:
.. toctree::
:maxdepth: 2
Indices and tables

@ -24,14 +24,13 @@ from sphinx.errors import ExtensionError
sphinx_version = version.parse(sphinx.__version__).release
def rebuild(confoverrides=None, confdir=".", **kwargs):
def rebuild(confdir=".", **kwargs):
app = Sphinx(
srcdir=".",
confdir=confdir,
outdir="_build/text",
doctreedir="_build/.doctrees",
buildername="text",
confoverrides=confoverrides,
**kwargs,
)
app.build()
@ -41,9 +40,19 @@ def rebuild(confoverrides=None, confdir=".", **kwargs):
def builder():
cwd = os.getcwd()
def build(test_dir, confoverrides=None, **kwargs):
def build(test_dir, **kwargs):
if kwargs.get("warningiserror"):
# Add any warnings raised when using `Sphinx` more than once
# in a Python session.
confoverrides = kwargs.setdefault("confoverrides", {})
confoverrides.setdefault("suppress_warnings", [])
suppress = confoverrides["suppress_warnings"]
suppress.append("app.add_node")
suppress.append("app.add_directive")
suppress.append("app.add_role")
os.chdir("tests/python/{0}".format(test_dir))
rebuild(confoverrides=confoverrides, **kwargs)
rebuild(**kwargs)
yield build
@ -59,7 +68,6 @@ class TestSimpleModule:
builder(
"pyexample",
warningiserror=True,
confoverrides={"suppress_warnings": ["app"]},
)
def test_integration(self):
@ -176,7 +184,6 @@ class TestMovedConfPy(TestSimpleModule):
"pymovedconfpy",
confdir="confpy",
warningiserror=True,
confoverrides={"suppress_warnings": ["app"]},
)
@ -195,7 +202,6 @@ class TestSimpleModuleDifferentPrimaryDomain:
"imported-members",
],
"primary_domain": "cpp",
"suppress_warnings": ["app"],
},
)
@ -1008,7 +1014,6 @@ class TestMemberOrder:
"pyexample",
warningiserror=True,
confoverrides={
"suppress_warnings": ["app"],
"autodoc_member_order": "bysource",
},
)

Loading…
Cancel
Save