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 <zigo@debian.org>
Change-Id: I4ab81ff4a4374709961fbbf126482a8b746a0227
Closes-bug: 2139378
This commit is contained in:
Thomas Goirand
2025-10-24 12:38:34 +02:00
committed by sean mooney
parent 74efcbf999
commit d30da847e2

View File

@@ -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'<watcher-{self.__class__.__name__.lower()}>'
# 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 ""