Changeset View
Changeset View
Standalone View
Standalone View
swh/docs/sphinx/conf.py
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | def setup(app): | ||||
httpdomain = pkg_resources.get_distribution("sphinxcontrib-httpdomain") | httpdomain = pkg_resources.get_distribution("sphinxcontrib-httpdomain") | ||||
if StrictVersion(httpdomain.version) <= StrictVersion("1.7.0"): | if StrictVersion(httpdomain.version) <= StrictVersion("1.7.0"): | ||||
app.connect("doctree-read", register_routingtable_as_label) | app.connect("doctree-read", register_routingtable_as_label) | ||||
if swh_package_doc_tox_build: | if swh_package_doc_tox_build: | ||||
# ensure glossary will be available in package doc scope | # ensure glossary will be available in package doc scope | ||||
app.connect("source-read", add_glossary_to_index) | app.connect("source-read", add_glossary_to_index) | ||||
# suppress httpdomain warnings in non web packages | # suppress some httpdomain warnings in non web packages | ||||
if "swh-web" not in app.srcdir: | if "swh-web" not in app.srcdir: | ||||
# filter out httpdomain unresolved reference warnings | # filter out httpdomain unresolved reference warnings | ||||
# to not consider them as errors when using -W option of sphinx-build | # to not consider them as errors when using -W option of sphinx-build | ||||
class HttpDomainWarningFilter(logging.Filter): | class HttpDomainWarningFilter(logging.Filter): | ||||
def filter(self, record: logging.LogRecord) -> bool: | def filter(self, record: logging.LogRecord) -> bool: | ||||
return not record.msg.startswith("Cannot resolve reference to") | return not record.msg.startswith("Cannot resolve reference to") | ||||
# suppress some httpdomain warnings in web package | |||||
else: | |||||
# filter out non critical warnings appeared with sphinx 4.1 release | |||||
# TODO: remove that hack when that pull request gets merged | |||||
# https://github.com/sphinx-contrib/httpdomain/pull/51 | |||||
class HttpDomainWarningFilter(logging.Filter): | |||||
def filter(self, record: logging.LogRecord) -> bool: | |||||
return not ( | |||||
record.args | |||||
and type(record.args) == tuple # to keep mypy happy | |||||
and record.args[0] == "http" | |||||
and record.msg.endswith("but that role is not in the domain.") | |||||
) | |||||
logger = logging.getLogger("sphinx") | logger = logging.getLogger("sphinx") | ||||
# insert a custom filter in the warning log handler of sphinx | # insert a custom filter in the warning log handler of sphinx | ||||
logger.handlers[1].filters.insert(0, HttpDomainWarningFilter()) | logger.handlers[1].filters.insert(0, HttpDomainWarningFilter()) |