Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions _ext/syncthing_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
Modeled after the standard :directive:`cmdoption` directive.
"""

from typing import Tuple, Dict, Iterator, Set, NamedTuple
from typing import Any, Iterator, NamedTuple, Tuple

from docutils.nodes import Element
from docutils.parsers.rst import directives

from sphinx import addnodes
from sphinx.addnodes import pending_xref
from sphinx.builders import Builder
from sphinx.directives import ObjectDescription
from sphinx.domains import Domain, ObjType
from sphinx.environment import BuildEnvironment
from sphinx.roles import XRefRole
from sphinx.util.nodes import make_refnode
from sphinx.util import logging
from sphinx.util.nodes import make_refnode


__licence__ = 'BSD (3 clause)'
Expand Down Expand Up @@ -116,11 +117,11 @@ class SyncthingConfigDomain(Domain):
}

@property
def config_sections(self) -> Set[str]:
return self.data.setdefault('sections', [])
def config_sections(self) -> set[str]:
return self.data.setdefault('sections', set())

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

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

def clear_doc(self, docname: str):
self.data['options'] = {
signature: entry
for signature, entry in self.config_options.items()
if entry.docname != docname
}

def merge_domaindata(self, docnames: set[str], otherdata: dict[str, Any]):
self.config_sections.update(otherdata.get('sections', set()))

for signature, entry in otherdata.get('options', {}).items():
if entry.docname in docnames:
if signature in self.config_options:
other = self.config_options[signature]
logger.warning(
'Duplicate object description of %s, other instance in %s',
entry.name, other.docname
)
self.config_options[signature] = entry


def setup(app):
"""Install the plugin.

:param app: Sphinx application context.
"""
app.add_domain(SyncthingConfigDomain)
return
return {
'parallel_read_safe': True,
'parallel_write_safe': True,
}
Loading