Write pre-commit that *checks* if jupyter notebooks have output cleared

Viewed 969

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!

1 Answers

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.

Related