Run any Python code quality tool on a Jupyter Notebook!
Project description
nbQA
Adapter to run any code-quality tool on a Jupyter notebook. Documentation is hosted here.
Prerequisites
If you don’t have pip installed, this Python installation guide can guide you through the process.
Installation
Install nbqa with
$ pip install nbqa
There are no dependencies for nbqa so installation should be lightning-fast.
Check your installation with
$ nbqa --version
nbqa 0.1.13
Quickstart
The general syntax is
nbqa <command> <notebook or directory> <args>
, where command is any standard Python code quality tool. For example, you could run:
$ nbqa flake8 my_notebook.ipynb
$ nbqa black my_notebook.ipynb --check
$ nbqa mypy my_notebook.ipynb --ignore-missing-imports
$ nbqa pytest my_notebook.ipynb --doctest-modules
You can also pass an entire directory instead of a single file, e.g. nbqa flake8 my_notebooks.
Examples
Format your notebooks using black:
$ nbqa black . --line-length=96
reformatted tweet-sentiment-roberta-pytorch.ipynb
All done! ✨ 🍰 ✨
1 files reformatted.
Check static type annotations:
$ nbqa mypy tweet-sentiment-roberta-pytorch.ipynb --ignore-missing-imports
tweet-sentiment-roberta-pytorch.ipynb:cell_10:5: error: Argument "batch_size" to "get_test_loader" has incompatible type "str"; expected "int"
Check any examples in your docstrings are correct:
$ nbqa pytest tweet-sentiment-roberta-pytorch.ipynb --doctest-modules
============================= test session starts ==============================
platform linux -- Python 3.8.2, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /home/marco/tweet-sentiment-extraction
plugins: cov-2.10.0
collected 3 items
tweet-sentiment-roberta-pytorch.ipynb . [100%]
============================== 1 passed in 0.03s ===============================
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:
Configuration
You can pass extra configurations to your tools either via the command line (as in the
examples above), or in a .nbqa.ini file, which could look something like this:
[black]
line-length=96
[flake8]
max-line-length=96
ignore=E203,W503,W504
Flags from this .ini will be passed to nbqa as they’re written.
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/MarcoGorelli/nbQA
rev: 0.1.13
hooks:
- id: nbqa
args: ['flake8']
name: nbqa-flake8
additional_dependencies: ['flake8']
- id: nbqa
args: ['isort']
name: nbqa-isort
additional_dependencies: ['isort']
- id: nbqa
args: ['mypy']
name: nbqa-mypy
additional_dependencies: ['mypy']
See Also
Here are some specialised code quality tools for Jupyter Notebooks:
Project template from cookiecutter.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbqa-0.1.13.tar.gz.
File metadata
- Download URL: nbqa-0.1.13.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a94f6c2411d82f1fd674cb2ad0a232f524142d3ae853fe3fdc9b233e2163e9b9
|
|
| MD5 |
868eab056e5305e4ecadf6a9f961117a
|
|
| BLAKE2b-256 |
5496a8c39f785dc6de0dbba3556a59b903f313a86be7e49c035239041fd39066
|
File details
Details for the file nbqa-0.1.13-py3-none-any.whl.
File metadata
- Download URL: nbqa-0.1.13-py3-none-any.whl
- Upload date:
- Size: 17.3 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/44.0.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f2c07ad7de5b11a3ee2e6f6d0fc2f032df909f5fc73d6d5a52fba7b194a4367
|
|
| MD5 |
530823d122dbd55eb07277df0b53b151
|
|
| BLAKE2b-256 |
10ac998ddb32de6cfae9467fa84a1f1ded5fc28c3c8a1f4f02bbf5fed07ac104
|