Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Make the service worker optional #92

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The [xeus-python](https://github.com/jupyter-xeus/xeus-python) Python kernel for

## Requirements

- JupyterLite >= 0.1.0b12
- JupyterLite >= 0.1.0b16

## Install

Expand All @@ -31,22 +31,22 @@ jupyter lite build

## Pre-installed packages

xeus-python allows you to pre-install packages in the Python runtime. You can pre-install packages by passing the ``XeusPythonEnv.packages`` CLI option to ``jupyter lite build``.
xeus-python allows you to pre-install packages in the Python runtime. You can pre-install packages by passing the `XeusPythonEnv.packages` CLI option to `jupyter lite build`.
This will automatically install any labextension that it founds, for example installing ipyleaflet will make ipyleaflet work without the need to manually install the jupyter-leaflet labextension.

For example, say you want to install ``NumPy``, ``Matplotlib`` and ``ipyleaflet``, it can be done with the following command:
For example, say you want to install `NumPy`, `Matplotlib` and `ipyleaflet`, it can be done with the following command:

```bash
jupyter lite build --XeusPythonEnv.packages=numpy,matplotlib,ipyleaflet
```

The same can be achieved through a ``jupyterlite_config.json`` file:
The same can be achieved through a `jupyterlite_config.json` file:

```json
{
"XeusPythonEnv": {
"packages": ["numpy", "matplotlib", "ipyleaflet"]
}
"XeusPythonEnv": {
"packages": ["numpy", "matplotlib", "ipyleaflet"]
}
}
```

Expand Down
3 changes: 1 addition & 2 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ dependencies:
- mamba
- pydata-sphinx-theme
- pip

- pip:
- jupyterlite
- jupyterlite>=0.1.0b16
- jupyterlite-sphinx
- jupyterlite-xeus-python>=0.5.0
14 changes: 7 additions & 7 deletions docs/jupyter-lite.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"jupyter-lite-schema-version": 0,
"jupyter-config-data": {
"disabledExtensions": [
"@jupyterlite/javascript-kernel-extension",
"@jupyterlite/pyolite-kernel-extension"
]
}
"jupyter-lite-schema-version": 0,
"jupyter-config-data": {
"disabledExtensions": [
"@jupyterlite/javascript-kernel-extension",
"@jupyterlite/pyolite-kernel-extension"
]
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyterlite/contents": "^0.1.0-beta.12",
"@jupyterlite/server": "^0.1.0-beta.12",
"@jupyterlite/contents": "^0.1.0-beta.16",
"@jupyterlite/server": "^0.1.0-beta.16",
"comlink": "^4.3.1"
},
"devDependencies": {
Expand Down
26 changes: 21 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// Distributed under the terms of the Modified BSD License.

import {
IServiceWorkerRegistrationWrapper,
IServiceWorkerManager,
JupyterLiteServer,
JupyterLiteServerPlugin
} from '@jupyterlite/server';

import { IBroadcastChannelWrapper } from '@jupyterlite/contents';
import { IKernel, IKernelSpecs } from '@jupyterlite/kernel';

import { WebWorkerKernel } from './web_worker_kernel';
Expand All @@ -18,11 +18,13 @@ import logo64 from '!!file-loader?context=.!../style/logos/python-logo-64x64.png
const server_kernel: JupyterLiteServerPlugin<void> = {
id: '@jupyterlite/xeus-python-kernel-extension:kernel',
autoStart: true,
requires: [IKernelSpecs, IServiceWorkerRegistrationWrapper],
requires: [IKernelSpecs],
optional: [IServiceWorkerManager, IBroadcastChannelWrapper],
activate: (
app: JupyterLiteServer,
kernelspecs: IKernelSpecs,
serviceWorkerRegistrationWrapper: IServiceWorkerRegistrationWrapper
serviceWorker?: IServiceWorkerManager,
broadcastChannel?: IBroadcastChannelWrapper
) => {
kernelspecs.register({
spec: {
Expand All @@ -36,9 +38,23 @@ const server_kernel: JupyterLiteServerPlugin<void> = {
}
},
create: async (options: IKernel.IOptions): Promise<IKernel> => {
const mountDrive = !!(
serviceWorker?.enabled && broadcastChannel?.enabled
);

if (mountDrive) {
console.info(
'xeus-python contents will be synced with Jupyter Contents'
);
} else {
console.warn(
'xeus-python contents will NOT be synced with Jupyter Contents'
);
}

return new WebWorkerKernel({
...options,
mountDrive: serviceWorkerRegistrationWrapper.enabled
mountDrive
});
}
});
Expand Down
Loading