AnswerDotAI / AnswerDotAI/nbdev

Only run pre-commit hooks on modified files

Aperta
#1,175 3 commenti 6 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Jupyter Notebook
Stelle
5.3k
Fork
513
Merge medio
2g 30m
PR unite (30g)
8

Descrizione

### 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]
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia esaminando .pre-commit-hooks.yaml e il comando nbdev_clear, insieme al comportamento di settings.ini descritto nell’issue. Traccia il modo in cui i nomi dei file e i percorsi arrivano al comando. Il lavoro è completo quando l’hook può essere eseguito senza settings.ini, riceve solo file Jupyter modificati e non ha più bisogno di un argomento di percorso implicito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
jupyter-notebook, python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.