docs: kdoc: handle the obsolescensce of docutils.ErrorString()

The ErrorString() and SafeString() docutils functions were helpers meant to
ease the handling of encodings during the Python 3 transition.  There is no
real need for them after Python 3.6, and docutils 0.22 removes them,
breaking the docs build

Handle this by just injecting our own one-liner version of ErrorString(),
and removing the sole SafeString() call entirely.

Reported-by: Zhixu Liu <zhixu.liu@gmail.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <87ldmnv2pi.fsf@trenco.lwn.net>
This commit is contained in:
Jonathan Corbet 2025-09-09 13:35:37 -06:00
parent 944df7a314
commit 00d95fcc4d
3 changed files with 10 additions and 4 deletions

View file

@ -40,9 +40,11 @@ import sys
from docutils import nodes, statemachine from docutils import nodes, statemachine
from docutils.statemachine import ViewList from docutils.statemachine import ViewList
from docutils.parsers.rst import directives, Directive from docutils.parsers.rst import directives, Directive
from docutils.utils.error_reporting import ErrorString
from sphinx.util.docutils import switch_source_input from sphinx.util.docutils import switch_source_input
def ErrorString(exc): # Shamelessly stolen from docutils
return f'{exc.__class__.__name}: {exc}'
__version__ = '1.0' __version__ = '1.0'
def setup(app): def setup(app):

View file

@ -89,7 +89,6 @@ import sys
from docutils import io, nodes, statemachine from docutils import io, nodes, statemachine
from docutils.statemachine import ViewList from docutils.statemachine import ViewList
from docutils.utils.error_reporting import SafeString, ErrorString
from docutils.parsers.rst import Directive, directives from docutils.parsers.rst import Directive, directives
from docutils.parsers.rst.directives.body import CodeBlock, NumberLines from docutils.parsers.rst.directives.body import CodeBlock, NumberLines
@ -106,6 +105,9 @@ logger = logging.getLogger(__name__)
RE_DOMAIN_REF = re.compile(r'\\ :(ref|c:type|c:func):`([^<`]+)(?:<([^>]+)>)?`\\') RE_DOMAIN_REF = re.compile(r'\\ :(ref|c:type|c:func):`([^<`]+)(?:<([^>]+)>)?`\\')
RE_SIMPLE_REF = re.compile(r'`([^`]+)`') RE_SIMPLE_REF = re.compile(r'`([^`]+)`')
def ErrorString(exc): # Shamelessly stolen from docutils
return f'{exc.__class__.__name}: {exc}'
# ============================================================================== # ==============================================================================
class KernelInclude(Directive): class KernelInclude(Directive):
@ -156,7 +158,7 @@ class KernelInclude(Directive):
except UnicodeEncodeError: except UnicodeEncodeError:
raise self.severe('Problems with directive path:\n' raise self.severe('Problems with directive path:\n'
'Cannot encode input file path "%s" ' 'Cannot encode input file path "%s" '
'(wrong locale?).' % SafeString(path)) '(wrong locale?).' % path)
except IOError as error: except IOError as error:
raise self.severe('Problems with directive path:\n%s.' % ErrorString(error)) raise self.severe('Problems with directive path:\n%s.' % ErrorString(error))

View file

@ -22,10 +22,12 @@ import re
import os.path import os.path
from docutils import statemachine from docutils import statemachine
from docutils.utils.error_reporting import ErrorString
from docutils.parsers.rst import Directive from docutils.parsers.rst import Directive
from docutils.parsers.rst.directives.misc import Include from docutils.parsers.rst.directives.misc import Include
def ErrorString(exc): # Shamelessly stolen from docutils
return f'{exc.__class__.__name}: {exc}'
__version__ = '1.0' __version__ = '1.0'
def setup(app): def setup(app):