Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup notebook.tex during PDF generation #768

Merged
merged 4 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice — that is cleaner.

newpath = os.path.join(td, file_name)
shutil.copy(self._get_notebook(), newpath)
(output, resources) = self.exporter_class(latex_count=1).from_filename(newpath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd feel better if this test would run LaTeX with a bibfile since that can also introduce artifacts and should be tested as part of the smoke test. If this turns out to be too big of a change, then we can move this into a new PR & make a new issue. But, could you give that a shot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to do that. Do you think it makes sense to copy these examples files into the repo for the test? https://github.com/jupyter/nbconvert-examples/tree/master/citations I can't seem to find an existing example notebook in this repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that those might be out of date — given that they were last updated over 3 years ago.

I'm now thinking that there may be no built-in way to do this… which is… odd.

We may need to look into the LaTeX templates to see if we need to include a new bibliography area and traitlet to get that to work. That's starting to sound like a separate PR though.

Could you try to figure out if any of the other code related to this is dead? If you just include assert False in places it should trigger failures in the tests if those parts of the code are actually being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code coverage, it seems like the only lines not executed in the PDF exporting are the win32 related, error related, or for generating the bib.

I am not sure exactly when the code became dead, if there are other files that are affected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code coverage actually doesn't get exactly what I was looking for. My ultimate aim was to know which tests were using the bibliography functionality to see how it was being used. I can just do this myself though…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright… so I'm fairly sure that right now that this code is only being run in the tests for the nbconvertapp, which are a gigantic pain to debug and investigate because they're hidden behind a subprocess.Popen call to nbconvert as part of the test… which means that pdb just causes everything to fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless my investigations left me believing that currently there is nothing that's properly testing the bibliography support… so we should look into that, but that's a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I don't know much about bib support and haven't used it.

self.assertIsInstance(output, bytes)
assert len(output) > 0

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