Skip to content

mls-tuhh/flake8-nb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flake8-nb

PyPi Version Conda Version Supported Python Versions Pre-commit License

Actions Status Documentation Status Testing Coverage Documentation Coverage

Codacy Badge All Contributors Code style Python: black Binder

flake8 checking for jupyter notebooks. 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 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)
  • pre-commit 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:

bad_formatted_dict = {"missing":"space"}

running flake8_nb would result in the following output.

Execution count

$ 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

$ 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

$ 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 ':'

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Sebastian Weigand

💻 🤔 🚧 📆 🚇 ⚠️ 📖

Jt Miclat

🐛

Philipp Eisenhauer

🐛

Shoma Okamoto

⚠️

Marco Gorelli

🔧 📖

Tony Hirst

🤔

Dobatymo

🐛

Alp Arıbal

🐛

1kastner

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Flake8 checking for jupyter notebooks

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 80.4%
  • Jupyter Notebook 17.4%
  • Makefile 2.2%