@@ -657,14 +657,19 @@ 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 to compare source and dest paths at end
663+ build_dir = os .path .normpath (build_dir )
664+
660665 if not os .path .exists (build_dir ):
661- cbook . mkdirs (build_dir )
666+ os . makedirs (build_dir )
662667
663668 # output_dir: final location in the builder's directory
664669 dest_dir = os .path .abspath (os .path .join (setup .app .builder .outdir ,
665670 source_rel_dir ))
666671 if not os .path .exists (dest_dir ):
667- cbook . mkdirs (dest_dir )
672+ os . makedirs (dest_dir ) # no problem here for me, but just use built-ins
668673
669674 # how to link to files from the RST file
670675 dest_dir_link = os .path .join (relpath (setup .confdir , rst_dir ),
@@ -738,15 +743,16 @@ def run(arguments, content, options, state_machine, state, lineno):
738743 if total_lines :
739744 state_machine .insert_input (total_lines , source = source_file_name )
740745
741- # copy image files to builder's output directory
746+ # copy image files to builder's output directory, if necessary
742747 if not os .path .exists (dest_dir ):
743748 cbook .mkdirs (dest_dir )
744-
749+
745750 for code_piece , images in results :
746751 for img in images :
747752 for fn in img .filenames ():
748- shutil .copyfile (fn , os .path .join (dest_dir ,
749- os .path .basename (fn )))
753+ destimg = os .path .join (dest_dir , os .path .basename (fn ))
754+ if fn != destimg :
755+ shutil .copyfile (fn , destimg )
750756
751757 # copy script (if necessary)
752758 if source_file_name == rst_file :
0 commit comments