Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ulupo opened this issue Sep 8, 2023 · 0 comments
Open

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

ulupo opened this issue Sep 8, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ulupo
Copy link

ulupo commented Sep 8, 2023

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, 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 <module>
    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.

@ulupo ulupo added the bug Something isn't working label Sep 8, 2023
@ulupo ulupo changed the title Black is not found when nbdev_export is run in pre-commit hook if black_formatting=True black is not found when nbdev_export is run in pre-commit hook if black_formatting=True Sep 8, 2023
@ulupo ulupo changed the title black is not found when nbdev_export is run in pre-commit hook if black_formatting=True black is not found when nbdev_export is run in pre-commit hook Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant