KwatMDPhD/Kata.jl

Support pluggable auto formatting of code blocks

Closed this issue · 6 comments

My team uses https://pre-commit.com to automatically run linters and formatters on all of our code. I'm looking for something to run this on jupyter notebooks as well which is why I ran across your project.

As part of our pre-commit process we run

isort
autoflake
black
whitespace checks

it occurs to me that others may run different combinations of these. It would be great if your project could provide a way to generically run a set of linters on each notebook block.

Hi Christopher,

Thank you for your input 👍

I am going to try to (the following is also a note to myself) modularize each application (formatter or whatever an end user wants to apply) for each cell. The challenge is how each application communicates with the previous and the next one. I think we can solve this challenge using echo piping to keep applications as flexible as possible as well as easy to customize. If you have other ideas, feel free to let me know :)

Let's do it. When this is implemented, please give it a try and let me know how it goes.

Best,
Kwat

I think I understand what you mean. The way pre-commit works is it expects that there is a cli tool available which can take a list of files on the command line. In general, all of these formatters will at least work at that level. Some of them allow you to pipe in and get the output. One idea is that you could read each code block out of the jupyter notebook, write it to a temporary file, then run the list of temporary files through the formatters and recreate the notebook after they're done.

I merged @samhardyhey 's pull request. Next, I'm trying to meet @fantapop 's requests while maintaining @samhardyhey 's inputs. Thank you for waiting.

@fantapop, is there a library that lints spacing specifically? Something more than just black?

@fantapop and @KwatME : I think I have worked out a solution for generic tooling

  • My solution is present as this branch on my fork.
  • I have described how it works by under 3.0 Features in README.md
  • I have tested this to work on both py & ipynb

Sending a pr