Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-weigand/flake8-nb
Flake8 checking for jupyter notebooks
https://github.com/s-weigand/flake8-nb
cli code-quality-analyzer flake8 flake8-nb jupyter-notebooks notebook quality-assurance testing-tools
Last synced: 3 months ago
JSON representation
Flake8 checking for jupyter notebooks
- Host: GitHub
- URL: https://github.com/s-weigand/flake8-nb
- Owner: s-weigand
- License: apache-2.0
- Created: 2019-09-28T16:58:21.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T07:17:11.000Z (11 months ago)
- Last Synced: 2024-04-14T03:07:33.443Z (10 months ago)
- Topics: cli, code-quality-analyzer, flake8, flake8-nb, jupyter-notebooks, notebook, quality-assurance, testing-tools
- Language: Python
- Homepage:
- Size: 654 KB
- Stars: 27
- Watchers: 3
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Authors: AUTHORS.rst
Awesome Lists containing this project
- awesome-flake8-extensions - flake8-nb - Runs flake8 on `*.ipynb` (jupyter notebook) files. (Integrations)
README
# flake8-nb
[](https://pypi.org/project/flake8-nb/)
[](https://anaconda.org/conda-forge/flake8-nb)
[](https://pypi.org/project/flake8-nb/)
[](https://github.com/pre-commit/pre-commit)
[](https://opensource.org/licenses/Apache-2.0)[](https://github.com/s-weigand/flake8-nb/actions)
[](https://flake8-nb.readthedocs.io/en/latest/?badge=latest)
[](https://codecov.io/gh/s-weigand/flake8-nb)
[](https://github.com/s-weigand/flake8-nb)[](https://www.codacy.com/gh/s-weigand/flake8-nb/dashboard?utm_source=github.com&utm_medium=referral&utm_content=s-weigand/flake8-nb&utm_campaign=Badge_Grade)
[](#contributors)
[](https://github.com/psf/black)
[](https://mybinder.org/v2/gh/s-weigand/flake8-nb.git/main?urlpath=lab%2Ftree%2Ftests%2Fdata%2Fnotebooks)[`flake8`](https://github.com/pycqa/flake8) checking for jupyter notebooks.
This tool is mainly aimed towards writing tutorials/lecture material, where one might also want
to show off bad practices and/or errors, while still keeping the rest of the code clean and
without adding the complexity of tooling to the readers
(see [docs on cell tags](https://flake8-nb.readthedocs.io/en/latest/usage.html#cell-tags)).Basically this is a hack on the `flake8`'s `Application` class,
which adds parsing and a cell based formatter for `*.ipynb` files.This is **NOT A PLUGIN** but a stand alone CLI tool/[pre-commit](https://pre-commit.com/) hook to be used instead of the `flake8` command/hook.
## Features
- flake8 CLI tests for jupyter notebooks
- Full base functionality of `flake8` and its plugins
- Input cell based error formatting (Execution count/code cell count/total cellcount)
- Report fine tuning with cell-tags (`flake8-noqa-tags` see [usage](https://flake8-nb.readthedocs.io/en/latest/usage.html#cell-tags))
- [pre-commit](https://pre-commit.com/) hook## Examples
## Default reporting
If you had a notebook with name `example_notebook.ipynb`, where the code cell
which was executed as 34th cell (`In[34]`) had the following code:```python
bad_formatted_dict = {"missing":"space"}
```running `flake8_nb` would result in the following output.
### Execution count
```bash
$ flake8_nb example_notebook.ipynb
example_notebook.ipynb#In[34]:1:31: E231 missing whitespace after ':'
```## Custom reporting
If you prefer the reports to show the cell number rather then the execution count you
can use the `--notebook-cell-format` option, given that the cell is the 5th `code` cell
and 10th total cell (taking `raw` and `markdown` cells into account),
you will get the following output.### Code cell count
```bash
$ flake8_nb --notebook-cell-format '{nb_path}:code_cell#{code_cell_count}' example_notebook.ipynb
example_notebook.ipynb:code_cell#5:1:31: E231 missing whitespace after ':'
```### Total cell count
```bash
$ flake8_nb --notebook-cell-format '{nb_path}:cell#{total_cell_count}' example_notebook.ipynb
example_notebook.ipynb:cell#10:1:31: E231 missing whitespace after ':'
```## Similar projects
- [nbQA](https://github.com/nbQA-dev/nbQA):
Run isort, pyupgrade, mypy, pylint, flake8, mdformat, black, blacken-docs, and more on Jupyter Notebooks## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Sebastian Weigand
π» π€ π§ π π β οΈ π
Jt Miclat
π
Philipp Eisenhauer
π
Shoma Okamoto
β οΈ
Marco Gorelli
π§ π
Tony Hirst
π€
Dobatymo
π
Alp ArΔ±bal
π
1kastner
π
Dominique Sydow
π
Liam Keegan
π π»
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!