9
9
import os
10
10
import re
11
11
from os import path
12
- from typing import Any
12
+ from typing import TYPE_CHECKING , Any
13
13
14
14
from docutils import nodes
15
15
from sphinx import addnodes
16
- from sphinx .application import Sphinx
17
16
from sphinx .builders .html import StandaloneHTMLBuilder
18
17
from sphinx .environment .adapters .indexentries import IndexEntries
19
18
from sphinx .locale import get_translation
20
19
from sphinx .util import logging
21
20
from sphinx .util .nodes import NodeMatcher
22
21
from sphinx .util .osutil import make_filename
23
22
24
- try :
25
- import xml . etree . ElementTree as etree
26
- except ImportError :
27
- import lxml .etree as etree # type: ignore
23
+ if TYPE_CHECKING :
24
+ from sphinx . application import Sphinx
25
+
26
+ import xml .etree . ElementTree as etree
28
27
29
28
__version__ = '1.0.6'
30
29
__version_info__ = (1 , 0 , 6 )
@@ -80,8 +79,7 @@ def build_devhelp(self, outdir: str | os.PathLike[str], outname: str) -> None:
80
79
self .config .master_doc , self , prune_toctrees = False )
81
80
82
81
def write_toc (node : nodes .Node , parent : etree .Element ) -> None :
83
- if isinstance (node , addnodes .compact_paragraph ) or \
84
- isinstance (node , nodes .bullet_list ):
82
+ if isinstance (node , (addnodes .compact_paragraph , nodes .bullet_list )):
85
83
for subnode in node :
86
84
write_toc (subnode , parent )
87
85
elif isinstance (node , nodes .list_item ):
@@ -93,7 +91,7 @@ def write_toc(node: nodes.Node, parent: etree.Element) -> None:
93
91
parent .attrib ['name' ] = node .astext ()
94
92
95
93
matcher = NodeMatcher (addnodes .compact_paragraph , toctree = Any )
96
- for node in tocdoc .findall (matcher ): # type: addnodes.compact_paragraph
94
+ for node in tocdoc .findall (matcher ):
97
95
write_toc (node , chapters )
98
96
99
97
# Index
@@ -115,7 +113,7 @@ def write_index(title: str, refs: list[Any], subitems: Any) -> None:
115
113
if subitems :
116
114
parent_title = re .sub (r'\s*\(.*\)\s*$' , '' , title )
117
115
for subitem in subitems :
118
- write_index ("%s %s" % ( parent_title , subitem [0 ]) ,
116
+ write_index (f' { parent_title } { subitem [0 ]} ' ,
119
117
subitem [1 ], [])
120
118
121
119
for (_group_key , group ) in index :
@@ -125,7 +123,7 @@ def write_index(title: str, refs: list[Any], subitems: Any) -> None:
125
123
# Dump the XML file
126
124
xmlfile = path .join (outdir , outname + '.devhelp.gz' )
127
125
with gzip .GzipFile (filename = xmlfile , mode = 'w' , mtime = 0 ) as f :
128
- tree .write (f , 'utf-8' ) # type: ignore
126
+ tree .write (f , 'utf-8' )
129
127
130
128
131
129
def setup (app : Sphinx ) -> dict [str , Any ]:
0 commit comments