Skip to content

Add pre-commit hook for Jupyter notebooks to reduce noisy diffs #3578

@omkar-334

Description

@omkar-334

While refactoring super() calls in notebooks, the notebook metadata kept changing, which led to a very big diff.
To reduce this in the future, we can add pre-commit hooks for this.

Possible hooks -
https://github.com/kynan/nbstripout - strips output

  # notebook JSON hygiene
  - repo: https://github.com/kynan/nbstripout
    rev: 0.7.1
    hooks:
      - id: nbstripout

https://github.com/nbQA-dev/nbQA - lints and fixes notebook cell code

  # notebook code quality
  - repo: https://github.com/nbQA-dev/nbQA
    rev: 1.8.7
    hooks:
      - id: nbqa-ruff
        args: ["--fix"]

https://github.com/srstevenson/nb-clean - removes metadata, outputs and execution counts

repos:
  - repo: https://github.com/srstevenson/nb-clean
    rev: 4.0.1
    hooks:
      - id: nb-clean

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions