jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.58k stars 4.86k forks source link

Would it be possible to add PyLint code checking to Jupyter-Python cells? #2872

Open konstantint opened 6 years ago

konstantint commented 6 years ago

... and what would be a reasonable approach for implementing it (e.g. what is the most relevant place for plugging in this logic)?

Madhu94 commented 6 years ago

The right place would be in a notebook extension and not part of Jupyter itself. Like this one for style checks

Can't seem to find a notebook extension for linting though..maybe the core team can point you to something.

juhasch commented 6 years ago

I guess a good place to start would be this: https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/code_prettify

gpshead commented 5 years ago

Another similar thing, this one invokes mypy on a cell: https://gist.github.com/knowsuchagency/f7b2203dd613756a45f816d6809f01a6

wstomv commented 5 years ago

The IHaskell kernel has built-in support for calling hlint (the Haskell equivalent of pylint). It does not even require cell magics. You can simply turn hlint checking on and off globally (default is on); see the IHaksell Wiki. It is annoying if you have to add a cell magic to every cell you want to have checked (especially in an educational setting).

Something like that for Python would be wonderful (especially if it would also check type hints).

psychemedia commented 5 years ago

The https://github.com/mattijn/pycodestyle_magic magic allows you run Flake8 and pycodestyle checks over code within a particular cell.

From the docs:

Enable the magic function by using the pycodestyle_magic module in a cell

%load_ext pycodestyle_magic

and then use the function in your cell to check compliance with pycodestyle or flake8 as such:

%%pycodestyle

or for flake8

%%flake8

stefaneidelloth commented 2 years ago

With nbqa its possible to run pylint against Jupyter notebooks from the console, e.g. nbqa pylint . https://pypi.org/project/nbqa/

I am still looking for a JupyterLab extension that auto-checks all notebooks and does not need a cell magic etc. pycodestyle_magic has an option %pycodestyle_on that enables checks for all cells in a notebook. I would prefer a plugin with a checkbox "pylint enabled" in its JupyterLab settings.