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

Split up the backend, frontend, and the docprovider #280

Merged
merged 18 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
- name: Run the tests with Coverage
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
run: |
python -m pytest -vv --cov jupyter_collaboration --cov-branch --cov-report term-missing:skip-covered
python -m pytest -vv --cov jupyter_server_ydoc --cov-branch --cov-report term-missing:skip-covered

#- name: Run the tests on pypy
# if: ${{ startsWith(matrix.python-version, 'pypy') }}
Expand All @@ -126,7 +126,7 @@ jobs:
- name: Run the tests on Windows
if: ${{ startsWith(runner.os, 'Windows') }}
run: |
python -W ignore::ImportWarning -m pytest -vv --cov jupyter_collaboration --cov-branch --cov-report term-missing:skip-covered
python -W ignore::ImportWarning -m pytest -vv --cov jupyter_server_ydoc --cov-branch --cov-report term-missing:skip-covered

- uses: jupyterlab/maintainer-tools/.github/actions/upload-coverage@v1

Expand All @@ -136,7 +136,7 @@ jobs:
run: |
set -eux
jupyter server extension list
jupyter server extension list 2>&1 | grep -ie "jupyter_collaboration.*OK"
jupyter server extension list 2>&1 | grep -ie "jupyter_server_ydoc.*OK"
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "@jupyter/collaboration-extension.*OK"
python -m jupyterlab.browser_check
Expand Down Expand Up @@ -196,7 +196,15 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/make-sdist@v1
- name: Build SDist
shell: bash
run: |
pip install build
find projects/* -maxdepth 0 -type d | xargs -L 1 python -m build --sdist --outdir dist/
- uses: actions/upload-artifact@v3
with:
name: "sdist"
path: dist/*.tar.gz

test_sdist:
runs-on: ubuntu-latest
Expand All @@ -216,10 +224,11 @@ jobs:
set -ex
cd sdist
mkdir test
tar --strip-components=1 -zxvf *.tar.gz -C ./test
find *.tar.gz | xargs -L 1 tar -C ./test -zxvf
cd test
python -m pip install "jupyterlab>=4.0.0,<5"
python -m pip install ".[test]"
# install each from source, except for `jupyter_collaboration` metapackage
find ./* -maxdepth 0 -type d -not -path './jupyter_collaboration-*' | sed 's/$/[test]/' | xargs -L 1 python -m pip install
echo "::endgroup::"

- name: Run Test
Expand All @@ -228,10 +237,14 @@ jobs:
echo "::group::Run test"
set -ex
cd sdist/test

# for now only `jupyter_server_ydoc` includes python tests
cd jupyter_server_ydoc*
python -m pytest -vv -raXxs --durations 10 --color=yes
cd ..

jupyter server extension list
jupyter server extension list 2>&1 | grep -ie "jupyter_collaboration.*OK"
jupyter server extension list 2>&1 | grep -ie "jupyter_server_ydoc.*OK"
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "@jupyter/collaboration-extension.*OK"
python -m jupyterlab.browser_check --no-browser-test
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ node_modules/
*.tsbuildinfo
package-lock.json
docs/source/ts
jupyter_collaboration/labextension

# Version file is handled by hatchling
jupyter_collaboration/_version.py
.jupyter
labextension

# Integration tests
ui-tests/test-results/
Expand Down
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ header:
- 'coverage'
- 'LICENSE'
- 'yarn.lock'
- '**/_version.py'

comment: on-failure
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ repos:
rev: v0.991
hooks:
- id: mypy
exclude: "^binder/jupyter_config\\.py$"
exclude: "(^binder/jupyter_config\\.py$)|(/setup\\.py$)"
args: ["--config-file", "pyproject.toml"]
additional_dependencies: [tornado, pytest]
stages: [manual]
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Jupyter Real-Time Collaboration

