davidbrochart / nbterm

Jupyter Notebooks in the terminal.
MIT License
753 stars 37 forks source link

Use nbformat instead of raw json to create/read/save notebooks #3

Closed fperez closed 3 years ago

fperez commented 3 years ago

While it's great that Jupyter notebooks are pure JSON files, I suggest using the nbformat read/write API instead of pure JSON. In practice, your format.py is gradually reinventing nbformat, I think it will be both safer and more productive to reuse nbformat itself.

davidbrochart commented 3 years ago

Yes, it's true that I'm kind of reinventing the wheel, but it's actually on purpose. It allows me to learn the Jupyter stack, and also to develop more quickly. I'm also not using https://github.com/jupyter/jupyter_client, and rebooted it in https://github.com/davidbrochart/kernel_driver. And I started a new Python kernel in https://github.com/davidbrochart/quenelles. I'm also a maintainer of the "official" Jupyter projects, and I want to improve them, but we also need to recognize that some of them have accumulated a lot of technological debt, making it hard to approach. With nbterm, I have found the perfect candidate to recode the stack in a lightweight manner.

fperez commented 3 years ago

Fair enough - though in the case of nbformat I think an argument can be made for the user side of the experience: nbformat will validate notebooks, ensure that the writing of complex notebooks is always correct, read older formats, etc. If nbterm becomes a more widely used tool, those might be arguments to consider. Data loss/notebook corruption is a pretty serious concern :)

I have already been able in small tests to damage a notebook, for example this cell:

image

I had actually run it again inside nbterm, changing it from 1+1 to 1+3. The prompts should match and the output should say 4, but it seems nbterm wrote the new cell content but kept the old output. I also see examples where the output of cells isn't shown correctly in nbterm. This is the same exact notebook open simultaneously in Lab and nbterm:

image

You can see that the outputs aren't correctly shown...

In any case - this is a great and fun project, love what you're doing. I think it has the potential to be very useful in certain contexts, so I hope that on the data loss front it can be 100% robust :)

davidbrochart commented 3 years ago

Thanks for reporting, yes I agree that notebook corruption is a pretty serious issue, I'll work on making nbterm more robust!

davidbrochart commented 3 years ago

Whilenot using nbformat, nbterm is much more robust regarding the notebook format now. Please reopen if you encounter issues.