summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--sphinx/ext/autosummary/__init__.py20
-rw-r--r--tests/test_ext_autosummary.py6
3 files changed, 20 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index e5c83ddb0..088fae434 100644
--- a/CHANGES
+++ b/CHANGES
@@ -41,6 +41,7 @@ Bugs fixed
* #5502: linkcheck: Consider HTTP 503 response as not an error
* #6439: Make generated download links reproducible
* #6486: UnboundLocalError is raised if broken extension installed
+* #6498: autosummary: crashed with wrong autosummary_generate setting
Testing
--------
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index 6eb0fea9b..19c400609 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -58,6 +58,7 @@ import posixpath
import re
import sys
import warnings
+from os import path
from types import ModuleType
from typing import List, cast
@@ -731,26 +732,31 @@ def process_generate_options(app):
# type: (Sphinx) -> None
genfiles = app.config.autosummary_generate
- if genfiles and not hasattr(genfiles, '__len__'):
+ if genfiles is True:
env = app.builder.env
genfiles = [env.doc2path(x, base=None) for x in env.found_docs
if os.path.isfile(env.doc2path(x))]
+ else:
+ ext = list(app.config.source_suffix)
+ genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
+ 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
- from sphinx.ext.autosummary.generate import generate_autosummary_docs
-
- ext = list(app.config.source_suffix)
- genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
- for genfile in genfiles]
-
suffix = get_rst_suffix(app)
if suffix is None:
logger.warning(__('autosummary generats .rst files internally. '
'But your source_suffix does not contain .rst. Skipped.'))
return
+ from sphinx.ext.autosummary.generate import generate_autosummary_docs
+
imported_members = app.config.autosummary_imported_members
with mock(app.config.autosummary_mock_imports):
generate_autosummary_docs(genfiles, builder=app.builder,
diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py
index ae97d3b57..ae2b2d585 100644
--- a/tests/test_ext_autosummary.py
+++ b/tests/test_ext_autosummary.py
@@ -302,3 +302,9 @@ def test_generate_autosummary_docs_property(app):
".. currentmodule:: target.methods\n"
"\n"
".. 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()