diff --git a/CHANGES b/CHANGES index b857ca251..6fefa1aa1 100644 --- a/CHANGES +++ b/CHANGES @@ -52,6 +52,7 @@ Features added * #5124: graphviz: ``:graphviz_dot:`` option is renamed to ``:layout:`` * #1464: html: emit a warning if :confval:`html_static_path` and :confval:`html_extra_path` directories are inside output directory +* #6514: html: Add a label to search input for accessability purposes * #5602: apidoc: Add ``--templatedir`` option Bugs fixed @@ -64,6 +65,8 @@ 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 +* #6507: autosummary: crashes without no autosummary_generate setting Testing -------- diff --git a/setup.py b/setup.py index 2b6e25713..96bffccfa 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ extras_require = { 'html5lib', 'flake8>=3.5.0', 'flake8-import-order', - 'mypy>=0.710', + 'mypy>=0.711', 'docutils-stubs', ], } diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index ed413de52..123e268da 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -157,7 +157,7 @@ def create_package_file(root, master_package, subroot, py_files, opts, subs, if submodules and opts.separatemodules: for submodule in submodules: - create_module_file(None, submodule, opts) + create_module_file(None, submodule, opts, user_template_dir) def create_modules_toc_file(modules, opts, name='modules', user_template_dir=None): diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 6eb0fea9b..de9d6dcd3 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 @@ -256,19 +257,26 @@ class Autosummary(SphinxDirective): docname = posixpath.join(tree_prefix, real_name) docname = posixpath.normpath(posixpath.join(dirname, docname)) if docname not in self.env.found_docs: + location = self.state_machine.get_source_and_line(self.lineno) if excluded(self.env.doc2path(docname, None)): - logger.warning(__('toctree references excluded document %r'), docname) + msg = __('autosummary references excluded document %r. Ignored.') else: - logger.warning(__('toctree references unknown document %r'), docname) + msg = __('autosummary: stub file not found %r. ' + 'Check your autosummary_generate setting.') + + logger.warning(msg, real_name, location=location) + continue + docnames.append(docname) - tocnode = addnodes.toctree() - tocnode['includefiles'] = docnames - tocnode['entries'] = [(None, docn) for docn in docnames] - tocnode['maxdepth'] = -1 - tocnode['glob'] = None + if docnames: + tocnode = addnodes.toctree() + tocnode['includefiles'] = docnames + tocnode['entries'] = [(None, docn) for docn in docnames] + tocnode['maxdepth'] = -1 + tocnode['glob'] = None - nodes.append(autosummary_toc('', '', tocnode)) + nodes.append(autosummary_toc('', '', tocnode)) return nodes @@ -731,26 +739,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/sphinx/themes/basic/search.html b/sphinx/themes/basic/search.html index 7446a8f25..6ac6b3899 100644 --- a/sphinx/themes/basic/search.html +++ b/sphinx/themes/basic/search.html @@ -33,7 +33,7 @@ containing fewer words won't appear in the result list.{% endtrans %}

- +
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 2cfceee5b..fc6dafe9f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -121,7 +121,7 @@ def isenumattribute(x: Any) -> bool: def ispartial(obj: Any) -> bool: """Check if the object is partial.""" - return isinstance(obj, (partial, partialmethod)) # type: ignore + return isinstance(obj, (partial, partialmethod)) def isclassmethod(obj: Any) -> bool: diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index ae97d3b57..1e50ac0ac 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -302,3 +302,17 @@ 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': []}) +def test_empty_autosummary_generate(app, status, warning): + app.build() + assert ("WARNING: autosummary: stub file not found 'autosummary_importfail'" + in warning.getvalue()) + + +@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() \ No newline at end of file