-
Notifications
You must be signed in to change notification settings - Fork 22
Changes the schema #27
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
davidbrochart
left a comment
There was a problem hiding this 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.
jupyter_ydoc/ydoc.py
Outdated
| 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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?
There was a problem hiding this comment.
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.
jupyter_ydoc/ydoc.py
Outdated
| if "metadata" in cell: | ||
| metadata = cell["metadata"] | ||
| cell["metadata"] = Y.YMap(metadata) | ||
| if cell_type == "raw" or cell_type == "markdown": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if cell_type == "raw" or cell_type == "markdown": | |
| if cell_type in ["raw", "markdown"]: |
jupyter_ydoc/ydoc.py
Outdated
| if "attachments" in cell: | ||
| attachments = cell["attachments"] | ||
| cell["attachments"] = Y.YMap(attachments) | ||
| if cell_type == "code": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if cell_type == "code": | |
| elif cell_type == "code": |
jupyter_ydoc/ydoc.py
Outdated
| outputs = [] | ||
| if "outputs" in cell: | ||
| outputs = cell["outputs"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| outputs = [] | |
| if "outputs" in cell: | |
| outputs = cell["outputs"] | |
| outputs = cell.get("outputs", []) |
|
Thanks for the review @davidbrochart! I'll apply the changes. |
for more information, see https://pre-commit.ci
|
Thanks! |
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
ymetato store other metadata from the notebook that's not part of the metadata object, likenbformatandnbformat_minor.This PR also improves the initialization of the cells by adding the outputs and attachments to the corresponding cells.