Last active
February 19, 2021 05:25
-
-
Save johnmarcampbell/ff15e5bc2fbef3abc034fdce2c4b0bfb to your computer and use it in GitHub Desktop.
A pre-commit hook for clearing output from jupyter notebooks
This file contains 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 | |
# Find staged files | filter for notebooks | substitute spaces for newlines | |
notebooks=$( git diff --staged --name-only | grep .ipynb | tr '\n' ' ') | |
# If there are staged notebooks, clear them and re-add them | |
if [ -n "$notebooks" ]; then | |
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace $notebooks | |
git add $notebooks | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment