jupyterkernel.vim icon indicating copy to clipboard operation
jupyterkernel.vim copied to clipboard

ipynb IO support via vimpyter

Open hisaknown opened this issue 6 years ago • 9 comments

vimpyter supports ipynb IO using notedown.
https://github.com/szymonmaszke/vimpyter

So I plan to make jupyterkernel.vim pluggable to vimpyter, in order to give complete Jupyter experience within vim.
To do so, jupyterkernel.vim must support notedown-styled markdown.

hisaknown avatar Oct 24 '18 09:10 hisaknown

Hmm, I checked out notedown and vimpyter, but the outputs are in json format, which is hardly readable for human...
Although notedown has an option to generate markdown with human-readable outputs, the generated markdown cannot get back to notebook as expected so far.
I think that human-friendliness is really important for tools like jupyterkernel.vim, so json output is not acceptable.

The situation seem to be difficult than I thought. What do you think? @szymonmaszke

hisaknown avatar Oct 24 '18 10:10 hisaknown

I think it should be implemented inside vimpyter, not on your part. My plugin edits the view of json notebook (created via notedown) located inside temporary folder (usually /tmp). After each save the converted data is transported to the original notebook using notedown as well.

Outputs in my notebook are not essential, those are more of a side-product which is not that useful to the end user. Maybe I could switch the form of output to markdown, would that be useful? Notebook itself would be updated without any outputs, but it seems like a better general solution IMO.

User would have readable outputs inside vim and jupyter inside the browser would only be useful for occasional, once in a long while checks.

Last thing: Could your plugin support images or animations in some form, even using 3rd party tools? You seem to be way more competent than me when it comes to jupyter's kernel.

szymonmaszke avatar Oct 27 '18 20:10 szymonmaszke

Thanks for reply. First of all, let me clarify my goal for jupyterkernel.vim. I am required to use Jupyter notebook for my research, to share the notebook with my collegues. But I want to use vim, not Jupyter (although there is a plugin for Jupyter that provides vim-like operation). So I develop jupyterkernel.vim to enable me to:

  • Run code within vim.
  • Save and load ipynb, so that my collegues can read and run it with Jupyter notebook, and I can read and run their notebook in vim.

Outputs in my notebook are not essential, those are more of a side-product which is not that useful to the end user. Maybe I could switch the form of output to markdown, would that be useful? Notebook itself would be updated without any outputs, but it seems like a better general solution IMO.

Yes, that would be an option. It may be OK for users who run notebooks in vim (with jupyterkernel.vim), not in Jupyter. But my situation is not, as I mentioned...

Last thing: Could your plugin support images or animations in some form, even using 3rd party tools? You seem to be way more competent than me when it comes to jupyter's kernel.

I suppose there are some ways to do that. Since the kernels (maybe) usually output plots as base64 encoded image, we can embed them in markdown file. Then, we can use plugins to preview markdown, like previm.

I think it is OK to label this issue as "pending", because it may require non-negligible effort to both you and me.

hisaknown avatar Oct 28 '18 01:10 hisaknown

Yeah, leave it open as I don't see myself working on mine plugin anytime soon, maybe in 3 months or so.

I will come back to this issue when I get more time.

szymonmaszke avatar Oct 28 '18 16:10 szymonmaszke

Hi all, I'm interested in both vimpyter and jupyterkernel.vim and may have some suggestions. @hisaknown you might be interested in https://github.com/mwouts/jupytext which allows round trip conversions of ipynb notebooks to markdown and python formats.

In particular, using the Python percent format, your plugin could be like vscodeJupyter or hydrogen but for vim.

theodcr avatar Nov 16 '18 12:11 theodcr

Thank you for your suggestion!

I've just took a quick look at jupytext. It seems to be a nice tool, but it doesn't reserve outputs when it converts ipynb to markdown. And the philosophy of jupytext about outputs is "to update outputs, run in Jupyter." It's not jupyterkernel.vim heads for.

I'm going to check it deeper, but integration with jupytext may not be straightforward, unfortunately...

hisaknown avatar Nov 16 '18 13:11 hisaknown

I understand and agree. Indeed jupytext doesn't support outputs in the markdown or python files.

So for now notedown + vimpyter seems to be the way to go for human-readable outputs in vim. And implementing round trip output conversion would have to be done by notedown or jupytext.

theodcr avatar Nov 16 '18 13:11 theodcr

If there was a way to convert json outputs to human readable form (and the reverse would be useful too), I think I could support it on my part.

szymonmaszke avatar Nov 16 '18 14:11 szymonmaszke

the way to go might be displaying the output in a human readable format like this plugin does, and since the human readable format is loosing information about how to represent the output in json format we could keep the json format below it in a fold.

This way we get clear output for the user and all the information is available when exporting in .ipynb format

TitouanT avatar Dec 05 '18 21:12 TitouanT