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

Skip to content

Commit 261b6f8

Browse files
committed
Merged revisions 6950 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r6950 | mdboom | 2009-03-03 17:06:53 -0500 (Tue, 03 Mar 2009) | 2 lines Add workaround for change in handling of absolute paths in image directive in recent Sphinx hg versions. ........ svn path=/trunk/matplotlib/; revision=6951
1 parent dcab7f5 commit 261b6f8

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
from docutils.parsers.rst.directives.images import Image
3131
align = Image.align
3232
from docutils import nodes
33+
import sphinx
34+
35+
sphinx_version = sphinx.__version__.split(".")
36+
sphinx_version = tuple([int(x) for x in sphinx_version[:2]])
3337

3438
import matplotlib
3539
import matplotlib.cbook as cbook
@@ -92,11 +96,11 @@ def write_char(s):
9296
9397
[%(links)s]
9498
95-
.. image:: %(tmpdir)s/%(outname)s.png
99+
.. image:: %(prefix)s%(tmpdir)s/%(outname)s.png
96100
%(options)s
97101
98102
.. latexonly::
99-
.. image:: %(tmpdir)s/%(outname)s.pdf
103+
.. image:: %(prefix)s%(tmpdir)s/%(outname)s.pdf
100104
%(options)s
101105
"""
102106

@@ -262,7 +266,17 @@ def plot_directive(name, arguments, options, content, lineno,
262266

263267
# tmpdir is where we build all the output files. This way the
264268
# plots won't have to be redone when generating latex after html.
265-
tmpdir = os.path.abspath(os.path.join('build', outdir))
269+
270+
# Prior to Sphinx 0.6, absolute image paths were treated as
271+
# relative to the root of the filesystem. 0.6 and after, they are
272+
# treated as relative to the root of the documentation tree. We need
273+
# to support both methods here.
274+
tmpdir = os.path.join('build', outdir)
275+
if sphinx_version < (0, 6):
276+
tmpdir = os.path.abspath(tmpdir)
277+
prefix = ''
278+
else:
279+
prefix = '/'
266280
if not os.path.exists(tmpdir):
267281
cbook.mkdirs(tmpdir)
268282

0 commit comments

Comments
 (0)