Run any Python code quality tool on a Jupyter Notebook!
Project description
nbQA
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 --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
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
🔧 Configuration
You can configure nbQA
either at the command line, or by using a pyproject.toml
file - see
configuration
for details and examples.
👷 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.2.1
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"]
💬 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 🤔 |
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.2.1.tar.gz
.
File metadata
- Download URL: nbqa-0.2.1.tar.gz
- Upload date:
- Size: 24.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e719a3c4db3aeca052eb104a29ea2696eba6af8ae90cca358e24f58aea3786e |
|
MD5 | e82c2b0f8189c3e8088bded0443bc841 |
|
BLAKE2b-256 | 79ff1196a042dac35e618c1638d09e7645fab05a7785fff50659362daccaab99 |
Provenance
File details
Details for the file nbqa-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: nbqa-0.2.1-py3-none-any.whl
- Upload date:
- Size: 24.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ce7a561314107a6397cc4d8301f0471a79dffbea36a9deed2d530907167aabc |
|
MD5 | 6f99da272792d49c5a2532c11d7f2a5a |
|
BLAKE2b-256 | 934f050fe55e2c74e70d0bf49e983efb6336ff5903a70b4fc3e2e9e0d5838ccc |