This project is no longer necessary!
To replace your black_nbconvert
pre-commit
configuration, use:
- repo: https://github.com/psf/black
rev: "22.1.0"
hooks:
- id: black-jupyter
If you're still using this project, the original README is below:
Tired of having to think about formatting in Jupyter notebooks? Look no further! This script will correctly format your Jupyter notebooks for you using black.
Warning: This project will overwrite your notebooks in place. It shouldn't change anything except the format, but use at your own risk!
To install:
pip install black_nbconvert
To check a notebook:
black_nbconvert --check /path/to/a/notebook.ipynb
To fix the formatting in a notebook (in place):
black_nbconvert /path/to/a/notebook.ipynb
If you pass a directory instead of a notebook file, notebooks will be found recursively below that directory. For example:
black_nbconvert .
will fix the formatting for all notebooks in the current directory and (recursively) below.
Configuration: Configuration for black
in a pyproject.toml
file above the target files will be respected.
Use pre-commit.
Once you have it installed, add this to the .pre-commit-config.yaml
in your repository:
repos:
- repo: https://github.com/dfm/black_nbconvert
rev: v0.3.0
hooks:
- id: black_nbconvert
Then run pre-commit install
and you're ready to go.