Fix #6498: autosummary: crashed with wrong autosummary_generate setting

This commit is contained in:
Takeshi KOMIYA 2019-06-19 01:05:47 +09:00
parent c78018cda7
commit 1aa1373ce3
3 changed files with 20 additions and 7 deletions

View File

@ -41,6 +41,7 @@ Bugs fixed
* #5502: linkcheck: Consider HTTP 503 response as not an error * #5502: linkcheck: Consider HTTP 503 response as not an error
* #6439: Make generated download links reproducible * #6439: Make generated download links reproducible
* #6486: UnboundLocalError is raised if broken extension installed * #6486: UnboundLocalError is raised if broken extension installed
* #6498: autosummary: crashed with wrong autosummary_generate setting
Testing Testing
-------- --------

View File

@ -58,6 +58,7 @@ import posixpath
import re import re
import sys import sys
import warnings import warnings
from os import path
from types import ModuleType from types import ModuleType
from typing import List, cast from typing import List, cast
@ -731,26 +732,31 @@ def process_generate_options(app):
# type: (Sphinx) -> None # type: (Sphinx) -> None
genfiles = app.config.autosummary_generate genfiles = app.config.autosummary_generate
if genfiles and not hasattr(genfiles, '__len__'): if genfiles is True:
env = app.builder.env env = app.builder.env
genfiles = [env.doc2path(x, base=None) for x in env.found_docs genfiles = [env.doc2path(x, base=None) for x in env.found_docs
if os.path.isfile(env.doc2path(x))] if os.path.isfile(env.doc2path(x))]
else:
if not genfiles:
return
from sphinx.ext.autosummary.generate import generate_autosummary_docs
ext = list(app.config.source_suffix) ext = list(app.config.source_suffix)
genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '') genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
for genfile in genfiles] for genfile in genfiles]
for entry in genfiles[:]:
if not path.isfile(path.join(app.srcdir, entry)):
logger.warning(__('autosummary_generate: file not found: %s'), entry)
genfiles.remove(entry)
if not genfiles:
return
suffix = get_rst_suffix(app) suffix = get_rst_suffix(app)
if suffix is None: if suffix is None:
logger.warning(__('autosummary generats .rst files internally. ' logger.warning(__('autosummary generats .rst files internally. '
'But your source_suffix does not contain .rst. Skipped.')) 'But your source_suffix does not contain .rst. Skipped.'))
return return
from sphinx.ext.autosummary.generate import generate_autosummary_docs
imported_members = app.config.autosummary_imported_members imported_members = app.config.autosummary_imported_members
with mock(app.config.autosummary_mock_imports): with mock(app.config.autosummary_mock_imports):
generate_autosummary_docs(genfiles, builder=app.builder, generate_autosummary_docs(genfiles, builder=app.builder,

View File

@ -302,3 +302,9 @@ def test_generate_autosummary_docs_property(app):
".. currentmodule:: target.methods\n" ".. currentmodule:: target.methods\n"
"\n" "\n"
".. autoproperty:: Base.prop") ".. autoproperty:: Base.prop")
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
confoverrides={'autosummary_generate': ['unknown']})
def test_invalid_autosummary_generate(app, status, warning):
assert 'WARNING: autosummary_generate: file not found: unknown.rst' in warning.getvalue()