From d30da847e2cb95de9c69794378786e45cced48b3 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Fri, 24 Oct 2025 12:38:34 +0200 Subject: [PATCH] Fix term.py with 0.22.2 As per this Debian bug: https://bugs.debian.org/1118332 watcher fails to build from source with python3-docutils 0.22.2. This patch fixes this. Signed-off-by: Thomas Goirand Change-Id: I4ab81ff4a4374709961fbbf126482a8b746a0227 Closes-bug: 2139378 --- doc/ext/term.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/ext/term.py b/doc/ext/term.py index c521ddb92..0ab6f826f 100644 --- a/doc/ext/term.py +++ b/doc/ext/term.py @@ -37,11 +37,22 @@ class BaseWatcherDirective(rst.Directive): def add_line(self, line, *lineno): """Append one line of generated reST to the output.""" - self.result.append(line, rst.directives.unchanged, *lineno) + # Provide a proper source string to avoid issues with newer docutils + # Try to get the actual source file, fallback to class name + source = getattr(self.state.document, 'current_source', None) + if source is None: + source = f'' + + # Handle lineno properly - use the first arg from *lineno if provided, otherwise use self.lineno + actual_lineno = lineno[0] if lineno else getattr(self, "lineno", 0) + + # For newer docutils, ensure source is always a string + self.result.append(line, source, actual_lineno) def add_textblock(self, textblock): - for line in textblock.splitlines(): - self.add_line(line) + base_lineno = getattr(self, "lineno", 0) + for i, line in enumerate(textblock.splitlines()): + self.add_line(line, base_lineno + i) def add_object_docstring(self, obj): obj_raw_docstring = obj.__doc__ or ""