Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19351e6

Browse files
tacaswellMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #11934: Suppress the "non-GUI backend" warning from the .. plot:: directive...
1 parent 7819eb4 commit 19351e6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines 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)
@@ -492,9 +493,13 @@ def run_code(code, code_path, ns=None, function_name=None):
492493
exec(str(setup.config.plot_pre_code), ns)
493494
if "__main__" in code:
494495
ns['__name__'] = '__main__'
495-
exec(code, ns)
496-
if function_name is not None:
497-
exec(function_name + "()", ns)
496+
497+
# Patch out non-interactive show() to avoid triggering a warning.
498+
with cbook._setattr_cm(FigureManagerBase, show=lambda self: None):
499+
exec(code, ns)
500+
if function_name is not None:
501+
exec(function_name + "()", ns)
502+
498503
except (Exception, SystemExit) as err:
499504
raise PlotError(traceback.format_exc())
500505
finally:

lib/matplotlib/sphinxext/tests/test_tinypages.py

Lines 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)