Skip to content

Make plot directive errors fail Sphinx builds#31863

Merged
story645 merged 1 commit into
matplotlib:mainfrom
chidoziemanagwu:fix-sphinx-plot-error-reporting
Jun 10, 2026
Merged

Make plot directive errors fail Sphinx builds#31863
story645 merged 1 commit into
matplotlib:mainfrom
chidoziemanagwu:fix-sphinx-plot-error-reporting

Conversation

@chidoziemanagwu

Copy link
Copy Markdown
Contributor

PR summary

Plot execution exceptions are currently converted into Docutils system messages,
so Sphinx does not treat them as warnings and sphinx-build -W can still exit
successfully.

Log PlotError exceptions through Sphinx while preserving the existing Docutils
system message. This makes warning-as-error builds fail when a plot directive
raises an exception.

Add a regression test that builds a page containing a failing plot directive and
checks that the Sphinx build exits unsuccessfully with the exception details.

closes #30899

AI Disclosure

OpenAI Codex was used to analyze the issue, implement the change, and draft the
regression test and pull request description. The resulting changes were reviewed
and validated with the available local checks.

PR checklist

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@timhoffm

timhoffm commented Jun 9, 2026

Copy link
Copy Markdown
Member

CI errors are unrelated and fixed through #31865.

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. If possible, please rebase to pick up #31865 and fix the CI failure.

Comment thread lib/matplotlib/tests/test_sphinxext.py Outdated

def build_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):
# Build the pages with warnings turned into errors
def run_sphinx_html(source_dir, doctree_dir, html_dir, extra_args=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not create a new function for this. Instead, expand build_sphinx_html to cover both cases.

  • Add an expected_returncode=0 parameter
  • Return the proc

@chidoziemanagwu chidoziemanagwu force-pushed the fix-sphinx-plot-error-reporting branch from 703fdb2 to 1856c9e Compare June 9, 2026 22:46
@chidoziemanagwu chidoziemanagwu requested a review from timhoffm June 9, 2026 23:16
@chidoziemanagwu

Copy link
Copy Markdown
Contributor Author

hello @timhoffm, I just made an update and rebased. will be waiting on your feedback thanks :)

@timhoffm timhoffm added this to the v3.12.0 milestone Jun 10, 2026
@story645 story645 merged commit fdcbc57 into matplotlib:main Jun 10, 2026
41 checks passed
@story645

Copy link
Copy Markdown
Member

Thanks for the fix @chidoziemanagwu!

@timhoffm this feels more like a bugfix to me, would it be okay to backport to 3.11.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[Bug]: plot_directive does not raise warning or error when the code it runs fails

3 participants