Run any Python code quality tool on a Jupyter Notebook!
Project description
nbQA
A tool (and pre-commit hook) to run any standard Python code-quality tool on a Jupyter notebook.
🎉 Installation
Install nbqa
in your virtual environment with pip:
python -m pip install -U nbqa
🚀 Examples
Reformat your notebooks with black:
$ nbqa black my_notebook.ipynb --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.
Check for style guide enforcement with flake8:
$ nbqa flake8 my_notebook.ipynb --extend-ignore=E203,E302,E305,E703
my_notebook.ipynb:cell_3:1:1: F401 'import pandas as pd' imported but unused
Upgrade your syntax with pyupgrade:
$ nbqa pyupgrade my_notebook.ipynb --py36-plus --nbqa-mutate
Rewriting my_notebook.ipynb
Perform static code analysis with pylint:
$ nbqa pylint my_notebook.ipynb --disable=C0114
my_notebook.ipynb:cell_1:5:0: W0611: Unused import datetime (unused-import)
🔧 Configuration
You can configure nbqa
either at the command line, or by using a pyproject.toml
file - see
configuration
for details and examples.
👷 Pre-commit
See usage as pre-commit hook for examples.
💬 Testimonials
Alex Andorra, Data Scientist, ArviZ & PyMC Dev, Host of 'Learning Bayesian Statistics' Podcast 🎙️:
well done on
nbqa
@MarcoGorelli ! Will be super useful in CI 😉
Girish Pasupathy, Software engineer and now core-contributor:
thanks a lot for your effort to create such a useful tool
👥 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.
Thanks goes to these wonderful people (emoji key):
Marco Gorelli 💻 🚧 👀 ⚠️ 🤔 |
Sebastian Weigand 🔧 👀 📖 🤔 |
Girish Pasupathy 💻 🚇 🐛 👀 🤔 |
fcatus 🚇 |
HD23me 🐛 |
mani 🤔 🚇 |
Daniel Mietchen 🤔 |
Michał Gacka 🐛 |
Happy 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
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
File details
Details for the file nbqa-0.3.4.tar.gz
.
File metadata
- Download URL: nbqa-0.3.4.tar.gz
- Upload date:
- Size: 30.4 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.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08045f9a07b216d7205354ba29c046fd9a3f04c4618829f96ca9c3de066baf59 |
|
MD5 | e2a7758d2e218500ea996e1e86cf376c |
|
BLAKE2b-256 | 49230b72bd93bcffd1aa13595ad31455d30f510636700689b752140b1485f931 |
Provenance
File details
Details for the file nbqa-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: nbqa-0.3.4-py3-none-any.whl
- Upload date:
- Size: 28.8 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.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2059aa2abeb5912823433995a03c25768853353c5b4bec2a931764b02e0525b1 |
|
MD5 | 28b4e486d1ddc232a1e279c2c4dfe6c1 |
|
BLAKE2b-256 | bcb335b63bd21842196e43923798f740c3cf7f5a93adf3852e4e80b435fe4469 |