Add nbstripout pre-commit hook to reduce noisy notebook diffs#3585
Add nbstripout pre-commit hook to reduce noisy notebook diffs#3585Prathamesh8989 wants to merge 5 commits intopytorch:masterfrom
Conversation
|
hi @Prathamesh8989 , thanks for this. a few suggestions -
|
|
Hi @omkar-334, Thanks for the suggestions! Here’s what I’ve done:
Please let me know which approach you prefer or if any further changes are needed. |
| @@ -1,4 +1,5 @@ | |||
| exclude: "^conda.recipe|assets|docs" | |||
|
|
|||
|
@vfdev-5 i think we can start with this. we can add |
.pre-commit-config.yaml
Outdated
|
|
||
| - repo: https://github.com/kynan/nbstripout | ||
| rev: 0.7.1 | ||
| hooks: | ||
| - id: nbstripout | ||
| types: [jupyter] |
There was a problem hiding this comment.
| - repo: https://github.com/kynan/nbstripout | |
| rev: 0.7.1 | |
| hooks: | |
| - id: nbstripout | |
| types: [jupyter] |
There was a problem hiding this comment.
Remove it from last hook
.pre-commit-config.yaml
Outdated
There was a problem hiding this comment.
| types_or: [python, pyi, jupyter] |
| hooks: | ||
| - id: prettier | ||
| exclude_types: ["python", "jupyter", "shell", "gitignore"] | ||
|
|
There was a problem hiding this comment.
| - repo: https://github.com/kynan/nbstripout | |
| rev: 0.7.1 | |
| hooks: | |
| - id: nbstripout | |
| types: [jupyter] | |
There was a problem hiding this comment.
Order matters, the notebooks should be cleaned before formatting.
| @@ -29,3 +30,9 @@ | |||
| rev: 24.10.0 | |||
| hooks: | |||
| - id: black | |||
There was a problem hiding this comment.
| - id: black | |
| - id: black | |
| types_or: [python, pyi, jupyter] | |
|
@vfdev-5 we could use ruff-format instead of using black separately whats your thoughts? |
We can try that as well. The last time it was the question between black and ruff differences in formatting rules. It may happen that ruff would require reformat the whole codebase. Maybe this can be ok, let's see how many files would be changed by ruff format |
|
Hi all, thanks for the detailed feedback and suggestions . Here’s a summary of the latest updates:
Current configuration
Workflows are now pending maintainer approval. Please let me know if any further adjustments are needed. Thanks again for the guidance! |
Fixes #3578
Description:
This PR adds the nbstripout pre-commit hook to automatically strip Jupyter notebook outputs and unnecessary metadata before committing.
This
helps reduce noisy diffs caused by execution counts, cell outputs, and metadata changes during notebook refactoring.The hook is configured in .pre-commit-config.yaml using:
This ensures cleaner version control history and improves reviewability of notebook changes.