Skip to content

Commit e2c8691

Browse files
committed
Use sys.executable -msphinx instead of sphinx-build.
1 parent 3b425d8 commit e2c8691

File tree

4 files changed

+49
-35
lines changed

4 files changed

+49
-35
lines changed

doc-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Install the documentation requirements with:
77
# pip install -r doc-requirements.txt
88
#
9-
sphinx>1.0,!=1.5.0
9+
sphinx>1.3,!=1.5.0
1010
numpydoc
1111
ipython
1212
mock

doc/devel/documenting_mpl.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Getting started
88
===============
99

1010
The documentation for matplotlib is generated from ReStructured Text using the
11-
Sphinx_ documentation generation tool. Sphinx-1.0 or later and numpydoc 0.4 or
11+
Sphinx_ documentation generation tool. Sphinx-1.3 or later and numpydoc 0.4 or
1212
later is required.
1313

1414
The documentation sources are found in the :file:`doc/` directory in

doc/make.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ def check_build():
4040

4141
def doctest():
4242
"""Execute Sphinx 'doctest' target. """
43-
os.system('sphinx-build -b doctest -d build/doctrees . build/doctest')
43+
subprocess.call(
44+
[sys.executable]
45+
+ '-msphinx -b doctest -d build/doctrees . build/doctest'.split())
4446

4547

4648
def linkcheck():
4749
"""Execute Sphinx 'linkcheck' target. """
48-
os.system('sphinx-build -b linkcheck -d build/doctrees . build/linkcheck')
50+
subprocess.call(
51+
[sys.executable]
52+
+ '-msphinx -b linkcheck -d build/doctrees . build/linkcheck'.split())
4953

5054

5155
# For generating PNGs of the top row of index.html:
@@ -81,7 +85,8 @@ def generate_frontpage_pngs(only_if_needed=True):
8185
continue # do nothing if png is newer
8286

8387
# Execute python as subprocess (preferred over os.system()):
84-
subprocess.check_call(["python", pn_py]) # raises CalledProcessError()
88+
subprocess.check_call(
89+
[sys.executable, pn_py]) # raises CalledProcessError()
8590
os.rename(fn_png, pn_png) # move file to _static/ directory
8691

8792

@@ -96,14 +101,16 @@ def html(buildername='html'):
96101
rc = default_rc
97102
copy_if_out_of_date(rc, '_static/matplotlibrc')
98103

104+
options = ['-j{}'.format(n_proc),
105+
'-b{}'.format(buildername),
106+
'-dbuild/doctrees']
99107
if small_docs:
100-
options = "-D plot_formats=png:100"
101-
else:
102-
options = ''
108+
options += ['-Dplot_formats=png:100']
103109
if warnings_as_errors:
104-
options = options + ' -W'
105-
if os.system('sphinx-build -j %d %s -b %s -d build/doctrees . build/%s' % (
106-
n_proc, options, buildername, buildername)):
110+
options += ['-W']
111+
if subprocess.call(
112+
[sys.executable, '-msphinx', '.', 'build/{}'.format(buildername)]
113+
+ options):
107114
raise SystemExit("Building HTML failed.")
108115

109116
# Clean out PDF files from the _images directory
@@ -132,7 +139,9 @@ def latex():
132139
# figs()
133140
if sys.platform != 'win32':
134141
# LaTeX format.
135-
if os.system('sphinx-build -b latex -d build/doctrees . build/latex'):
142+
if subprocess.call(
143+
[sys.executable]
144+
+ '-msphinx -b latex -d build/doctrees . build/latex'.split()):
136145
raise SystemExit("Building LaTeX failed.")
137146

138147
# Produce pdf.
@@ -153,8 +162,9 @@ def texinfo():
153162
# figs()
154163
if sys.platform != 'win32':
155164
# Texinfo format.
156-
if os.system(
157-
'sphinx-build -b texinfo -d build/doctrees . build/texinfo'):
165+
if subprocess.call(
166+
[sys.executable]
167+
+ '-msphinx -b texinfo -d build/doctrees . build/texinfo'.split()):
158168
raise SystemExit("Building Texinfo failed.")
159169

160170
# Produce info file.
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
""" Tests for tinypages build using sphinx extensions """
22

