Skip to content

Conversation

@hbcarlos
Copy link
Contributor

This PR adds a new YMap for the metadata, to have the metadata as a Map instead of a JSONObject. This way when listening for changes we know what attribute changed. This schema is necessary for jupyterlab/jupyterlab#12359.

I kept ymeta to store other metadata from the notebook that's not part of the metadata object, like nbformat and nbformat_minor.

This PR also improves the initialization of the cells by adding the outputs and attachments to the corresponding cells.

Copy link
Collaborator

@davidbrochart davidbrochart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Carlos.
Tests fail probably because we need a release of @jupyterlab/shared-models, but that won't happen before jupyterlab/jupyterlab#12359 is merged and released. We can merge this PR and release jupyter_ydoc, and have tests failing temporarily, but we need to exactly pin jupyter_ydoc in JupyterLab.

if "id" in cell and meta["nbformat"] == 4 and meta["nbformat_minor"] <= 4:
# strip cell IDs if we have notebook format 4.0-4.4
del cell["id"]
if (cell["cell_type"] == "raw" or cell["cell_type"] == "raw") and len(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the same condition twice: cell["cell_type"] == "raw" or cell["cell_type"] == "raw".
Also, you might want to use not cell["attachments"] instead of len(cell["attachments"]) == 0.

]
with self._ydoc.begin_transaction() as t:
# clear document
# TODO: use clear
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. In yjs, we have a clear function. Not sure if we will have the equivalent in ypy.

if "metadata" in cell:
metadata = cell["metadata"]
cell["metadata"] = Y.YMap(metadata)
if cell_type == "raw" or cell_type == "markdown":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if cell_type == "raw" or cell_type == "markdown":
if cell_type in ["raw", "markdown"]:

if "attachments" in cell:
attachments = cell["attachments"]
cell["attachments"] = Y.YMap(attachments)
if cell_type == "code":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if cell_type == "code":
elif cell_type == "code":

Comment on lines 152 to 154
outputs = []
if "outputs" in cell:
outputs = cell["outputs"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputs = []
if "outputs" in cell:
outputs = cell["outputs"]
outputs = cell.get("outputs", [])

@hbcarlos
Copy link
Contributor Author

Thanks for the review @davidbrochart! I'll apply the changes.

@davidbrochart davidbrochart merged commit 9329161 into jupyter-server:main May 20, 2022
@davidbrochart
Copy link
Collaborator

Thanks!

@hbcarlos hbcarlos deleted the rtc branch May 20, 2022 10:23
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

Successfully merging this pull request may close these issues.

2 participants