From ab3795f1769753c6c743431d88aa001ebf6f686a Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 23 Apr 2020 01:59:17 +0900 Subject: [PATCH] Fix #7536: sphinx-autogen: crashes when template uses i18n feature --- CHANGES | 1 + sphinx/ext/autosummary/generate.py | 8 +++++--- tests/test_ext_autosummary.py | 10 +++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index d05816f27..bad9a15c1 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,7 @@ Features added * #248, #6040: autosummary: Add ``:recursive:`` option to autosummary directive to generate stub files recursively * #7535: sphinx-autogen: crashes when custom template uses inheritance +* #7536: sphinx-autogen: crashes when template uses i18n feature * #7481: html theme: Add right margin to footnote/citation labels * #7482: html theme: CSS spacing for code blocks with captions and line numbers * #7443: html theme: Add new options :confval:`globaltoc_collapse` and diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 8a056f55f..de88fc2a6 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -25,6 +25,7 @@ import pydoc import re import sys import warnings +from gettext import NullTranslations from os import path from typing import Any, Callable, Dict, List, NamedTuple, Set, Tuple @@ -58,10 +59,10 @@ logger = logging.getLogger(__name__) class DummyApplication: """Dummy Application class for sphinx-autogen command.""" - def __init__(self) -> None: + def __init__(self, translator: NullTranslations) -> None: self.registry = SphinxComponentRegistry() self.messagelog = [] # type: List[str] - self.translator = None + self.translator = translator self.verbosity = 0 self._warncount = 0 self.warningiserror = False @@ -528,8 +529,9 @@ The format of the autosummary directive is documented in the def main(argv: List[str] = sys.argv[1:]) -> None: sphinx.locale.setlocale(locale.LC_ALL, '') sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx') + translator, _ = sphinx.locale.init([], None) - app = DummyApplication() + app = DummyApplication(translator) logging.setup(app, sys.stdout, sys.stderr) # type: ignore setup_documenters(app) args = get_parser().parse_args(argv) diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index 58fbb0967..7e7a20663 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -19,9 +19,10 @@ from sphinx import addnodes from sphinx.ext.autosummary import ( autosummary_table, autosummary_toc, mangle_signature, import_by_name, extract_summary ) -from sphinx.ext.autosummary.generate import AutosummaryEntry, generate_autosummary_docs +from sphinx.ext.autosummary.generate import AutosummaryEntry, generate_autosummary_docs, main as autogen_main from sphinx.testing.util import assert_node, etree_parse from sphinx.util.docutils import new_document +from sphinx.util.osutil import cd html_warnfile = StringIO() @@ -388,3 +389,10 @@ def test_empty_autosummary_generate(app, status, warning): confoverrides={'autosummary_generate': ['unknown']}) def test_invalid_autosummary_generate(app, status, warning): assert 'WARNING: autosummary_generate: file not found: unknown.rst' in warning.getvalue() + + +def test_autogen(rootdir, tempdir): + with cd(rootdir / 'test-templating'): + args = ['-o', tempdir, '-t', '.', 'autosummary_templating.txt'] + autogen_main(args) + assert (tempdir / 'sphinx.application.TemplateBridge.rst').exists()