2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Warn about duplicate .. statement:: definitions

This commit is contained in:
Petr Špaček
2022-05-12 09:51:41 +02:00
parent 2f2aa1d21c
commit ff577462f9

View File

@@ -30,8 +30,12 @@ from sphinx import addnodes
from sphinx.directives import ObjectDescription from sphinx.directives import ObjectDescription
from sphinx.domains import Domain from sphinx.domains import Domain
from sphinx.roles import XRefRole from sphinx.roles import XRefRole
from sphinx.util.nodes import make_refnode from sphinx.util import logging
from sphinx.util.docutils import SphinxDirective from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import make_refnode
logger = logging.getLogger(__name__)
def split_csv(argument, required): def split_csv(argument, required):
@@ -96,7 +100,7 @@ def domain_factory(domainname, domainlabel, todolist):
signode["ids"].append(domainname + "-statement-" + sig) signode["ids"].append(domainname + "-statement-" + sig)
iscconf = self.env.get_domain(domainname) iscconf = self.env.get_domain(domainname)
iscconf.add_statement(sig, self.isc_tags, self.isc_short) iscconf.add_statement(sig, self.isc_tags, self.isc_short, self.lineno)
@property @property
def isc_tags(self): def isc_tags(self):
@@ -179,7 +183,18 @@ def domain_factory(domainname, domainlabel, todolist):
""" """
raise NotImplementedError raise NotImplementedError
def add_statement(self, signature, tags, short): @staticmethod
def log_statement_overlap(new, old):
assert new["fullname"] == old["fullname"]
logger.warning(
"duplicite detected! %s previously defined at %s:%d",
new["fullname"],
old["filename"],
old["lineno"],
location=(new["docname"], new["lineno"]),
)
def add_statement(self, signature, tags, short, lineno):
""" """
Add a new statement to the domain data structures. Add a new statement to the domain data structures.
No visible effect. No visible effect.
@@ -187,9 +202,11 @@ def domain_factory(domainname, domainlabel, todolist):
name = "{}.{}.{}".format(domainname, "statement", signature) name = "{}.{}.{}".format(domainname, "statement", signature)
anchor = "{}-statement-{}".format(domainname, signature) anchor = "{}-statement-{}".format(domainname, signature)
self.data["statements"][name] = { new = {
"tags": tags, "tags": tags,
"short": short, "short": short,
"filename": self.env.doc2path(self.env.docname),
"lineno": lineno,
# Sphinx API # Sphinx API
"fullname": name, # internal name "fullname": name, # internal name
"signature": signature, # display name "signature": signature, # display name
@@ -199,6 +216,10 @@ def domain_factory(domainname, domainlabel, todolist):
"priority": 1, # search priority "priority": 1, # search priority
} }
if name in self.data["statements"]:
self.log_statement_overlap(new, self.data["statements"][name])
self.data["statements"][name] = new
def clear_doc(self, docname): def clear_doc(self, docname):
""" """
Sphinx API: like env-purge-doc event, but in a domain. Sphinx API: like env-purge-doc event, but in a domain.
@@ -218,13 +239,12 @@ def domain_factory(domainname, domainlabel, todolist):
domaindata inventory (coming from a subprocess in parallel builds). domaindata inventory (coming from a subprocess in parallel builds).
@param otherdata is self.data equivalent from another process @param otherdata is self.data equivalent from another process
"""
Beware: As of Sphinx 4.5.0, this is called multiple times in a row old = self.data["statements"]
with the same data and has to guard against duplicites. It seems new = otherdata["statements"]
that all existing domains in Sphinx distribution have todo like for name in set(old).intersection(set(new)):
"deal with duplicates" but do nothing about them, so we just follow self.log_statement_overlap(new[name], old[name])
the suite.""" old.update(new)
self.data["statements"].update(otherdata["statements"])
@classmethod @classmethod
def process_statementlist_nodes(cls, app, doctree, fromdocname): def process_statementlist_nodes(cls, app, doctree, fromdocname):