From 3f932374accf9099726f7943c775e32e0c942bb1 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 26 Feb 2018 14:09:38 -0500 Subject: [PATCH 1/4] Test for cleaning up `notebook.tex` in pdf --- nbconvert/exporters/tests/test_pdf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nbconvert/exporters/tests/test_pdf.py b/nbconvert/exporters/tests/test_pdf.py index e09ef21b8..ca864eaf2 100644 --- a/nbconvert/exporters/tests/test_pdf.py +++ b/nbconvert/exporters/tests/test_pdf.py @@ -37,4 +37,6 @@ def test_export(self): (output, resources) = self.exporter_class(latex_count=1).from_filename(newpath) self.assertIsInstance(output, bytes) assert len(output) > 0 + # tex file should be cleaned up + assert 'notebook.tex' not in os.listdir(td) From 9ffb7533506886818198bc660334d492869e8c9b Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 26 Feb 2018 14:18:46 -0500 Subject: [PATCH 2/4] Write tex file in pdf generation to temp folder --- nbconvert/exporters/pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index 7ee7a50e5..7620866d7 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -66,7 +66,7 @@ class PDFExporter(LatexExporter): ).tag(config=True) texinputs = Unicode(help="texinputs dir. A notebook's directory is added") - writer = Instance("nbconvert.writers.FilesWriter", args=()) + writer = Instance("nbconvert.writers.FilesWriter", args=(), kw={'build_directory': '.'}) _captured_output = List() From 6bdba4f98b347924a01d0e1072b98378e3534540 Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Mon, 26 Feb 2018 14:19:37 -0500 Subject: [PATCH 3/4] Remove dead code for manual pdf cleanup --- nbconvert/exporters/pdf.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index 7620866d7..d9998a9e8 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -61,10 +61,6 @@ class PDFExporter(LatexExporter): help="Whether to display the output of latex commands." ).tag(config=True) - temp_file_exts = List(['.aux', '.bbl', '.blg', '.idx', '.log', '.out'], - help="File extensions of temp files to remove after running." - ).tag(config=True) - texinputs = Unicode(help="texinputs dir. A notebook's directory is added") writer = Instance("nbconvert.writers.FilesWriter", args=(), kw={'build_directory': '.'}) @@ -155,16 +151,6 @@ def log_error(command, out): self.log.debug(u"%s output: %s\n%s", command[0], command, out) return self.run_command(self.bib_command, filename, 1, log_error) - - def clean_temp_files(self, filename): - """Remove temporary files created by xelatex/bibtex.""" - self.log.info("Removing temporary LaTeX files") - filename = os.path.splitext(filename)[0] - for ext in self.temp_file_exts: - try: - os.remove(filename+ext) - except OSError: - pass def from_notebook_node(self, nb, resources=None, **kw): latex, resources = super(PDFExporter, self).from_notebook_node( From 2210f10d96295906c330718c60b8189d8cded77a Mon Sep 17 00:00:00 2001 From: Saul Shanabrook Date: Tue, 27 Feb 2018 10:06:31 -0500 Subject: [PATCH 4/4] Verify all tmp files removed after pdf gen --- nbconvert/exporters/tests/test_pdf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nbconvert/exporters/tests/test_pdf.py b/nbconvert/exporters/tests/test_pdf.py index ca864eaf2..f9b0183d9 100644 --- a/nbconvert/exporters/tests/test_pdf.py +++ b/nbconvert/exporters/tests/test_pdf.py @@ -32,11 +32,11 @@ def test_constructor(self): def test_export(self): """Smoke test PDFExporter""" with tempdir.TemporaryDirectory() as td: - newpath = os.path.join(td, os.path.basename(self._get_notebook())) + file_name = os.path.basename(self._get_notebook()) + newpath = os.path.join(td, file_name) shutil.copy(self._get_notebook(), newpath) (output, resources) = self.exporter_class(latex_count=1).from_filename(newpath) self.assertIsInstance(output, bytes) assert len(output) > 0 - # tex file should be cleaned up - assert 'notebook.tex' not in os.listdir(td) - + # all temporary file should be cleaned up + assert {file_name} == set(os.listdir(td))