AnswerDotAI / AnswerDotAI/nbdev

Only run pre-commit hooks on modified files

Open
#1,175 3 comments 6 reactions 0 assignees View on GitHub
enhancement
Dominant language
Jupyter Notebook
Stars
5.3k
Forks
513
Avg merge
2d 30m
Merged PRs (30d)
8

Description

### Motivation
Improve integration with pre-commit

### Expected behavior
Can use the nbdev_clear without having a `nbdev` config at `settings.ini` or to implicit pass `args: ['-fname', 'mydir/']` at pre-commit config.

### Explanation
As I explain [here](https://github.com/fastai/nbdev/issues/1152#issuecomment-1288105205), seems to be a workaround need to add the `path` if you don't have a nbdev config. Mainly, because this will cause the command to be executed for all files at that path, which is unnecessary.

If the command accepts `n` arguments (multiple filenames), we can use the pre-commit "normally", by letting it command in which files the hook should be executed -- only those that have been changed in the commit.

Consequently, this will improve the hook's execution speed, since it will not be checking for unnecessary files.

----

With this enhancement, we can update the `.pre-commit-hooks.yaml` to:

```diff
--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -5,7 +5,8 @@
always_run: true
- pass_filenames: false
+ pass_filenames: true
+ types: [jupyter]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.