[![Build Status](https://github.com/jupyterlab/jupyter_collaboration/actions/workflows/test.yml/badge.svg?query=branch%3Amain++)](https://github.com/jupyterlab/jupyter_collaboration/actions?query=branch%3Amain++)[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab/jupyter_collaboration/main)[![PyPI](https://img.shields.io/pypi/v/jupyter-collaboration)](https://pypi.org/project/jupyter-collaboration)[![npm](https://img.shields.io/npm/v/@jupyter/collaboration-extension)](https://www.npmjs.com/package/@jupyter/collaboration-extension)
[![Build Status](https://github.com/jupyterlab/jupyter_collaboration/actions/workflows/test.yml/badge.svg?query=branch%3Amain++)](https://github.com/jupyterlab/jupyter_collaboration/actions?query=branch%3Amain++)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab/jupyter_collaboration/main)
[![PyPI](https://img.shields.io/pypi/v/jupyter-collaboration)](https://pypi.org/project/jupyter-collaboration)
[![npm](https://img.shields.io/npm/v/@jupyter/collaboration-extension)](https://www.npmjs.com/package/@jupyter/collaboration-extension)

JupyterLab Real-Time Collaboration is a Jupyter Server Extension and JupyterLab extensions providing support for [Y documents](https://github.com/jupyter-server/jupyter_ydoc) and adding collaboration UI elements in JupyterLab.

Expand Down
7 changes: 6 additions & 1 deletion docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ steps:
pip install --upgrade pip
git clone https://github.com/jupyterlab/jupyter_collaboration
cd jupyter_collaboration
# install monorepo
pip install -e ".[dev,test]"
jupyter labextension develop --overwrite .
# install local dependencies as editable
pip install -e projects/jupyter-collaboration-ui -e projects/jupyter-docprovider -e projects/jupyter-server-ydoc
# link lab extensions
jupyter labextension develop --overwrite projects/jupyter-collaboration-ui
jupyter labextension develop --overwrite projects/jupyter-docprovider


If you are using a system-wide Python installation and you only want to install the server for you,
Expand Down
8 changes: 4 additions & 4 deletions docs/source/developer/python_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
Python API
==========

``jupyter_collaboration`` instantiates :any:`YDocExtension` and stores it under ``serverapp.settings`` dictionary, under the ``"jupyter_collaboration"`` key.
``jupyter_server_ydoc`` instantiates :any:`YDocExtension` and stores it under ``serverapp.settings`` dictionary, under the ``"jupyter_server_ydoc"`` key.
This instance can be used in other extensions to access the public API methods.

For example, to access a read-only view of the shared notebook model in your jupyter-server extension, you can use the :any:`get_document` method:

.. code-block::

collaboration = serverapp.settings["jupyter_collaboration"]
collaboration = serverapp.settings["jupyter_server_ydoc"]
document = collaboration.get_document(
path='Untitled.ipynb',
content_type="notebook",
Expand All @@ -23,10 +23,10 @@ For example, to access a read-only view of the shared notebook model in your jup
API Reference
-------------

.. automodule:: jupyter_collaboration.app
.. automodule:: jupyter_server_ydoc.app
:members:
:inherited-members:

.. automodule:: jupyter_collaboration.handlers
.. automodule:: jupyter_server_ydoc.handlers
:members:
:inherited-members:
15 changes: 2 additions & 13 deletions packages/collaboration-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"build:labextension:dev": "jupyter labextension build --development True .",
"clean": "jlpm run clean:lib",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo node_modules",
"clean:labextension": "rimraf ../../jupyter_collaboration/labextension",
"clean:labextension": "rimraf ../../projects/jupyter-collaboration-ui/jupyter_collaboration_ui/labextension",
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
"install:extension": "jlpm run build",
"watch": "run-p watch:src watch:labextension",
Expand All @@ -60,17 +60,10 @@
"@jupyterlab/apputils": "^4.2.0-beta.0",
"@jupyterlab/codemirror": "^4.2.0-beta.0",
"@jupyterlab/coreutils": "^6.0.5",
"@jupyterlab/docregistry": "^4.2.0-beta.0",
"@jupyterlab/filebrowser": "^4.2.0-beta.0",
"@jupyterlab/fileeditor": "^4.2.0-beta.0",
"@jupyterlab/logconsole": "^4.2.0-beta.0",
"@jupyterlab/notebook": "^4.2.0-beta.0",
"@jupyterlab/services": "^7.0.5",
"@jupyterlab/settingregistry": "^4.2.0-beta.0",
"@jupyterlab/statedb": "^4.2.0-beta.0",
"@jupyterlab/translation": "^4.2.0-beta.0",
"@jupyterlab/ui-components": "^4.2.0-beta.0",
"@lumino/commands": "^2.1.0",
"@lumino/widgets": "^2.1.0",
"y-protocols": "^1.0.5",
"y-websocket": "^1.3.15",
Expand All @@ -95,11 +88,7 @@
"jupyterlab": {
"extension": true,
"schemaDir": "./schema",
"outputDir": "../../jupyter_collaboration/labextension",
"disabledExtensions": [
"@jupyterlab/filebrowser-extension:defaultFileBrowser",
"@jupyterlab/notebook-extension:cell-executor"
],
"outputDir": "../../projects/jupyter-collaboration-ui/jupyter_collaboration_ui/labextension",
"sharedPackages": {
"@codemirror/state": {
"bundled": false,
Expand Down
64 changes: 1 addition & 63 deletions packages/collaboration-extension/src/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
EditorExtensionRegistry,
IEditorExtensionRegistry
} from '@jupyterlab/codemirror';
import { type MarkdownCell } from '@jupyterlab/cells';
import { INotebookCellExecutor, runCell } from '@jupyterlab/notebook';
import { WebSocketAwarenessProvider } from '@jupyter/docprovider';
import { SidePanel, usersIcon } from '@jupyterlab/ui-components';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { URLExt } from '@jupyterlab/coreutils';
import { ServerConnection } from '@jupyterlab/services';
import { IStateDB, StateDB } from '@jupyterlab/statedb';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
Expand Down Expand Up @@ -191,63 +189,3 @@ export const userEditorCursors: JupyterFrontEndPlugin<void> = {
});
}
};

export const notebookCellExecutor: JupyterFrontEndPlugin<INotebookCellExecutor> =
{
id: '@jupyter/collaboration-extension:notebook-cell-executor',
description:
'Add notebook cell executor that uses REST API instead of kernel protocol over WebSocket.',
autoStart: true,
provides: INotebookCellExecutor,
activate: (app: JupyterFrontEnd): INotebookCellExecutor => {
if (PageConfig.getOption('serverSideExecution') === 'true') {
return Object.freeze({ runCell: runCellServerSide });
}
return Object.freeze({ runCell });
}
};

async function runCellServerSide({
cell,
notebook,
notebookConfig,
onCellExecuted,
onCellExecutionScheduled,
sessionContext,
sessionDialogs,
translator
}: INotebookCellExecutor.IRunCellOptions): Promise<boolean> {
switch (cell.model.type) {
case 'markdown':
(cell as MarkdownCell).rendered = true;
cell.inputHidden = false;
onCellExecuted({ cell, success: true });
break;
case 'code': {
const kernelId = sessionContext?.session?.kernel?.id;
const settings = ServerConnection.makeSettings();
const apiURL = URLExt.join(
settings.baseUrl,
`api/kernels/${kernelId}/execute`
);
const cellId = cell.model.sharedModel.getId();
const documentId = `json:notebook:${notebook.sharedModel.getState(
'file_id'
)}`;
const body = `{"cell_id":"${cellId}","document_id":"${documentId}"}`;
const init = {
method: 'POST',
body
};
try {
await ServerConnection.makeRequest(apiURL, init, settings);
} catch (error: any) {
throw new ServerConnection.NetworkError(error);
}
break;
}
default:
break;
}
return Promise.resolve(true);
}
18 changes: 2 additions & 16 deletions packages/collaboration-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,25 @@

import { JupyterFrontEndPlugin } from '@jupyterlab/application';

import {
drive,
yfile,
ynotebook,
defaultFileBrowser,
logger
} from './filebrowser';
import {
userMenuPlugin,
menuBarPlugin,
rtcGlobalAwarenessPlugin,
rtcPanelPlugin,
userEditorCursors,
notebookCellExecutor
userEditorCursors
} from './collaboration';
import { sharedLink } from './sharedlink';

/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
drive,
yfile,
ynotebook,
defaultFileBrowser,
logger,
userMenuPlugin,
menuBarPlugin,
rtcGlobalAwarenessPlugin,
rtcPanelPlugin,
sharedLink,
userEditorCursors,
notebookCellExecutor
userEditorCursors
];

export default plugins;
3 changes: 3 additions & 0 deletions packages/docprovider-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @jupyter/docprovider-extension

A JupyterLab package which provides a set of plugins for collaborative shared models.
Loading
Loading