Configure Sphinx's WarningHandler to handle (expected) missing include.
(app: "sphinx.application.Sphinx")
| 399 | |
| 400 | |
| 401 | def configure_logging(app: "sphinx.application.Sphinx") -> None: |
| 402 | """Configure Sphinx's WarningHandler to handle (expected) missing include.""" |
| 403 | import sphinx.util.logging |
| 404 | import logging |
| 405 | |
| 406 | class WarnLogFilter(logging.Filter): |
| 407 | def filter(self, record: logging.LogRecord) -> bool: |
| 408 | """Ignore warnings about missing include with "only" directive. |
| 409 | |
| 410 | Ref: https://github.com/sphinx-doc/sphinx/issues/2150.""" |
| 411 | if ( |
| 412 | record.msg.startswith('Problems with "include" directive path:') |
| 413 | and "_changelog_towncrier_draft.rst" in record.msg |
| 414 | ): |
| 415 | return False |
| 416 | return True |
| 417 | |
| 418 | logger = logging.getLogger(sphinx.util.logging.NAMESPACE) |
| 419 | warn_handler = [x for x in logger.handlers if x.level == logging.WARNING] |
| 420 | assert len(warn_handler) == 1, warn_handler |
| 421 | warn_handler[0].filters.insert(0, WarnLogFilter()) |
| 422 | |
| 423 | |
| 424 | def setup(app: "sphinx.application.Sphinx") -> None: |
no test coverage detected