Skip to content

Instantly share code, notes, and snippets.

@leonoverweel
Created December 2, 2021 11:41
Show Gist options
  • Save leonoverweel/7125325e2aa90aed588ca1ce605fcbd3 to your computer and use it in GitHub Desktop.
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
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