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 --help:

black [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.

Source Distribution

black-nb-0.0.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

black_nb-0.0.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file black-nb-0.0.2.tar.gz.

File metadata

  • Download URL: black-nb-0.0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for black-nb-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ad96c0f1aebd3074ebdc8dd874fcde3f17b3099f426b683cf6d85b7dd8975cdc
MD5 81c71f424e4c2e6a3525a76c1502b2cf
BLAKE2b-256 21d40085cdf66a711c1c0db24c444b22de32e5536e12ca7fe84971d9cb5c7264

See more details on using hashes here.

File details

Details for the file black_nb-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: black_nb-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.7.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for black_nb-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4283714f1ba03bb4326e5c669e66b716c50c6a4ec6d226fda6067512d46c36a4
MD5 00efda9755a9991b7f5df861aa9ee993
BLAKE2b-256 b7efd5a5a9b47fbb3c06f588d66ae8617b1944540a7571e1e28e4ff85eb7a98d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page