Created
December 2, 2021 11:41
-
-
Save leonoverweel/7125325e2aa90aed588ca1ce605fcbd3 to your computer and use it in GitHub Desktop.
Simple Python script to fail CI/CD checks if Jupyter notebooks aren't cleared
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
import glob | |
import subprocess | |
import sys | |
CLEAR_COMMAND = "jupyter nbconvert --to notebook --inplace --clear-output" | |
DIFF_COMMAND = "git diff --quiet --exit-code" | |
# Clear notebook outputs | |
for notebook_file in glob.glob("notebooks/*.ipynb"): | |
subprocess.run([*CLEAR_COMMAND.split(), notebook_file]) | |
# Check if clearing notebooks changed anything | |
exit_code = subprocess.run([*DIFF_COMMAND.split()]).returncode | |
# Fail if it did | |
sys.exit(exit_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment