-
Notifications
You must be signed in to change notification settings - Fork 22
Fix joining of source when source is an array of strings
#186
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
Conversation
source when source is an array of strings
|
Jupyverse sends the cell source as-is, which also leads to extra newlines in JupyterLab. There is a fix in jupyter-server/jupyverse#354, but does it mean this issue is a JupyterLab frontend issue (not particularly an issue in jupyter-ydoc)? Meaning that JupyterLab should render the source correctly if in an array. |
|
JupyterLab uses the This means jupyter-server/jupyverse#354 would then not be necessary, as the frontend would handle reading an array of strings. |
|
But the issue also appears in non-collaborative mode. |
|
Because JupyterLab still instantiates a And uses shared interfaces exposes by |
|
I see, thanks. Then I think this PR is good to go. I'll also merge jupyter-server/jupyverse#354 to better align with jupyter-server. |
|
Thanks @jtpio! |
|
Thanks @davidbrochart for the review! Would it be possible to get this in a patch release? 🙏 |
|
Thanks! |

This should fix the issue noticed in jupyterlite/jupyterlite#1141 (comment).
As discussed in jupyterlite/jupyterlite#1141 (comment), loading notebooks which have cells with their
sourceset to be a list of strings instead of a single string.Example notebook: https://github.com/jupyterlite/jupyterlite/blob/main/examples/pyodide/ipycanvas.ipynb
Example cell:
{ "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def life_step(x):\n", " \"\"\"Game of life step\"\"\"\n", " nbrs_count = sum(\n", " np.roll(np.roll(x, i, 0), j, 1)\n", " for i in (-1, 0, 1)\n", " for j in (-1, 0, 1)\n", " if (i != 0 or j != 0)\n", " )\n", " return (nbrs_count == 3) | (x & (nbrs_count == 2))" ] },Which in JupyterLite renders as follows with extra line breaks:
Currently the server component in JupyterLite does not normalize the
sourceto be a string. So it sends the array of strings to the frontend.This is not an issue in stock JupyterLab because the response from the Jupyter Server already normalizes the
sourceto be a single string:This is likely because Jupyter Server uses
nbformatto read the notebook: https://github.com/jupyter-server/jupyter_server/blob/3544deb53902cc02c9aa9d6513b3c30f1113896b/jupyter_server/services/contents/fileio.py#L264-L291And the
nbformatdocumentation mentions the following in https://nbformat.readthedocs.io/en/latest/format_description.html#cell-types:nbformatalso joins the string with an empty string: https://github.com/jupyter/nbformat/blob/0a2942c8f77d33b43a327293c7a7596afcf4527d/nbformat/v4/rwbase.py#L38