click_extra.sphinx.fail_on_warnings module¶
Fail a Sphinx build on the warning types a project lists, and only on those.
Sphinx fails a build on warnings all or nothing: --fail-on-warning counts
every warning, and suppress_warnings can hide a type but never make one
fatal. A project that lives with some warnings, like the unresolved references
autodoc produces for third-party names, then cannot stop the build on the ones
it does not accept.
The main case is myst.xref_missing. myst-parser resolves every
`text <#anchor>`_ and `text <page.md#anchor>`_ link against what the build
produced. For a link it cannot place, it logs that warning and ships the link as
written anyway, so a dead fragment reaches the published site behind a green
build.
A handler on the sphinx logger records each warning whose type the project
lists in FAIL_ON_WARNINGS_CONFIG. Once the build is over, it reports
them in one error and sets the exit status to 1. The build itself runs to
its end, so every offending warning is reported, not only the first.
Todo
Contribute this upstream as a Sphinx config value, on sphinx-doc/sphinx#7949, which asks for the same feature and has waited for a design since 2020.
Sphinx already holds both halves. sphinx.util.logging.is_suppressed_warning
is the matching this module reuses, and the exit status --fail-on-warning
sets is the outcome. A config value read where
sphinx.util.logging.WarningSuppressor already counts each warning would
replace this module.
Should it land, keep this module as a shim for the Sphinx releases that predate it, then drop it once click-extra’s Sphinx floor moves past them.
- click_extra.sphinx.fail_on_warnings.FAIL_ON_WARNINGS_CONFIG = 'click_extra_fail_on_warnings'¶
Name of the
conf.pyvalue listing the warning types that fail the build.Entries use the syntax of
suppress_warnings:mystcovers every subtype,myst.xref_missingonly that one. Empty by default, which leaves Sphinx’s behavior untouched: which warnings a project can live with is its own call.
- class click_extra.sphinx.fail_on_warnings.ListedWarningCollector(app)[source]¶
Bases:
HandlerCollect the warnings whose type the project listed as fatal.
Attached to the
sphinxlogger rather than to Sphinx’s warning stream, so it sees every warning, whatever--quietdoes to the console. A warning thatsuppress_warningshides is skipped, the same way--fail-on-warningskips it.Initializes the instance - basically setting the formatter to None and the filter list to empty.
- click_extra.sphinx.fail_on_warnings.setup(app)[source]¶
Register the config value and attach a collector for
app.Called from
click_extra.sphinx.setup()so projects only need to list"click_extra.sphinx"in theirextensions. The collector reports at priority 900, after the default 500 of otherbuild-finishedhandlers, so a warning one of them logs still counts.- Return type: