2 (taken from https://github.com/zephyrproject-rtos/zephyr/blob/main/doc/_extensions/zephyr/warnings_filter.py)
4 Warnings filter extension
5 #########################
7 Copyright (c) 2021 Nordic Semiconductor ASA
8 SPDX-License-Identifier: Apache-2.0
13 This Sphinx plugin can be used to filter out warnings that are known to be false
14 positives. The warnings are filtered out based on a set of regular expressions
15 given via an configuration file. The format of the configuration file is a
16 plain-text file where each line consists of a regular expression. Any lines
17 starting with ``#`` will be ignored.
22 - ``warnings_filter_config``: Configuration file.
23 - ``warnings_filter_silent``: Silent flag. If True, warning is hidden. If False
24 the warning is converted to an information message and displayed.
29 from typing
import Dict, Any, List
31 from sphinx.application
import Sphinx
32 from sphinx.util.logging
import NAMESPACE
42 expressions: List of regular expressions.
43 silent: If true, warning is hidden, otherwise it is shown as INFO.
47 def __init__(self, expressions: List[str], silent: bool, name: str =
"") ->
None:
53 def filter(self, record: logging.LogRecord) -> bool:
56 if re.match(expression,
str(record.msg)):
60 record.levelno = logging.INFO
61 record.msg = f
"Filtered warning: {record.msg}"
64 print(
"ERROR??", expression, record.msg,
type(record.msg))
74 app: Sphinx application instance.
78 with
open(app.config.warnings_filter_config)
as f:
80 for line
in f.readlines():
81 if not line.startswith(
"#"):
82 expressions.append(line.rstrip())
85 filter =
WarningsFilter(expressions, app.config.warnings_filter_silent)
86 logger = logging.getLogger(NAMESPACE)
87 for handler
in logger.handlers:
88 handler.filters.insert(0, filter)
91 def setup(app: Sphinx) -> Dict[str, Any]:
92 app.add_config_value(
"warnings_filter_config",
"",
"")
93 app.add_config_value(
"warnings_filter_silent",
True,
"")
95 app.connect(
"builder-inited", configure)
98 "version": __version__,
99 "parallel_read_safe":
True,
100 "parallel_write_safe":
True,