Skip to main content

Apply black to all code cells in a jupyter notebook.

Project description

black-nb

black-nb applies black to Jupyter notebooks.

Much of the code is taken from the original black project and the behaviour is intentionally similar.

Installation

black-nb can be installed by running pip install black-nb. It requires Python 3.6.0+ to run but you can reformat Python 2 code with it, too.

Usage

To apply black with a line length of 120 to all code cells in notebooks under the current directory:

black-nb . -l 120

To check if notebooks pass black, including have no output:

black-nb . -l 120 --clear-output --check

To exclude reformat everything below ./ excluding ./outputs/* :

black-nb . -l 120 --exclude outputs

Command Line Options

black-nb doesn't provide many options. You can list them by running black-nb --help:

black-nb [OPTIONS] [SRC]...

Options:
  -l, --line-length INTEGER   Where to wrap around.  [default: 88]
                              Don't normalize underscores in numeric literals.
  --check                     Don't write the files back, just return the
                              status.  Return code 0 means nothing would
                              change.  Return code 1 means some files would be
                              reformatted.  Return code 123 means there was an
                              internal error.
  --include TEXT              A regular expression that matches files and
                              directories that should be included on
                              recursive searches. On Windows, use forward
                              slashes for directories.  [default: \.ipynb$]
  --exclude TEXT              A regular expression that matches files and
                              directories that should be excluded on
                              recursive searches. On Windows, use forward
                              slashes for directories.  [default:
                              build/|buck-out/|dist/|_build/|\.eggs/|\.git/|
                              \.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/|\.ipynb_checkpoints]
  --clear-output              Clearing code output is included in formatting.
  --help                      Show this message and exit.

Copyright

Copyright © 2019 Tom Catling.

black-nb is distributed under the terms of the ISC licence.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for black-nb, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size black_nb-0.0.3-py3-none-any.whl (5.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size black-nb-0.0.3.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page