Use keyword-arguments with `IndexEntry`

This commit is contained in:
Adam Turner 2024-10-25 17:49:30 +01:00
parent bd7d595c6b
commit 8682f64b6f
2 changed files with 176 additions and 47 deletions

View File

@ -594,19 +594,42 @@ class PythonModuleIndex(Index):
# first submodule - make parent a group head
if entries:
last = entries[-1]
entries[-1] = IndexEntry(last[0], 1, last[2], last[3],
last[4], last[5], last[6])
entries[-1] = IndexEntry(
name=last.name,
subtype=1,
docname=last.docname,
anchor=last.anchor,
extra=last.extra,
qualifier=last.qualifier,
descr=last.descr,
)
elif not prev_modname.startswith(package):
# submodule without parent in list, add dummy entry
entries.append(IndexEntry(stripped + package, 1, '', '', '', '', ''))
dummy_entry = IndexEntry(
name=stripped + package,
subtype=1,
docname='',
anchor='',
extra='',
qualifier='',
descr='',
)
entries.append(dummy_entry)
subtype = 2
else:
num_toplevels += 1
subtype = 0
qualifier = _('Deprecated') if deprecated else ''
entries.append(IndexEntry(stripped + modname, subtype, docname,
node_id, platforms, qualifier, synopsis))
entry = IndexEntry(
name=stripped + modname,
subtype=subtype,
docname=module.docname,
anchor=module.node_id,
extra=module.platform,
qualifier=_('Deprecated') if module.deprecated else '',
descr=module.synopsis,
)
entries.append(entry)
prev_modname = modname
# apply heuristics when to collapse modindex at page load:

View File

@ -572,34 +572,67 @@ def test_module_index(app):
index = PythonModuleIndex(app.env.domains.python_domain)
assert index.generate() == (
[
('d', [IndexEntry('docutils', 0, 'index', 'module-docutils', '', '', '')]),
(
'd',
[
IndexEntry(
name='docutils',
subtype=0,
docname='index',
anchor='module-docutils',
extra='',
qualifier='',
descr='',
),
],
),
(
's',
[
IndexEntry('sphinx', 1, 'index', 'module-sphinx', '', '', ''),
IndexEntry(
'sphinx.builders',
2,
'index',
'module-sphinx.builders',
'',
'',
'',
name='sphinx',
subtype=1,
docname='index',
anchor='module-sphinx',
extra='',
qualifier='',
descr='',
),
IndexEntry(
'sphinx.builders.html',
2,
'index',
'module-sphinx.builders.html',
'',
'',
'',
name='sphinx.builders',
subtype=2,
docname='index',
anchor='module-sphinx.builders',
extra='',
qualifier='',
descr='',
),
IndexEntry(
'sphinx.config', 2, 'index', 'module-sphinx.config', '', '', ''
name='sphinx.builders.html',
subtype=2,
docname='index',
anchor='module-sphinx.builders.html',
extra='',
qualifier='',
descr='',
),
IndexEntry(
'sphinx_intl', 0, 'index', 'module-sphinx_intl', '', '', ''
name='sphinx.config',
subtype=2,
docname='index',
anchor='module-sphinx.config',
extra='',
qualifier='',
descr='',
),
IndexEntry(
name='sphinx_intl',
subtype=0,
docname='index',
anchor='module-sphinx_intl',
extra='',
qualifier='',
descr='',
),
],
),
@ -618,9 +651,23 @@ def test_module_index_submodule(app):
(
's',
[
IndexEntry('sphinx', 1, '', '', '', '', ''),
IndexEntry(
'sphinx.config', 2, 'index', 'module-sphinx.config', '', '', ''
name='sphinx',
subtype=1,
docname='',
anchor='',
extra='',
qualifier='',
descr='',
),
IndexEntry(
name='sphinx.config',
subtype=2,
docname='index',
anchor='module-sphinx.config',
extra='',
qualifier='',
descr='',
),
],
)
@ -636,8 +683,34 @@ def test_module_index_not_collapsed(app):
index = PythonModuleIndex(app.env.domains.python_domain)
assert index.generate() == (
[
('d', [IndexEntry('docutils', 0, 'index', 'module-docutils', '', '', '')]),
('s', [IndexEntry('sphinx', 0, 'index', 'module-sphinx', '', '', '')]),
(
'd',
[
IndexEntry(
name='docutils',
subtype=0,
docname='index',
anchor='module-docutils',
extra='',
qualifier='',
descr='',
),
],
),
(
's',
[
IndexEntry(
name='sphinx',
subtype=0,
docname='index',
anchor='module-sphinx',
extra='',
qualifier='',
descr='',
),
],
),
],
True,
)
@ -666,22 +739,22 @@ def test_modindex_common_prefix(app):
'b',
[
IndexEntry(
'sphinx.builders',
1,
'index',
'module-sphinx.builders',
'',
'',
'',
name='sphinx.builders',
subtype=1,
docname='index',
anchor='module-sphinx.builders',
extra='',
qualifier='',
descr='',
),
IndexEntry(
'sphinx.builders.html',
2,
'index',
'module-sphinx.builders.html',
'',
'',
'',
name='sphinx.builders.html',
subtype=2,
docname='index',
anchor='module-sphinx.builders.html',
extra='',
qualifier='',
descr='',
),
],
),
@ -689,17 +762,50 @@ def test_modindex_common_prefix(app):
'c',
[
IndexEntry(
'sphinx.config', 0, 'index', 'module-sphinx.config', '', '', ''
)
name='sphinx.config',
subtype=0,
docname='index',
anchor='module-sphinx.config',
extra='',
qualifier='',
descr='',
),
],
),
(
'd',
[
IndexEntry(
name='docutils',
subtype=0,
docname='index',
anchor='module-docutils',
extra='',
qualifier='',
descr='',
),
],
),
('d', [IndexEntry('docutils', 0, 'index', 'module-docutils', '', '', '')]),
(
's',
[
IndexEntry('sphinx', 0, 'index', 'module-sphinx', '', '', ''),
IndexEntry(
'sphinx_intl', 0, 'index', 'module-sphinx_intl', '', '', ''
name='sphinx',
subtype=0,
docname='index',
anchor='module-sphinx',
extra='',
qualifier='',
descr='',
),
IndexEntry(
name='sphinx_intl',
subtype=0,
docname='index',
anchor='module-sphinx_intl',
extra='',
qualifier='',
descr='',
),
],
),