Skip to content

Commit 58e3e82

Browse files
committed
singlebuilder: switch to using write_documents call
Sphinx's builder implementation has added a final hint on the `write` call and introduced a `write_documents` as a more appropriate hook for processing documents [1]. This commit updates `SingleConfluenceBuilder` to no longer use `write`, except for supporting legacy versions of Sphinx that this extension still supports. [1]: sphinx-doc/sphinx#12767 Signed-off-by: James Knight <[email protected]>
1 parent b341fc4 commit 58e3e82

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

sphinxcontrib/confluencebuilder/singlebuilder.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright 2007-2019 by the Sphinx team (sphinx-doc/sphinx#AUTHORS)
44

55
from docutils import nodes
6+
from sphinx import version_info as sphinx_version_info
67
from sphinx.util.console import darkgreen # pylint: disable=no-name-in-module
78
from sphinx.util.display import progress_message
89
from sphinxcontrib.confluencebuilder.builder import ConfluenceBuilder
@@ -16,6 +17,20 @@ class SingleConfluenceBuilder(ConfluenceBuilder):
1617
name = 'singleconfluence'
1718
supported_linkcode = name
1819

20+
def __init__(self, app, env=None):
21+
super().__init__(app, env)
22+
23+
# As of Sphinx v8.1, the builder's the `write` call has be finalized.
24+
# Support has been added to use the new `write_documents` call. To
25+
# handle older versions of Sphinx this extension supports, register
26+
# a `write` hook override still.
27+
if sphinx_version_info < (8, 1, 0):
28+
def compat(self, *args, **kwargs):
29+
self.write_documents(None)
30+
31+
# pylint: disable=E1111
32+
self.write = compat.__get__(self, self.__class__)
33+
1934
def assemble_doctree(self):
2035
root_doc = self.config.root_doc
2136
tree = self.env.get_doctree(root_doc)
@@ -64,12 +79,11 @@ def get_target_uri(self, docname, typ=None):
6479

6580
return self.link_transform(docname)
6681

67-
def write(self, build_docnames, updated_docnames, method='update'):
68-
docnames = self.env.all_docs
69-
if self.config.root_doc not in docnames:
70-
logger.error('singleconfluence requires root_doc')
71-
return
82+
def prepare_writing(self, docnames):
83+
# override; nothing to prepare
84+
pass
7285

86+
def write_documents(self, _docnames):
7387
root_doctitle = self._process_root_document()
7488
if not root_doctitle:
7589
logger.error('singleconfluence requires title on root_doc')
@@ -100,7 +114,7 @@ def write(self, build_docnames, updated_docnames, method='update'):
100114
# register title targets for references before assembling doc
101115
# re-works them into a single document
102116
title_db = {}
103-
for docname in docnames:
117+
for docname in self.env.all_docs:
104118
doctree = self.env.get_doctree(docname)
105119
self._register_doctree_targets(docname, doctree, title_db)
106120

0 commit comments

Comments
 (0)