s-weigand / flake8-nb

Flake8 checking for jupyter notebooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate annotated notebook with embedded flake8 reports

psychemedia opened this issue · comments

To make it easier to check notebooks, it would be useful to generate notebooks annotated with flake8 reports at the cell level, either as a tagged report cell immediately after each code cell, or by clearing the notebook of all code cell outputs and then injecting the flake8 report into appropriate code cell outputs.

If reports are added to code cell outputs, it would be useful if they were styled with pink warning style such as used in the stale/deprecated pycodestyle_magic:

image

I'm not too sure about this feature 🤔
While I see the usefulness, I also see the problems in having a CLI linting tool manipulate a notebook (at least for now).

  1. Running a CLI tool on a notebook that changes it on disk, can leave you in limbo (true for all CLI tools). For example, imagine the following scenario:
  • You have unsaved changes, so the CLI tool does only knows about the saved changes.
  • Based on that knowledge it changes the notebook, which might lead to data loss.
  • You get prompted the "File changed do you want to 'Reload', 'Overwrite' or 'cancel' "
    The only clean way to prevent a scenario like this would be via an editor plugin that uses the following steps:
  • Save the notebook
  • Run the CLI tool
  • Reload the notebook from disk
    If you know a plugin that allows running an arbitrary CLI tool in that way please tell me 😄
  1. There already is jupyterlab-flake8 which directly gives you feedback in your notebook.

So at least until there is an editor plugin that could prevent such a scenario (e.g. for jupyterlab) I would put this on halt (if you really want this, PR's are welcome 😉 ).

Re: overwriting - I generally get my cli tools to have an option to write to a new file, or even to a new default output file (out.py, ORIGINAL_FILENAME-revised.py etc).

If I get anywhere with a PR, I'll let you know...