Fix #5327: "document isn't included in any toctree" warning on rebuild with generated files

This commit is contained in:
Takeshi KOMIYA 2018-08-22 22:36:48 +09:00
parent a029a8f81d
commit 294e9041b7
2 changed files with 12 additions and 8 deletions

View File

@ -7,6 +7,8 @@ Dependencies
Incompatible changes Incompatible changes
-------------------- --------------------
* The type of ``env.included`` has been changed to dict of set
Deprecated Deprecated
---------- ----------
@ -19,6 +21,8 @@ Bugs fixed
* #5320: intersphinx: crashed if invalid url given * #5320: intersphinx: crashed if invalid url given
* #5326: manpage: crashed when invalid docname is specified as ``man_pages`` * #5326: manpage: crashed when invalid docname is specified as ``man_pages``
* #5322: autodoc: ``Any`` typehint causes formatting error * #5322: autodoc: ``Any`` typehint causes formatting error
* #5327: "document isn't included in any toctree" warning on rebuild with
generated files
Testing Testing
-------- --------

View File

@ -22,7 +22,7 @@ from os import path
from docutils.frontend import OptionParser from docutils.frontend import OptionParser
from docutils.utils import Reporter, get_source_line from docutils.utils import Reporter, get_source_line
from six import BytesIO, itervalues, class_types, next from six import BytesIO, itervalues, class_types, next
from six.moves import cPickle as pickle from six.moves import cPickle as pickle, reduce
from sphinx import addnodes, versioning from sphinx import addnodes, versioning
from sphinx.deprecation import RemovedInSphinx20Warning from sphinx.deprecation import RemovedInSphinx20Warning
@ -200,7 +200,8 @@ class BuildEnvironment(object):
self.dependencies = defaultdict(set) # type: Dict[unicode, Set[unicode]] self.dependencies = defaultdict(set) # type: Dict[unicode, Set[unicode]]
# docname -> set of dependent file # docname -> set of dependent file
# names, relative to documentation root # names, relative to documentation root
self.included = set() # type: Set[unicode] self.included = defaultdict(set) # type: Dict[unicode, Set[unicode]]
# docname -> set of included file
# docnames included from other documents # docnames included from other documents
self.reread_always = set() # type: Set[unicode] self.reread_always = set() # type: Set[unicode]
# docnames to re-read unconditionally on # docnames to re-read unconditionally on
@ -309,8 +310,8 @@ class BuildEnvironment(object):
"""Remove all traces of a source file in the inventory.""" """Remove all traces of a source file in the inventory."""
if docname in self.all_docs: if docname in self.all_docs:
self.all_docs.pop(docname, None) self.all_docs.pop(docname, None)
self.included.pop(docname, None)
self.reread_always.discard(docname) self.reread_always.discard(docname)
self.included.discard(docname)
for version, changes in self.versionchanges.items(): for version, changes in self.versionchanges.items():
new = [change for change in changes if change[1] != docname] new = [change for change in changes if change[1] != docname]
@ -329,12 +330,10 @@ class BuildEnvironment(object):
docnames = set(docnames) # type: ignore docnames = set(docnames) # type: ignore
for docname in docnames: for docname in docnames:
self.all_docs[docname] = other.all_docs[docname] self.all_docs[docname] = other.all_docs[docname]
self.included[docname] = other.included[docname]
if docname in other.reread_always: if docname in other.reread_always:
self.reread_always.add(docname) self.reread_always.add(docname)
for docname in other.included:
self.included.add(docname)
for version, changes in other.versionchanges.items(): for version, changes in other.versionchanges.items():
self.versionchanges.setdefault(version, []).extend( self.versionchanges.setdefault(version, []).extend(
change for change in changes if change[1] in docnames) change for change in changes if change[1] in docnames)
@ -724,7 +723,7 @@ class BuildEnvironment(object):
*filename* should be absolute or relative to the source directory. *filename* should be absolute or relative to the source directory.
""" """
self.included.add(self.path2doc(filename)) self.included[self.docname].add(self.path2doc(filename))
def note_reread(self): def note_reread(self):
# type: () -> None # type: () -> None
@ -915,12 +914,13 @@ class BuildEnvironment(object):
def check_consistency(self): def check_consistency(self):
# type: () -> None # type: () -> None
"""Do consistency checks.""" """Do consistency checks."""
included = reduce(lambda x, y: x | y, self.included.values(), set()) # type: Set[unicode] # NOQA
for docname in sorted(self.all_docs): for docname in sorted(self.all_docs):
if docname not in self.files_to_rebuild: if docname not in self.files_to_rebuild:
if docname == self.config.master_doc: if docname == self.config.master_doc:
# the master file is not included anywhere ;) # the master file is not included anywhere ;)
continue continue
if docname in self.included: if docname in included:
# the document is included from other documents # the document is included from other documents
continue continue
if 'orphan' in self.metadata[docname]: if 'orphan' in self.metadata[docname]: