Created
August 2, 2023 21:45
-
-
Save scivision/e7326fdcfadb0c61b3f0adfff84f0f13 to your computer and use it in GitHub Desktop.
Strip Jupyter notebook outputs as Git pre-commit hook
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
#!/usr/bin/env python3 | |
""" | |
Strip Jupyter notebook outputs as Git pre-commit hook | |
""" | |
import subprocess | |
from pathlib import Path | |
files_changed = subprocess.check_output(["git", "diff", "--staged", "--name-only"], text=True).split("\n") | |
for file in files_changed: | |
p = Path(file) | |
if not p.is_file(): | |
continue | |
if p.suffix == ".ipynb": | |
subprocess.check_call(["jupyter", "nbconvert", "--clear-output", "--inplace", file]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment