6

I know you can use jupyter nbconvert --clear-output --inplace <file> (per here) to clear the output of a jupyter notebook. I'm wondering if there's an easy way to check if output has been cleared in a pre-commit hook. That way I can fail the pre-commit if it hasn't and force the user to try again. Thanks!

dfried
  • 313
  • 2
  • 8
  • 1
    Clear and compare with the original? – phd Nov 11 '20 at 05:16
  • I guess this works. I was hoping (maybe naively) that there was an option like `--check` that just tells you if it's already cleared or not. Thanks! – dfried Nov 11 '20 at 17:32

1 Answers1

2

You can use nbstripout as a pre-commit hook.

repos:
- repo: https://github.com/kynan/nbstripout
  rev: 0.5.0
  hooks:
    - id: nbstripout

You could possibly modify it with --dry-run to not modify any files. I have not tried that, though.

KPLauritzen
  • 1,719
  • 13
  • 23
  • Looks like using `--dry-run` would not work in a pre-commit hook b/c it always returns `0` (success), even if files were to change (issue in GH [here](https://github.com/kynan/nbstripout/issues/159)) – Joao Coelho Oct 29 '21 at 23:58