AnswerDotAI / AnswerDotAI/nbdev

`black` is not found when `nbdev_export` is run in pre-commit hook

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

Descrizione

When creating a brand new repository and setting `black_formatting=True` in `settings.ini`, indeed `black` is run as part of `nbdev_export` correctly. However, when I add `nbdev_clean` and `nbdev_export` as pre-commit hooks, exactly as in the [docs](https://nbdev.fast.ai/tutorials/pre_commit.html), `nbdev_clean` runs correctly but `nbdev_export` breaks with the following traceback:

```
Traceback (most recent call last):
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/export.py", line 36, in black_format
try: import black
ModuleNotFoundError: No module named 'black'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/bin/nbdev_export", line 8, in
sys.exit(nbdev_export())
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/doclinks.py", line 138, in nbdev_export
for f in files: nb_export(f)
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/export.py", line 49, in nb_export
nb.process()
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/process.py", line 126, in process
for proc in self.procs: self._proc(proc)
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/process.py", line 119, in _proc
for cell in self.nb.cells: self._process_cell(proc, cell)
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/process.py", line 110, in _process_cell
if callable(proc) and not _is_direc(proc): cell = opt_set(cell, proc(cell))
File "/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10/lib/python3.10/site-packages/nbdev/export.py", line 37, in black_format
except: raise ImportError("You must install black: `pip install black` if you wish to use black formatting with nbdev")
ImportError: You must install black: `pip install black` if you wish to use black formatting with nbdev
```
I can make things work by activating the environment `/Users/ulupo/.cache/pre-commit/repochwlih_v/py_env-python3.10` and installing `black` there, but this is not an ideal solution.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da nbdev/export.py, in particolare da black_format, e confronta l’ambiente normale con l’ambiente pre-commit descritto nel traceback. Esamina la configurazione di pre-commit nella documentazione collegata e riproduci il problema con nbdev_clean e nbdev_export. Il lavoro è completato quando nbdev_export termina correttamente con black_formatting=True se eseguito come hook pre-commit.

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

Valutazione

Stack tecnologico
jupyter, python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 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.