Skip to content

Commit

Permalink
Merge pull request #768 from saulshanabrook/pdf-cleanup-tex
Browse files Browse the repository at this point in the history
Cleanup notebook.tex during PDF generation
  • Loading branch information
takluyver authored Mar 1, 2018
2 parents 53f3c86 + 2210f10 commit e59f4ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
16 changes: 1 addition & 15 deletions nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ 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=())
writer = Instance("nbconvert.writers.FilesWriter", args=(), kw={'build_directory': '.'})

_captured_output = List()

Expand Down Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions nbconvert/exporters/tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +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

# all temporary file should be cleaned up
assert {file_name} == set(os.listdir(td))

0 comments on commit e59f4ce

Please sign in to comment.