Skip to content

Commit c830fa9

Browse files
mchehabgregkh
authored andcommitted
docs: kernel_abi.py: make it compatible with Sphinx 1.7+
The same way kerneldoc.py needed changes to work with newer Sphinx, this script needs the same changes. While here, reorganize the include order to match kerneldoc.py. Acked-by: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Link: https://lore.kernel.org/r/f2b25caef5db7738629773a03463908d3b39b83a.1604042072.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 823830d commit c830fa9

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

Documentation/sphinx/kernel_abi.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@
3333
"""
3434

3535
import codecs
36-
import sys
3736
import os
38-
from os import path
3937
import subprocess
38+
import sys
4039

41-
from sphinx.ext.autodoc import AutodocReporter
40+
from os import path
4241

43-
from docutils import nodes
44-
from docutils.parsers.rst import Directive, directives
42+
from docutils import nodes, statemachine
4543
from docutils.statemachine import ViewList
44+
from docutils.parsers.rst import directives, Directive
4645
from docutils.utils.error_reporting import ErrorString
4746

47+
#
48+
# AutodocReporter is only good up to Sphinx 1.7
49+
#
50+
import sphinx
51+
52+
Use_SSI = sphinx.__version__[:3] >= '1.7'
53+
if Use_SSI:
54+
from sphinx.util.docutils import switch_source_input
55+
else:
56+
from sphinx.ext.autodoc import AutodocReporter
4857

4958
__version__ = '1.0'
5059

@@ -142,11 +151,17 @@ def nestedParse(self, lines, fname):
142151
content.append(l, fname, c)
143152

144153
buf = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter
145-
self.state.memo.title_styles = []
146-
self.state.memo.section_level = 0
147-
self.state.memo.reporter = AutodocReporter(content, self.state.memo.reporter)
148-
try:
149-
self.state.nested_parse(content, 0, node, match_titles=1)
150-
finally:
151-
self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
154+
155+
if Use_SSI:
156+
with switch_source_input(self.state, content):
157+
self.state.nested_parse(content, 0, node, match_titles=1)
158+
else:
159+
self.state.memo.title_styles = []
160+
self.state.memo.section_level = 0
161+
self.state.memo.reporter = AutodocReporter(content, self.state.memo.reporter)
162+
try:
163+
self.state.nested_parse(content, 0, node, match_titles=1)
164+
finally:
165+
self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = buf
166+
152167
return node.children

0 commit comments

Comments
 (0)