Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __enter__(self):
self.old_wd = _os.getcwd()
_os.chdir(self.name)
return super(TemporaryWorkingDirectory, self).__enter__()
def from_notebook_node(self, nb, resources=None, **kw):
latex, resources = super(PDFExporter, self).from_notebook_node(
nb, resources=resources, **kw
)
# set texinputs directory, so that local files will be found
if resources and resources.get('metadata', {}).get('path'):
self.texinputs = resources['metadata']['path']
else:
self.texinputs = getcwd()
self._captured_outputs = []
with TemporaryWorkingDirectory():
notebook_name = 'notebook'
tex_file = self.writer.write(latex, resources, notebook_name=notebook_name)
self.log.info("Building PDF")
rc = self.run_latex(tex_file)
if rc:
rc = self.run_bib(tex_file)
if rc:
rc = self.run_latex(tex_file)
pdf_file = notebook_name + '.pdf'
if not os.path.isfile(pdf_file):
raise LatexFailed('\n'.join(self._captured_output))
self.log.info('PDF successfully created')
with open(pdf_file, 'rb') as f:
pdf_data = f.read()