Created
March 12, 2021 17:24
-
-
Save bobpace/489bd285cf6e2a8b5709c15b807c9524 to your computer and use it in GitHub Desktop.
git pre-commit hook to clear jupyter notebooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
notebook_files=$(git diff --cached --name-only | grep -E '\.ipynb$') | |
if [ -n "$notebook_files" ] | |
then | |
source ./notebook/venv/bin/activate || exit | |
for file in $notebook_files | |
do | |
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace "$file" | |
git add "$file" | |
done | |
deactivate | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment