From 38ce3f954da16fa60c35e97586b35d0c5e852d59 Mon Sep 17 00:00:00 2001 From: Antoine Lambert <anlambert@softwareheritage.org> Date: Fri, 17 Nov 2023 11:18:58 +0100 Subject: [PATCH] sphinx/conf.py: Filter out warnings related to extension paralell read Some extensions we are using does not declare them as safe for parallel read so sphinx emits warnings when parallel build is used. Filter out these warnings to fix CI builds. --- swh/docs/sphinx/conf.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/swh/docs/sphinx/conf.py b/swh/docs/sphinx/conf.py index d01d2388..0e798647 100755 --- a/swh/docs/sphinx/conf.py +++ b/swh/docs/sphinx/conf.py @@ -322,6 +322,15 @@ def add_glossary_to_index(app, docname, source): source[0] += "\n" + glossary.read() +def get_sphinx_warning_handler(): + from sphinx.util.logging import WarningStreamHandler + + logger = logging.getLogger("sphinx") + for handler in logger.handlers: + if isinstance(handler, WarningStreamHandler): + return handler + + def setup(app): # env-purge-doc event is fired before source-read app.connect("env-purge-doc", set_django_settings) @@ -331,7 +340,18 @@ def setup(app): # the documentation os.environ["SWH_DOC_BUILD"] = "1" - logger = logging.getLogger("sphinx") + # filter out parallel read in sphinx extension warnings + # to not consider them as errors when using -W option of sphinx-build + class ParallelReadWarningFilter(logging.Filter): + def filter(self, record: logging.LogRecord) -> bool: + message = record.getMessage() + return ( + "extension does not declare if it is safe for parallel reading" + not in message + ) and message != "doing serial read" + + # insert a custom filter in the warning log handler of sphinx + get_sphinx_warning_handler().filters.insert(0, ParallelReadWarningFilter()) if swh_package_doc_tox_build: # ensure glossary will be available in package doc scope @@ -339,7 +359,6 @@ def setup(app): # suppress some httpdomain warnings in non web packages if not any([pattern in str(app.srcdir) for pattern in ("swh-web", "DWAPPS")]): - # filter out httpdomain unresolved reference warnings # to not consider them as errors when using -W option of sphinx-build class HttpDomainRefWarningFilter(logging.Filter): @@ -347,7 +366,7 @@ def setup(app): return not record.msg.startswith("Cannot resolve reference to") # insert a custom filter in the warning log handler of sphinx - logger.handlers[1].filters.insert(0, HttpDomainRefWarningFilter()) + get_sphinx_warning_handler().filters.insert(0, HttpDomainRefWarningFilter()) else: -- GitLab