Merge pull request #5386 from tk0miya/add_IndexEntriesMigrator

refactor: Add IndexEntriesMigrator to simplify
This commit is contained in:
Takeshi KOMIYA 2018-09-06 02:05:54 +09:00 committed by GitHub
commit 9553453424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -50,11 +50,7 @@ class IndexEntriesCollector(EnvironmentCollector):
node.parent.remove(node)
else:
for entry in node['entries']:
if len(entry) == 5:
# Since 1.4: new index structure including index_key (5th column)
entries.append(entry)
else:
entries.append(entry + (None,))
def setup(app):

View File

@ -14,9 +14,12 @@ from __future__ import absolute_import
import sys
import warnings
from docutils.utils import get_source_line
from six import string_types, iteritems
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx import addnodes
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
from sphinx.transforms import SphinxTransform
from sphinx.util import import_object
if False:
@ -52,8 +55,23 @@ def register_application_for_autosummary(app):
autosummary._app = app
class IndexEntriesMigrator(SphinxTransform):
"""Migrating indexentries from old style (4columns) to new style (5columns)."""
default_priority = 700
def apply(self):
for node in self.document.traverse(addnodes.index):
for entries in node['entries']:
if len(entries) == 4:
source, line = get_source_line(node)
warnings.warn('An old styled index node found: %r at (%s:%s)' %
(node, source, line), RemovedInSphinx40Warning)
entries.extend([None])
def setup(app):
# type: (Sphinx) -> Dict[unicode, Any]
app.add_transform(IndexEntriesMigrator)
app.connect('config-inited', deprecate_source_parsers)
app.connect('builder-inited', register_application_for_autosummary)