jupyter-server / jupyter_ydoc

Jupyter document structures for collaborative editing using Yjs/pycrdt
https://jupyter-ydoc.readthedocs.io
BSD 3-Clause "New" or "Revised" License
28 stars 17 forks source link

Support cell.source as [list, of, strings] #111

Closed Wh1isper closed 1 year ago

Wh1isper commented 1 year ago

Description

https://nbformat.readthedocs.io/en/latest/format_description.html#cell-types

There are a few basic cell types for encapsulating code and text. All cells have the following basic structure:

{ "cell_type" : "type", "metadata" : {}, "source" : "single string or [list, of, strings]", }

In Jupyterlab3.x, cell.source is [list, of, strings], which causes

  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 30, in source
    return self.set(value)
  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 197, in set
    self._ycells.extend(t, [self.create_ycell(cell) for cell in cells])
  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 197, in <listcomp>
    self._ycells.extend(t, [self.create_ycell(cell) for cell in cells])
  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 127, in create_ycell
    cell["source"] = Y.YText(cell["source"])
TypeError: argument 'init': 'list' object cannot be converted to 'PyString'

Reproduce

example ipynb json:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c8d2523-c9e8-4102-8949-8ec23e2be509",
   "metadata": {},
   "outputs": [],
   "source": [
    "print('hello world')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Expected behavior

Context

Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.

welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

Wh1isper commented 1 year ago

I opened a pr for this: https://github.com/jupyter-server/jupyter_ydoc/pull/112

Wh1isper commented 1 year ago

fixed: https://github.com/jupyter-server/jupyter_ydoc/pull/112