mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #6498: autosummary: crashed with wrong autosummary_generate setting
This commit is contained in:
parent
c78018cda7
commit
1aa1373ce3
1
CHANGES
1
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
|
||||
--------
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user