Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save samuelsmal/185d0c6b027c3d24b47a892f062cb9bc to your computer and use it in GitHub Desktop.
Save samuelsmal/185d0c6b027c3d24b47a892f062cb9bc to your computer and use it in GitHub Desktop.
jupyter notebook saving hook
import os
from subprocess import check_call
c = get_config()
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py scripts"""
if model['type'] != 'notebook':
return # only do this for notebooks
d, fname = os.path.split(os_path)
check_call(['jupyter', 'nbconvert', '--to', 'script', fname], cwd=d)
check_call(['jupyter', 'nbconvert', '--to', 'html', fname], cwd=d)
c.FileContentsManager.post_save_hook = post_save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment