dfm / black_nbconvert

Apply black to ipynb files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom excluding in recursive mode

The-Compiler opened this issue · comments

Right now it looks like .ipynb-checkpoints is excluded when using black_nbconvert ., but that include is hardcoded. This means when e.g. using it via tox (or from a hand-created virtualenv), it will end up picking its own testcases:

$ .venv/bin/black_nbconvert .
Formatted: /home/florian/hsr/python-basics/jupyter-notebooks/.venv/lib/python3.9/site-packages/nbconvert/tests/files/notebook3_with_errors.ipynb
[...]
Formatted: /home/florian/hsr/python-basics/jupyter-notebooks/.venv/lib/python3.9/site-packages/nbclient/tests/files/ipywidgets.nbconvert.ipynb
Formatted: /home/florian/hsr/python-basics/jupyter-notebooks/.venv/lib/python3.9/site-packages/nbformat/tests/invalid.ipynb
Traceback (most recent call last):
  [...]
  File "/home/florian/hsr/python-basics/jupyter-notebooks/.venv/lib/python3.9/site-packages/blib2to3/pgen2/tokenize.py", line 542, in generate_tokens
    raise TokenError("EOF in multi-line statement", (lnum, 0))
blib2to3.pgen2.tokenize.TokenError: ('EOF in multi-line statement', (3, 0))

I think there should be some kind of --exclude argument, probably accepting a list of globs or so. Or perhaps any hidden directory (i.e. .*) should be excluded by default, or at least .venv and .tox.

I'd say that the preferred usage is via pre-commit which already has this built in so I'm not keen to add such a feature. But, if you feel that it would help for your use cases, feel free to open a PR (just try to keep it simple!).

black now runs on Jupyter Notebooks directly (just bringing this up as an FYI to save you from duplicating work!)

Awesome news - thanks!!