Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
metadata_path = os.path.dirname(rstfilename)
unique_key = nbfilename.rstrip('.ipynb')
resources = {
'metadata': {'path': metadata_path},
'output_files_dir': output_files_dir,
# Prefix for the output image filenames
'unique_key': unique_key
}
# Read notebook
with open(nbfilepath, 'r') as f:
nb = nbformat.read(f, as_version=4)
# Export
exporter = nbsphinx.Exporter(execute='never', allow_errors=True)
(body, resources) = exporter.from_notebook_node(nb, resources)
# Correct path for the resources
for filename in list(resources['outputs'].keys()):
tmp = os.path.join(RST_PATH, filename)
resources['outputs'][tmp] = resources['outputs'].pop(filename)
fw = FilesWriter()
fw.build_directory = RST_PATH
# Prevent "not in doctree" complains
resources['output_extension'] = ''
body = 'Examples\n--------\n' + body
fw.write(body, resources, notebook_name=rstfilename)
The extension of the file is '.txt' since it will
note be part of the `toctree`.
"""
path = os.path.dirname(rst_filename)
basename = os.path.splitext(os.path.basename(rst_filename))[0]
resources_d = {
'metadata': {'path': path},
'output_files_dir': basename
}
# Read notebook
with open(notebook_filename, 'r') as f:
nb = nbformat.read(f, as_version=4)
# Export
rst_exporter = nbsphinx.Exporter(execute='never', allow_errors=True)
(body, resources) = rst_exporter.from_notebook_node(
nb, resources_d)
# Correct path for the resources
for filename in list(resources['outputs'].keys()):
tmp = '{}/{}'.format(path, filename)
resources['outputs'][tmp] = resources['outputs'].pop(filename)
fw = FilesWriter()
fw.build_directory = path
# Prevent "not in doctree" complains
resources['output_extension'] = '.txt'
body = 'Examples\n--------\n' + body
return fw.write(body, resources, notebook_name=basename)