Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13239b5

Browse filesBrowse files
committed
Suppress the "non-GUI backend" warning from the .. plot:: directive...
... when the example file contains a call to `show()` (the examples are always run with the agg backend). To do so, patch FigureManagerBase.show to be a no-op when running the example. Also modified a test to check for this behavior.
1 parent 7b5ff33 commit 13239b5
Copy full SHA for 13239b5

File tree

Expand file treeCollapse file tree

2 files changed

+13
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-6
lines changed

‎lib/matplotlib/sphinxext/plot_directive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/plot_directive.py
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
import jinja2 # Sphinx dependency.
157157

158158
import matplotlib
159+
from matplotlib.backend_bases import FigureManagerBase
159160
try:
160161
with warnings.catch_warnings(record=True):
161162
warnings.simplefilter("error", UserWarning)
@@ -491,9 +492,13 @@ def run_code(code, code_path, ns=None, function_name=None):
491492
exec(str(setup.config.plot_pre_code), ns)
492493
if "__main__" in code:
493494
ns['__name__'] = '__main__'
494-
exec(code, ns)
495-
if function_name is not None:
496-
exec(function_name + "()", ns)
495+
496+
# Patch out non-interactive show() to avoid triggering a warning.
497+
with cbook._setattr_cm(FigureManagerBase, show=lambda self: None):
498+
exec(code, ns)
499+
if function_name is not None:
500+
exec(function_name + "()", ns)
501+
497502
except (Exception, SystemExit) as err:
498503
raise PlotError(traceback.format_exc())
499504
finally:

‎lib/matplotlib/sphinxext/tests/test_tinypages.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/tests/test_tinypages.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ def test_tinypages(tmpdir):
1919
# Build the pages with warnings turned into errors
2020
cmd = [sys.executable, '-msphinx', '-W', '-b', 'html', '-d', doctree_dir,
2121
pjoin(dirname(__file__), 'tinypages'), html_dir]
22-
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
22+
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
2323
out, err = proc.communicate()
2424
assert proc.returncode == 0, \
25-
"'{} -msphinx' failed with stdout:\n{}\nstderr:\n{}\n".format(
26-
sys.executable, out, err)
25+
"sphinx build failed with stdout:\n{}\nstderr:\n{}\n".format(out, err)
26+
if err:
27+
pytest.fail("sphinx build emitted the following warnings:\n{}"
28+
.format(err))
2729

2830
assert isdir(html_dir)
2931

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.