-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Temporary files in FilesWriter #6450
Description
I am not sure if this is a bug or not, but it was unexpected behavior for me, so I figured I'd report it.
When using FilesWriter with nbconvert, if you are converting multiple notebooks at once that rely on the same set of supplementary files, they do get copied to the build directory, but so do temporary files (one version per extra notebook). For example, if I have the following directory/file structure:
$ ls -R
.:
bar.ipynb files/ foo.ipynb ipython_nbconvert_config.py
./files:
file1.txt file2.txt
Where ipython_nbconvert_config.py is:
from glob import glob
c = get_config()
c.NbConvertApp.export_format = 'notebook'
c.NbConvertApp.notebooks = glob('*.ipynb')
c.NbConvertApp.writer_class = 'FilesWriter'
c.FilesWriter.build_directory = 'build'
c.FilesWriter.files = glob('files/*')Then, if I run nbconvert, the build/files directory contains:
$ ls build/files/
file1.txt file1.txt-temp-77A5 file2.txt file2.txt-temp-CE50
I traced the root of the problem to IPython.utils.path.link_or_copy, which says "Because os.link does not overwrite files, a unique temporary file will be used if the target already exists, then that file will be moved into place." That's fine, except it seems like the os.rename(new_dst, dst) line isn't actually removing new_dst (which is the temporary file).