Skip to main content

Run any Python code quality tool on a Jupyter Notebook!

Project description

https://github.com/nbQA-dev/nbQA/raw/master/assets/logo.png

nbQA

https://github.com/nbQA-dev/nbQA/workflows/tox/badge.svg https://codecov.io/gh/nbQA-dev/nbQA/branch/master/graph/badge.svg https://badge.fury.io/py/nbqa.svg https://readthedocs.org/projects/nbqa/badge/?version=latest&style=plastic https://img.shields.io/pypi/pyversions/nbqa.svg https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white http://www.mypy-lang.org/static/mypy_badge.svg https://interrogate.readthedocs.io/en/latest/_static/interrogate_badge.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/pylint-10/10-brightgreen.svg

Adapter to run any standard code-quality tool on a Jupyter notebook. Documentation is hosted here.

Installation

Install nbqa with pip:

pip install -U nbqa

Examples

Reformat your notebook with black:

$ nbqa black my_notebook.ipynb --line-length=96 --nbqa-mutate
reformatted my_notebook.ipynb
All done!  🍰 
1 files reformatted.

Sort your imports with isort:

$ nbqa isort my_notebook.ipynb --treat-comment-as-code='# %%' --nbqa-mutate
Fixing my_notebook.ipynb

Check your type annotations with mypy:

$ nbqa mypy my_notebook.ipynb --ignore-missing-imports
my_notebook.ipynb:cell_10:5: error: Argument "num1" to "add" has incompatible type "str"; expected "int"

Run your docstring tests with doctest:

$ nbqa doctest my_notebook.ipynb
**********************************************************************
File "my_notebook.ipynb", cell_2:11, in my_notebook.add
Failed example:
    add(2, 2)
Expected:
    4
Got:
    5
**********************************************************************
1 items had failures:
1 of   2 in my_notebook.hello
***Test Failed*** 1 failures.

Configuration

Here’s an example nbqa.ini file - see configuration for more on configuration:

[isort]
config = setup.cfg
mutate = 1
addopts = --treat-comment-as-code '# %%%%'

[flake8]
config = setup.cfg

Usage as pre-commit hook

If you want to use nbqa with pre-commit, here’s an example of what you could add to your .pre-commit-config.yaml file:

- repo: https://github.com/nbQA-dev/nbQA
  rev: 0.1.28
  hooks:
    - id: nbqa
      args: ['flake8']
      name: nbqa-flake8
      alias: nbqa-flake8
      additional_dependencies: ['flake8']
    - id: nbqa
      args: ['isort', '--nbqa-mutate']
      name: nbqa-isort
      alias: nbqa-isort
      additional_dependencies: ['isort']

Supported third party packages

In theory, nbqa can adapt any Python code-quality tool to a Jupyter Notebook.

In practice, here are the tools it’s been tested with:

Contributing

I will give write-access to anyone who contributes anything useful (e.g. pull request / bug report) - see the contributing guide for details on how to do so.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

nbqa-0.1.28.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

nbqa-0.1.28-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file nbqa-0.1.28.tar.gz.

File metadata

  • Download URL: nbqa-0.1.28.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

File hashes

Hashes for nbqa-0.1.28.tar.gz
Algorithm Hash digest
SHA256 c630e7ff1faa80dd822078e22d7b76ed928fc84749f0c0ae3671fd36820d41cb
MD5 c80cd3e5194fee1174c2b3b2fee4294e
BLAKE2b-256 348e61a7a266884b4aa11ac24fc38a8846925306f4366c1b1dfdc97f2682ebe0

See more details on using hashes here.

Provenance

File details

Details for the file nbqa-0.1.28-py3-none-any.whl.

File metadata

  • Download URL: nbqa-0.1.28-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

File hashes

Hashes for nbqa-0.1.28-py3-none-any.whl
Algorithm Hash digest
SHA256 80328f3a71d24df14714abe3ce9132ed31c8fde8ad2957af70e66300ef0da909
MD5 0f2d8d73ede9bfb971f4e5685f4255cc
BLAKE2b-256 8e32733ceacf6289fad211cbbc8eee0ebd19d08847ed688b455d626aee799c75

See more details on using hashes here.

Provenance

Supported by

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