sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.45k stars 2.1k forks source link

Option to throw error if module cannot be imported by autodoc #11764

Open peanutfun opened 10 months ago

peanutfun commented 10 months ago

Is your feature request related to a problem? Please describe. Autodoc throws warnings when it cannot import modules it is supposed to document. If the overall Sphinx build succeeds, these modules are then simply missing from the generated documentation. The option sphinx-build -W, however, turns all warnings into errors. For a large Sphinx build with a lot of modules, it is unfeasible to have a build without warnings. Without the -W option, I have to manually inspect each build to see if the modules could be imported and were documented as expected. I would like the option to turn autodoc warnings into errors, and more specifically only warnings about importing modules.

Describe the solution you'd like A configuration option autodoc_module_import_error. If set to True, module import errors like WARNING: autodoc: failed to import module 'XYZ' become errors that stop the Sphinx build.

Describe alternatives you've considered

picnixz commented 9 months ago

I would say 'why not' so feel free to open a PR. More generally, it would be good if we could turn specific warnings into errors, but this would require to correctly add types/subtypes to the warnings (which is currently something we lack).