3+
import filecmp
4+
from os.path import join as pjoin, dirname, isdir
35
import shutil
4-
import tempfile
5-
6-
from os.path import (join as pjoin, dirname, isdir)
7-
86
from subprocess import call, Popen, PIPE
7+
import sys
8+
import tempfile
99

1010
import pytest
1111

12+
from matplotlib import cbook
13+
1214

1315
HERE = dirname(__file__)
1416
TINY_PAGES = pjoin(HERE, 'tinypages')
1517

1618

1719
def setup_module():
18-
"""Check we have the sphinx-build command"""
19-
try:
20-
ret = call(['sphinx-build', '--help'], stdout=PIPE, stderr=PIPE)
21-
except OSError:
22-
pytest.skip('Need sphinx-build on path for these tests')
20+
"""Check we have a recent enough version of sphinx installed.
21+
"""
22+
ret = call([sys.executable, '-msphinx', '--help'],
23+
stdout=PIPE, stderr=PIPE)
2324
if ret != 0:
24-
raise RuntimeError('sphinx-build does not return 0')
25+
raise RuntimeError(
26+
"'{} -msphinx' does not return 0".format(sys.executable))
2527

2628

29+
@cbook.deprecated("2.1", alternative="filecmp.cmp")
2730
def file_same(file1, file2):
2831
with open(file1, 'rb') as fobj:
2932
contents1 = fobj.read()
@@ -42,15 +45,16 @@ def setup_class(cls):
4245
cls.html_dir = pjoin(cls.page_build, 'html')
4346
cls.doctree_dir = pjoin(cls.page_build, 'doctrees')
4447
# Build the pages with warnings turned into errors
45-
cmd = [str('sphinx-build'), '-W', '-b', 'html',
48+
cmd = [sys.executable, '-msphinx', '-W', '-b', 'html',
4649
'-d', cls.doctree_dir,
4750
TINY_PAGES,
4851
cls.html_dir]
4952
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
5053
out, err = proc.communicate()
5154
if proc.returncode != 0:
52-
raise RuntimeError('sphinx-build failed with stdout:\n'
53-
'{0}\nstderr:\n{1}\n'.format(out, err))
55+
raise RuntimeError(
56+
"'{} -msphinx' failed with stdout:\n{}\nstderr:\n{}\n"
57+
.format(sys.executable, out, err))
5458
except Exception as e:
5559
shutil.rmtree(cls.page_build)
5660
raise e
@@ -67,22 +71,22 @@ def plot_file(num):
6771

6872
range_10, range_6, range_4 = [plot_file(i) for i in range(1, 4)]
6973
# Plot 5 is range(6) plot
70-
assert file_same(range_6, plot_file(5))
74+
assert filecmp.cmp(range_6, plot_file(5))
7175
# Plot 7 is range(4) plot
72-
assert file_same(range_4, plot_file(7))
76+
assert filecmp.cmp(range_4, plot_file(7))
7377
# Plot 11 is range(10) plot
74-
assert file_same(range_10, plot_file(11))
78+
assert filecmp.cmp(range_10, plot_file(11))
7579
# Plot 12 uses the old range(10) figure and the new range(6) figure
76-
assert file_same(range_10, plot_file('12_00'))
77-
assert file_same(range_6, plot_file('12_01'))
80+
assert filecmp.cmp(range_10, plot_file('12_00'))
81+
assert filecmp.cmp(range_6, plot_file('12_01'))
7882
# Plot 13 shows close-figs in action
79-
assert file_same(range_4, plot_file(13))
83+
assert filecmp.cmp(range_4, plot_file(13))
8084
# Plot 14 has included source
8185
with open(pjoin(self.html_dir, 'some_plots.html'), 'rb') as fobj:
8286
html_contents = fobj.read()
8387
assert b'# Only a comment' in html_contents
8488
# check plot defined in external file.
85-
assert file_same(range_4, pjoin(self.html_dir, 'range4.png'))
86-
assert file_same(range_6, pjoin(self.html_dir, 'range6.png'))
89+
assert filecmp.cmp(range_4, pjoin(self.html_dir, 'range4.png'))
90+
assert filecmp.cmp(range_6, pjoin(self.html_dir, 'range6.png'))
8791
# check if figure caption made it into html file
8892
assert b'This is the caption for plot 15.' in html_contents

0 commit comments

Comments
 (0)