Usage
Since flake8_nb
is basically a hacked version of
flake8
its usage is identically.
The only key difference is the appended _nb
is the commands and
configurations name.
Command line usage
The basic usage is to call flake8_nb
with the files/paths,
which should be checked as arguments (see flake8 invocation).
$ flake8_nb path-to-notebooks-or-folder
To customize the behavior you can use the many options provided
by flake8
’s CLI. To see all the provided option just call:
$ flake8_nb --help
Additional flags/options provided by flake8_nb
:
--keep-parsed-notebooks
If this flag is activated the the parsed notebooks will be kept and the path they were saved in will be displayed, for further debugging or trouble shooting.
--notebook-cell-format
Template string used to format the filename and cell part of error report. Possible variables which will be replaced are
nb_path
,exec_count
,code_cell_count
andtotal_cell_count
.
Project wide configuration
Configuration of a project can be saved in one of the following files
setup.cfg
, tox.ini
or .flake8_nb
, on the top level of your project
(see flake8 configuration).
[flake8_nb]
; Default values
keep_parsed_notebooks = False
notebook_cell_format = {nb_path}#In[{exec_count}]
For a detailed explanation on how to use and configure it, you can consult the official flake8 documentation
Per cell/line configuration
There are multiple ways to fine grade configure flake8_nb
on a line or cell basis.
flake8 noqa
comments
The most intuitive way for experienced flake8
users is
to utilize the known flake8 noqa comment on a line, to ignore specific
or all errors, flake8
would report on that given line.
Note
If a normal flake8 noqa comment
ends with a string, which doesn’t
match the error code pattern (\w+\d+
), this comment will be ignored.
As pre-commit hook
Add the following to your .pre-commit-config.yaml
file:
- repo: https://github.com/s-weigand/flake8-nb
rev: 0.5.3 # specify version here
hooks:
- id: flake8-nb
See pre-commit docs for more on pre-commit.