From f534ef291b1a203146d63c06addd41860a4bec3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0pa=C4=8Dek?= Date: Wed, 20 Jul 2022 18:44:48 +0200 Subject: [PATCH] Support Sphinx 1.6.7 Luckily we don't rely on SphinxDirective functionality which does not exist in 1.6.7. Replace it with docutils Directive. transform_content() callback was added only in Sphinx 3.0.0. Detect if it was not called and call it manually. The transform_content() function requires access to inner "contentnode" which is created inside run(). This workaround relies on the order of node as it was in the pre-3.0.0 versions, but it should not matter as new versions will not trigger the workaround. --- doc/arm/_ext/iscconf.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/arm/_ext/iscconf.py b/doc/arm/_ext/iscconf.py index 10c24040fe..b5bd966e2a 100644 --- a/doc/arm/_ext/iscconf.py +++ b/doc/arm/_ext/iscconf.py @@ -23,7 +23,7 @@ https://www.sphinx-doc.org/en/master/development/tutorials/recipe.html from collections import namedtuple -from docutils.parsers.rst import directives +from docutils.parsers.rst import Directive, directives from docutils import nodes from sphinx import addnodes @@ -31,7 +31,6 @@ from sphinx.directives import ObjectDescription from sphinx.domains import Domain from sphinx.roles import XRefRole from sphinx.util import logging -from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import make_refnode import checkgrammar @@ -61,7 +60,7 @@ def domain_factory(domainname, domainlabel, todolist, grammar): See StatementListDirective. """ - class StatementListDirective(SphinxDirective): + class StatementListDirective(Directive): """A custom directive to generate list of statements. It only installs placeholder which is later replaced by process_statementlist_nodes() callback. @@ -229,6 +228,7 @@ def domain_factory(domainname, domainlabel, todolist, grammar): def transform_content(self, contentnode: addnodes.desc_content) -> None: """autogenerate content from structured data""" + self.workaround_transform_content = True if self.isc_short: contentnode.insert(0, self.isc_short_node) if self.isc_tags: @@ -263,6 +263,19 @@ def domain_factory(domainname, domainlabel, todolist, grammar): if len(warn): contentnode.insert(0, warn) + def __init__(self, *args, **kwargs): + """Compability with Sphinx < 3.0.0""" + self.workaround_transform_content = False + super().__init__(*args, **kwargs) + + def run(self): + """Compability with Sphinx < 3.0.0""" + nodelist = super().run() + if not self.workaround_transform_content: + # get access to "contentnode" created inside super.run() + self.transform_content(nodelist[1][-1]) + return nodelist + name = domainname label = domainlabel