Skip to content

Instantly share code, notes, and snippets.

@v-i-s-h
Created October 23, 2020 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v-i-s-h/fe77eeadade02e915ac58c93bd69dada to your computer and use it in GitHub Desktop.
Save v-i-s-h/fe77eeadade02e915ac58c93bd69dada to your computer and use it in GitHub Desktop.
Jupyter notebook git tools
# prepare notebook folder for commit
# Does
# 1. Render all notebooks to HTML
# 2. Clear all cell outputs
# Make destination directory to store rendered html, if not exists
RENDER_DIR=rendered
mkdir -p rendered
# Get all files with Added, Modified, or untracked status from git
FILES_TO_RENDER=$(git status . --porcelain | sed -nr 's/^([AM]|\?\?) *.+\/(.*ipynb)/\2/p')
# Render to html
jupyter nbconvert $FILES_TO_RENDER --output-dir=$RENDER_DIR
# Clear outputs of all notebooks
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace $FILES_TO_RENDER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment