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

Skip to content

Commit 41f46a9

Browse files
committed
Fix plot_basedir bug in sphinxext
1 parent 39bfc6f commit 41f46a9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,22 @@ def run(arguments, content, options, state_machine, state, lineno):
657657
build_dir = os.path.join(os.path.dirname(setup.app.doctreedir),
658658
'plot_directive',
659659
source_rel_dir)
660+
# get rid of .. in paths, also changes pathsep
661+
# see note in Python docs for warning about symbolic links on Windows.
662+
# need this if you use cbook.mkdirs
663+
# also need it to compare source and dest paths at end
664+
build_dir = os.path.normpath(build_dir)
665+
660666
if not os.path.exists(build_dir):
661-
cbook.mkdirs(build_dir)
667+
# cbook.mkdirs(build_dir)
668+
os.makedirs(build_dir)
662669

663670
# output_dir: final location in the builder's directory
664671
dest_dir = os.path.abspath(os.path.join(setup.app.builder.outdir,
665672
source_rel_dir))
666673
if not os.path.exists(dest_dir):
667-
cbook.mkdirs(dest_dir)
674+
# cbook.mkdirs(dest_dir)
675+
os.makedirs(dest_dir) # no problem here for me, but just use built-ins
668676

669677
# how to link to files from the RST file
670678
dest_dir_link = os.path.join(relpath(setup.confdir, rst_dir),
@@ -738,15 +746,16 @@ def run(arguments, content, options, state_machine, state, lineno):
738746
if total_lines:
739747
state_machine.insert_input(total_lines, source=source_file_name)
740748

741-
# copy image files to builder's output directory
749+
# copy image files to builder's output directory, if necessary
742750
if not os.path.exists(dest_dir):
743751
cbook.mkdirs(dest_dir)
744-
752+
745753
for code_piece, images in results:
746754
for img in images:
747755
for fn in img.filenames():
748-
shutil.copyfile(fn, os.path.join(dest_dir,
749-
os.path.basename(fn)))
756+
destimg = os.path.join(dest_dir, os.path.basename(fn))
757+
if fn != destimg:
758+
shutil.copyfile(fn, destimg)
750759

751760
# copy script (if necessary)
752761
if source_file_name == rst_file:

0 commit comments

Comments
 (0)