Skip to content

Commit a59b729

Browse files
authored
fix: avoid warnings in custom config option extension (#1014)
* Clear option index for document on rebuild. Implement the clear_doc() method to fix warnings about duplicate object definitions when using incremental builds. The data attribute is cached in the build environment, thus the duplication warning triggers on each reprocessed document. But clear_doc() is called for each document being re-read, so it should simply remove the matching previous entries. Not important for sections, these amy simply linger after a partial rebuild if removed. No biggie. * Fix initialization type of initial sections data. As declared, the default value should be a set, while the initial_data template contained an empty list. * Implement merge_domaindata() method for safe parallel builds. Sphinx may process different documents concurrently in several runners. The resulting domain data (signatures and corresponding object entries) must be merged by the Domain code. Declare this extension safe for parallel processing with the method now implemented. * Modernize for Python >= 3.9, fix linter warnings. Signed-off-by: André Colomb <src@andre.colomb.de>
1 parent 7cf8f3b commit a59b729

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

_ext/syncthing_config.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
Modeled after the standard :directive:`cmdoption` directive.
55
"""
66

7-
from typing import Tuple, Dict, Iterator, Set, NamedTuple
7+
from typing import Any, Iterator, NamedTuple, Tuple
88

99
from docutils.nodes import Element
1010
from docutils.parsers.rst import directives
11+
1112
from sphinx import addnodes
1213
from sphinx.addnodes import pending_xref
1314
from sphinx.builders import Builder
1415
from sphinx.directives import ObjectDescription
1516
from sphinx.domains import Domain, ObjType
1617
from sphinx.environment import BuildEnvironment
1718
from sphinx.roles import XRefRole
18-
from sphinx.util.nodes import make_refnode
1919
from sphinx.util import logging
20+
from sphinx.util.nodes import make_refnode
2021

2122

2223
__licence__ = 'BSD (3 clause)'
@@ -116,11 +117,11 @@ class SyncthingConfigDomain(Domain):
116117
}
117118

118119
@property
119-
def config_sections(self) -> Set[str]:
120-
return self.data.setdefault('sections', [])
120+
def config_sections(self) -> set[str]:
121+
return self.data.setdefault('sections', set())
121122

122123
@property
123-
def config_options(self) -> Dict[str, Tuple]:
124+
def config_options(self) -> dict[str, Tuple]:
124125
return self.data.setdefault('options', {}) # fullname -> (docname, node_id)
125126

126127
def get_full_qualified_name(self, node): # FIXME: what is this for?!
@@ -168,11 +169,34 @@ def add_config_option(self, signature, section, option, anchor, location=None):
168169
docname=self.env.docname,
169170
anchor=anchor, priority=0)
170171

172+
def clear_doc(self, docname: str):
173+
self.data['options'] = {
174+
signature: entry
175+
for signature, entry in self.config_options.items()
176+
if entry.docname != docname
177+
}
178+
179+
def merge_domaindata(self, docnames: set[str], otherdata: dict[str, Any]):
180+
self.config_sections.update(otherdata.get('sections', set()))
181+
182+
for signature, entry in otherdata.get('options', {}).items():
183+
if entry.docname in docnames:
184+
if signature in self.config_options:
185+
other = self.config_options[signature]
186+
logger.warning(
187+
'Duplicate object description of %s, other instance in %s',
188+
entry.name, other.docname
189+
)
190+
self.config_options[signature] = entry
191+
171192

172193
def setup(app):
173194
"""Install the plugin.
174195
175196
:param app: Sphinx application context.
176197
"""
177198
app.add_domain(SyncthingConfigDomain)
178-
return
199+
return {
200+
'parallel_read_safe': True,
201+
'parallel_write_safe': True,
202+
}

0 commit comments

Comments
 (0)