|
7 | 7 | from __future__ import annotations
|
8 | 8 |
|
9 | 9 | import copy
|
10 |
| -from abc import ABC, abstractmethod |
11 |
| -from collections.abc import Callable |
12 |
| -from typing import TYPE_CHECKING, Any, NamedTuple, cast |
| 10 | +from typing import TYPE_CHECKING, Any, cast |
13 | 11 |
|
14 |
| -from docutils.nodes import Element, Node, system_message |
15 |
| - |
16 |
| -from sphinx.errors import SphinxError |
| 12 | +from sphinx.domains._index import Index, IndexEntry |
17 | 13 | from sphinx.locale import _
|
18 | 14 |
|
19 | 15 | if TYPE_CHECKING:
|
20 |
| - from collections.abc import Iterable, Sequence |
21 |
| - from typing import TypeAlias |
| 16 | + from collections.abc import Callable, Iterable, Sequence |
22 | 17 |
|
23 | 18 | from docutils import nodes
|
| 19 | + from docutils.nodes import Element, Node |
24 | 20 | from docutils.parsers.rst import Directive
|
25 | 21 | from docutils.parsers.rst.states import Inliner
|
26 | 22 |
|
27 | 23 | from sphinx.addnodes import pending_xref
|
28 | 24 | from sphinx.builders import Builder
|
29 | 25 | from sphinx.environment import BuildEnvironment
|
30 | 26 | from sphinx.roles import XRefRole
|
31 |
| - from sphinx.util.typing import RoleFunction |
| 27 | + from sphinx.util.typing import RoleFunction, TitleGetter |
| 28 | + |
| 29 | +__all__ = ( |
| 30 | + 'Domain', |
| 31 | + 'Index', |
| 32 | + 'IndexEntry', |
| 33 | + 'ObjType', |
| 34 | +) |
32 | 35 |
|
33 | 36 |
|
34 | 37 | class ObjType:
|
@@ -57,107 +60,6 @@ def __init__(self, lname: str, *roles: Any, **attrs: Any) -> None:
|
57 | 60 | self.attrs.update(attrs)
|
58 | 61 |
|
59 | 62 |
|
60 |
| -class IndexEntry(NamedTuple): |
61 |
| - name: str |
62 |
| - subtype: int |
63 |
| - docname: str |
64 |
| - anchor: str |
65 |
| - extra: str |
66 |
| - qualifier: str |
67 |
| - descr: str |
68 |
| - |
69 |
| - |
70 |
| -class Index(ABC): |
71 |
| - """ |
72 |
| - An Index is the description for a domain-specific index. To add an index to |
73 |
| - a domain, subclass Index, overriding the three name attributes: |
74 |
| -
|
75 |
| - * `name` is an identifier used for generating file names. |
76 |
| - It is also used for a hyperlink target for the index. Therefore, users can |
77 |
| - refer the index page using ``ref`` role and a string which is combined |
78 |
| - domain name and ``name`` attribute (ex. ``:ref:`py-modindex```). |
79 |
| - * `localname` is the section title for the index. |
80 |
| - * `shortname` is a short name for the index, for use in the relation bar in |
81 |
| - HTML output. Can be empty to disable entries in the relation bar. |
82 |
| -
|
83 |
| - and providing a :meth:`generate()` method. Then, add the index class to |
84 |
| - your domain's `indices` list. Extensions can add indices to existing |
85 |
| - domains using :meth:`~sphinx.application.Sphinx.add_index_to_domain()`. |
86 |
| -
|
87 |
| - .. versionchanged:: 3.0 |
88 |
| -
|
89 |
| - Index pages can be referred by domain name and index name via |
90 |
| - :rst:role:`ref` role. |
91 |
| - """ |
92 |
| - |
93 |
| - name: str |
94 |
| - localname: str |
95 |
| - shortname: str | None = None |
96 |
| - |
97 |
| - def __init__(self, domain: Domain) -> None: |
98 |
| - if not self.name or self.localname is None: |
99 |
| - raise SphinxError('Index subclass %s has no valid name or localname' |
100 |
| - % self.__class__.__name__) |
101 |
| - self.domain = domain |
102 |
| - |
103 |
| - @abstractmethod |
104 |
| - def generate(self, docnames: Iterable[str] | None = None, |
105 |
| - ) -> tuple[list[tuple[str, list[IndexEntry]]], bool]: |
106 |
| - """Get entries for the index. |
107 |
| -
|
108 |
| - If ``docnames`` is given, restrict to entries referring to these |
109 |
| - docnames. |
110 |
| -
|
111 |
| - The return value is a tuple of ``(content, collapse)``: |
112 |
| -
|
113 |
| - ``collapse`` |
114 |
| - A boolean that determines if sub-entries should start collapsed (for |
115 |
| - output formats that support collapsing sub-entries). |
116 |
| -
|
117 |
| - ``content``: |
118 |
| - A sequence of ``(letter, entries)`` tuples, where ``letter`` is the |
119 |
| - "heading" for the given ``entries``, usually the starting letter, and |
120 |
| - ``entries`` is a sequence of single entries. Each entry is a sequence |
121 |
| - ``[name, subtype, docname, anchor, extra, qualifier, descr]``. The |
122 |
| - items in this sequence have the following meaning: |
123 |
| -
|
124 |
| - ``name`` |
125 |
| - The name of the index entry to be displayed. |
126 |
| -
|
127 |
| - ``subtype`` |
128 |
| - The sub-entry related type. One of: |
129 |
| -
|
130 |
| - ``0`` |
131 |
| - A normal entry. |
132 |
| - ``1`` |
133 |
| - An entry with sub-entries. |
134 |
| - ``2`` |
135 |
| - A sub-entry. |
136 |
| -
|
137 |
| - ``docname`` |
138 |
| - *docname* where the entry is located. |
139 |
| -
|
140 |
| - ``anchor`` |
141 |
| - Anchor for the entry within ``docname`` |
142 |
| -
|
143 |
| - ``extra`` |
144 |
| - Extra info for the entry. |
145 |
| -
|
146 |
| - ``qualifier`` |
147 |
| - Qualifier for the description. |
148 |
| -
|
149 |
| - ``descr`` |
150 |
| - Description for the entry. |
151 |
| -
|
152 |
| - Qualifier and description are not rendered for some output formats such |
153 |
| - as LaTeX. |
154 |
| - """ |
155 |
| - raise NotImplementedError |
156 |
| - |
157 |
| - |
158 |
| -TitleGetter: TypeAlias = Callable[[Node], str | None] |
159 |
| - |
160 |
| - |
161 | 63 | class Domain:
|
162 | 64 | """
|
163 | 65 | A Domain is meant to be a group of "object" description directives for
|
@@ -268,7 +170,7 @@ def role(self, name: str) -> RoleFunction | None:
|
268 | 170 | def role_adapter(typ: str, rawtext: str, text: str, lineno: int,
|
269 | 171 | inliner: Inliner, options: dict | None = None,
|
270 | 172 | content: Sequence[str] = (),
|
271 |
| - ) -> tuple[list[Node], list[system_message]]: |
| 173 | + ) -> tuple[list[Node], list[nodes.system_message]]: |
272 | 174 | return self.roles[name](fullname, rawtext, text, lineno,
|
273 | 175 | inliner, options or {}, content)
|
274 | 176 | self._role_cache[name] = role_adapter
|
|
0 commit comments