123456789101112131415161718192021 |
- def _post_save_script(model, os_path, contents_manager, **kwargs):
- """convert notebooks to Python script after save with nbconvert
- replaces `jupyter notebook --script`
- """
- from nbconvert.exporters.script import ScriptExporter
- warnings.warn("`_post_save_script` is deprecated and will be removed in Notebook 5.0", DeprecationWarning)
- if model['type'] != 'notebook':
- return
- global _script_exporter
- if _script_exporter is None:
- _script_exporter = ScriptExporter(parent=contents_manager)
- log = contents_manager.log
- base, ext = os.path.splitext(os_path)
- script, resources = _script_exporter.from_filename(os_path)
- script_fname = base + resources.get('output_extension', '.txt')
- log.info("Saving script /%s", to_api_path(script_fname, contents_manager.root_dir))
- with io.open(script_fname, 'w', encoding='utf-8') as f:
- f.write(script)
|