Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to provide round trip consistency for notebooks in nbformat version 4.5 (with cell ids)? #735

Closed
mwouts opened this issue Feb 5, 2021 · 3 comments

Comments

@mwouts
Copy link
Owner

mwouts commented Feb 5, 2021

As reported at #715 , the new cell ids introduced in notebooks in nbformat version 4.5 causes trouble with Jupytext. Indeed, the text representation does not store the cell id, and in that case nbformat regenerate a (random) cell id, contributing random differences on text <-> ipynb round trips.

I see at least two possible approaches to address this issue:

  1. Patch nbformat to generate non-random cell ids
  2. Store the cell id in the Jupytext representation of the notebook

Anyone is welcome to contribute ideas or comments!

@mwouts
Copy link
Owner Author

mwouts commented Feb 8, 2021

Actually, Jupytext already preserves the cell id if one uses either --update or --sync (since jupytext>=1.7.1).

@mwouts mwouts closed this as completed Feb 8, 2021
@krassowski
Copy link

Apologies for reviving an old thread, but while implementing a feature of linking to cell by ID for jupyter-book (already present in JupyterLab and in nbconvert) here executablebooks/MyST-NB#519 I came up against a challenge of cell IDs being dropped by jupytext during conversion to myst format (so these end up randomly regenerated by nbformat). Is there a canonical way to encode these/intend to support it in jupytext?

Just to highlight, while myst has a support for cell-level metadata cell ID is one level higher in hierarchy, i.e.:

{
   "cell_type": "code",
   "execution_count": 1,
   "id": "2e32aa7d",    #  this is getting lost
   "metadata": {    #  this is supported
    "load": "mystnb_codecell_file.py"
   },
   "outputs": [],
   "source": [
    "# flake8: noqa\n",
    "\n",
    "import numpy as np\n"
   ]
  }

@mwouts
Copy link
Owner Author

mwouts commented Jul 30, 2023

Hey @krassowski , yes you're right, Jupytext does not store the cell id in the text notebooks. The cell ids are preserved only in .ipynb notebooks when those are paired with a text notebook. Obviously, if myst-nb now offers support for cell ids we could revisit this and pass the ids to myst-nb. Would you mind opening a new issue for this? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants