Stop to use deprecated API: env.indexentries

This commit is contained in:
Takeshi KOMIYA 2019-12-25 23:41:54 +09:00
parent de9ee3e70a
commit c171702ee2
2 changed files with 9 additions and 13 deletions

View File

@ -21,6 +21,7 @@ from docutils.nodes import Element, Node, Text
from sphinx import addnodes, __display_version__ from sphinx import addnodes, __display_version__
from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.domains import IndexEntry from sphinx.domains import IndexEntry
from sphinx.domains.index import IndexDomain
from sphinx.errors import ExtensionError from sphinx.errors import ExtensionError
from sphinx.locale import admonitionlabels, _, __ from sphinx.locale import admonitionlabels, _, __
from sphinx.util import logging from sphinx.util import logging
@ -497,8 +498,9 @@ class TexinfoTranslator(SphinxTranslator):
self.indices.append((indexcls.localname, self.indices.append((indexcls.localname,
generate(content, collapsed))) generate(content, collapsed)))
# only add the main Index if it's not empty # only add the main Index if it's not empty
domain = cast(IndexDomain, self.builder.env.get_domain('index'))
for docname in self.builder.docnames: for docname in self.builder.docnames:
if self.builder.env.indexentries[docname]: if domain.entries[docname]:
self.indices.append((_('Index'), '\n@printindex ge\n')) self.indices.append((_('Index'), '\n@printindex ge\n'))
break break

View File

@ -14,9 +14,8 @@ from sphinx.environment.adapters.indexentries import IndexEntries
from sphinx.testing import restructuredtext from sphinx.testing import restructuredtext
@pytest.mark.sphinx('dummy') @pytest.mark.sphinx('dummy', freshenv=True)
def test_create_single_index(app): def test_create_single_index(app):
app.env.indexentries.clear()
text = (".. index:: docutils\n" text = (".. index:: docutils\n"
".. index:: Python\n" ".. index:: Python\n"
".. index:: pip; install\n" ".. index:: pip; install\n"
@ -42,9 +41,8 @@ def test_create_single_index(app):
assert index[5] == ('ת', [('‏תירבע‎', [[('', '#index-7')], [], None])]) assert index[5] == ('ת', [('‏תירבע‎', [[('', '#index-7')], [], None])])
@pytest.mark.sphinx('dummy') @pytest.mark.sphinx('dummy', freshenv=True)
def test_create_pair_index(app): def test_create_pair_index(app):
app.env.indexentries.clear()
text = (".. index:: pair: docutils; reStructuredText\n" text = (".. index:: pair: docutils; reStructuredText\n"
".. index:: pair: Python; interpreter\n" ".. index:: pair: Python; interpreter\n"
".. index:: pair: Sphinx; documentation tool\n" ".. index:: pair: Sphinx; documentation tool\n"
@ -73,9 +71,8 @@ def test_create_pair_index(app):
('Ель', [[], [('Sphinx', [('', '#index-4')])], None])]) ('Ель', [[], [('Sphinx', [('', '#index-4')])], None])])
@pytest.mark.sphinx('dummy') @pytest.mark.sphinx('dummy', freshenv=True)
def test_create_triple_index(app): def test_create_triple_index(app):
app.env.indexentries.clear()
text = (".. index:: triple: foo; bar; baz\n" text = (".. index:: triple: foo; bar; baz\n"
".. index:: triple: Python; Sphinx; reST\n") ".. index:: triple: Python; Sphinx; reST\n")
restructuredtext.parse(app, text) restructuredtext.parse(app, text)
@ -89,9 +86,8 @@ def test_create_triple_index(app):
assert index[4] == ('S', [('Sphinx', [[], [('reST, Python', [('', '#index-1')])], None])]) assert index[4] == ('S', [('Sphinx', [[], [('reST, Python', [('', '#index-1')])], None])])
@pytest.mark.sphinx('dummy') @pytest.mark.sphinx('dummy', freshenv=True)
def test_create_see_index(app): def test_create_see_index(app):
app.env.indexentries.clear()
text = (".. index:: see: docutils; reStructuredText\n" text = (".. index:: see: docutils; reStructuredText\n"
".. index:: see: Python; interpreter\n" ".. index:: see: Python; interpreter\n"
".. index:: see: Sphinx; documentation tool\n") ".. index:: see: Sphinx; documentation tool\n")
@ -103,9 +99,8 @@ def test_create_see_index(app):
assert index[2] == ('S', [('Sphinx', [[], [('see documentation tool', [])], None])]) assert index[2] == ('S', [('Sphinx', [[], [('see documentation tool', [])], None])])
@pytest.mark.sphinx('dummy') @pytest.mark.sphinx('dummy', freshenv=True)
def test_create_seealso_index(app): def test_create_seealso_index(app):
app.env.indexentries.clear()
text = (".. index:: seealso: docutils; reStructuredText\n" text = (".. index:: seealso: docutils; reStructuredText\n"
".. index:: seealso: Python; interpreter\n" ".. index:: seealso: Python; interpreter\n"
".. index:: seealso: Sphinx; documentation tool\n") ".. index:: seealso: Sphinx; documentation tool\n")
@ -117,9 +112,8 @@ def test_create_seealso_index(app):
assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])]) assert index[2] == ('S', [('Sphinx', [[], [('see also documentation tool', [])], None])])
@pytest.mark.sphinx('dummy') @pytest.mark.sphinx('dummy', freshenv=True)
def test_create_index_by_key(app): def test_create_index_by_key(app):
app.env.indexentries.clear()
# At present, only glossary directive is able to create index key # At present, only glossary directive is able to create index key
text = (".. glossary::\n" text = (".. glossary::\n"
"\n" "\n"