Skip to content

Commit 56704c6

Browse files
committed
FIX: fix PUrePath
1 parent 70caa44 commit 56704c6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/matplotlib/sphinxext/figmpl_directive.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import os
2121
from os.path import relpath
22-
from pathlib import PurePosixPath, Path
22+
from pathlib import PurePath, Path
2323
import shutil
2424

2525
from sphinx.errors import ExtensionError
@@ -140,17 +140,17 @@ def _copy_images_figmpl(self, node):
140140
srcset = None
141141

142142
# the rst file's location: eg /Users/username/matplotlib/doc/users/explain/artists
143-
docsource = PurePosixPath(self.document['source']).parent
143+
docsource = PurePath(self.document['source']).parent
144144

145145
# get the relpath relative to root:
146146
srctop = self.builder.srcdir
147-
rel = relpath(docsource, srctop).replace('.', '').replace('/', '-')
147+
rel = relpath(docsource, srctop).replace('.', '').replace(os.sep, '-')
148148
if len(rel):
149149
rel += '-'
150150
# eg: users/explain/artists
151151

152-
imagedir = PurePosixPath(self.builder.imagedir)
153-
imagedir = PurePosixPath(self.builder.outdir) / imagedir
152+
imagedir = PurePath(self.builder.imagedir)
153+
imagedir = PurePath(self.builder.outdir) / imagedir
154154
# eg: /Users/username/matplotlib/doc/build/html/_images/users/explain/artists
155155

156156
Path(imagedir).mkdir(parents=True, exist_ok=True)
@@ -159,11 +159,11 @@ def _copy_images_figmpl(self, node):
159159
if srcset:
160160
for mult in srcset:
161161
# the entries in srcset are relative to docsource's directory
162-
abspath = PurePosixPath(docsource, srcset[mult])
162+
abspath = PurePath(docsource, srcset[mult])
163163
name = rel + abspath.name
164164
shutil.copyfile(abspath, imagedir / name)
165165
else:
166-
abspath = PurePosixPath(docsource, node['uri'])
166+
abspath = PurePath(docsource, node['uri'])
167167
name = rel + abspath.name
168168
shutil.copyfile(abspath, imagedir / name)
169169

@@ -175,14 +175,14 @@ def visit_figmpl_html(self, node):
175175
imagedir, srcset, rel = _copy_images_figmpl(self, node)
176176

177177
# /doc/examples/subd/plot_1.rst
178-
docsource = PurePosixPath(self.document['source'])
178+
docsource = PurePath(self.document['source'])
179179
# /doc/
180180
# make sure to add the trailing slash:
181-
srctop = PurePosixPath(self.builder.srcdir, '')
181+
srctop = PurePath(self.builder.srcdir, '')
182182
# examples/subd/plot_1.rst
183183
relsource = relpath(docsource, srctop)
184184
# /doc/build/html
185-
desttop = PurePosixPath(self.builder.outdir, '')
185+
desttop = PurePath(self.builder.outdir, '')
186186
# /doc/build/html/examples/subd
187187
dest = desttop / relsource
188188

@@ -192,7 +192,7 @@ def visit_figmpl_html(self, node):
192192
imagerel = f'..{imagerel}'
193193

194194
# make uri also be relative...
195-
nm = PurePosixPath(node['uri'][1:]).name
195+
nm = PurePath(node['uri'][1:]).name
196196
uri = f'{imagerel}/{rel}{nm}'
197197

198198
# make srcset str. Need to change all the prefixes!
@@ -201,7 +201,7 @@ def visit_figmpl_html(self, node):
201201
if srcset:
202202
maxmult = -1
203203
for mult in srcset:
204-
nm = PurePosixPath(srcset[mult][1:]).name
204+
nm = PurePath(srcset[mult][1:]).name
205205
# ../../_images/plot_1_2_0x.png
206206
path = f'{imagerel}/{rel}{nm}'
207207
srcsetst += path
@@ -262,7 +262,7 @@ def visit_figmpl_latex(self, node):
262262
maxmult = -1
263263
# choose the highest res version for latex:
264264
maxmult = max(srcset, default=-1)
265-
node['uri'] = PurePosixPath(srcset[maxmult]).name
265+
node['uri'] = PurePath(srcset[maxmult]).name
266266

267267
self.visit_figure(node)
268268

0 commit comments

Comments
 (0)