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

7.x: Allow building against JupyterLab 4 #3955

Merged
merged 12 commits into from
Oct 22, 2024
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
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ jobs:
${{ runner.os }}-yarn-
- name: Install dependencies
run: |
python -m pip install jupyterlab~=3.0
python -m pip install jupyterlab~=4.0
python -m pip install jupyter_packaging~=0.7.9
- name: Build the extension
run: |
yarn install --frozen-lockfile
yarn run build
yarn run build:examples
jlpm install --frozen-lockfile
jlpm run build
jlpm run build:examples

# First install the dev jupyterlab_widgets, since it is a dependency
pushd jupyterlab_widgets
Expand All @@ -67,17 +67,17 @@ jobs:
- name: Run JS tests
run: |
pushd packages/base
yarn run test:unit:firefox:headless
jlpm run test:unit:firefox:headless
popd

pushd packages/controls
yarn run test:unit:firefox:headless
jlpm run test:unit:firefox:headless
popd

pushd packages/html-manager
yarn run test:unit:firefox:headless
jlpm run test:unit:firefox:headless
popd

pushd examples/web1
yarn run test:firefox:headless
jlpm run test:firefox:headless
popd
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ index.built.js.map

temp/*

.yarn

tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
12 changes: 3 additions & 9 deletions dev-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ $? -ne 0 ]; then
exit 1
fi

echo -n "Checking JupyterLab (assuming JupyterLab >=3)... "
echo -n "Checking JupyterLab (assuming JupyterLab >=4)... "
jupyter lab --version 2>/dev/null
if [ $? -ne 0 ]; then
echo "no, skipping installation of widgets for jupyterlab"
Expand All @@ -34,18 +34,12 @@ set -e
nbExtFlags="--sys-prefix $1"

echo -n "Installing and building all yarn packages"
yarn install
yarn run build
jlpm install
jlpm run build

echo -n "widgetsnbextension"
cd widgetsnbextension
pip install -v -e .
if [[ "$OSTYPE" == "msys" ]]; then
jupyter nbextension install --overwrite --py $nbExtFlags widgetsnbextension || true
else
jupyter nbextension install --overwrite --py --symlink $nbExtFlags widgetsnbextension || true
fi
jupyter nbextension enable --py $nbExtFlags widgetsnbextension || true
cd ..

if test "$skip_jupyter_lab" != yes; then
Expand Down
10 changes: 5 additions & 5 deletions docs/source/dev_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ To install ipywidgets from git, you will need:
version of the notebook, checkout the appropriate tag.
+ See the
[Compatibility table](https://github.com/jupyter-widgets/ipywidgets#compatibility)

- the latest [JupyterLab release](https://github.com/jupyterlab/jupyterlab/releases)



### Installing With Conda
### Installing With Conda

```bash
conda create -c conda-forge -n ipywidgets yarn notebook
Expand All @@ -41,10 +41,10 @@ Rebuilding after making changes

To build and test changes, run the following commands in the ipywidgets repository root directory, empty your browser's cache, and refresh the page.

yarn run clean
yarn run build
jlpm run clean
jlpm run build

If your changes are confined to one package (for example, just in the widgetsnbextension package), then it may be sufficient to just run `yarn run build` in that specific directory.
If your changes are confined to one package (for example, just in the widgetsnbextension package), then it may be sufficient to just run `jlpm run build` in that specific directory.

Tips and troubleshooting
------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/source/dev_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ git checkout 7.x
git pull origin 7.x
git reset --hard origin/7.x
git clean -fdx
yarn install
yarn run publish
jlpm install
npm publish
```

Lerna will prompt you for version numbers for each of the changed npm packages. Lerna will then change the versions appropriately (including the interdependency versions), commit, tag, and publish the new packages to npm.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/dev_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ To run the Python tests:

To run the Javascript tests in each package directory:

yarn test
jlpm test

This will run the test suite using `karma` with 'debug' level logging.
8 changes: 4 additions & 4 deletions examples/web1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"scripts": {
"build": "webpack",
"clean": "rimraf built",
"test": "npm run test:firefox && npm run test:chrome",
"test:chrome": "npm run test:default",
"test": "jlpm run test:firefox && jlpm run test:chrome",
"test:chrome": "jlpm run test:default",
"test:default": "karma start karma.config.js --log-level debug",
"test:firefox": "npm run test:default -- --browsers Firefox",
"test:firefox:headless": "npm run test:default -- --browsers FirefoxHeadless"
"test:firefox": "jlpm run test:default -- --browsers Firefox",
"test:firefox:headless": "jlpm run test:default -- --browsers FirefoxHeadless"
},
"dependencies": {
"@jupyter-widgets/base": "^4.1.6",
Expand Down
2 changes: 1 addition & 1 deletion examples/web2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"build": "webpack",
"clean": "rimraf built",
"test": "npm run test:default",
"test": "jlpm run test:default",
"test:default": "echo \"No test specified\""
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions examples/web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"author": "IPython",
"main": "lib/index.js",
"scripts": {
"build": "npm run clean && tsc && node scripts/copyfiles.js && webpack",
"build": "jlpm run clean && tsc && node scripts/copyfiles.js && webpack",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo && rimraf built",
"host": "http-server",
"lint": "tslint --project tslint.json --format stylish",
"test": "npm run test:default",
"test": "jlpm run test:default",
"test:default": "echo \"No test specified\""
},
"dependencies": {
"@jupyter-widgets/base": "^4.1.6",
"@jupyter-widgets/controls": "^3.1.7",
"@jupyter-widgets/html-manager": "^0.20.8",
"@jupyterlab/services": "^6.0.0",
"@lumino/widgets": "^1.3.0",
"@jupyterlab/services": "^6 || ^7",
"@lumino/widgets": "^1 || ^2",
"codemirror": "^5.48.0",
"font-awesome": "^4.7.0",
"http-server": "^0.11.1"
Expand All @@ -37,7 +37,7 @@
"rimraf": "^2.6.1",
"style-loader": "^1.1.2",
"tslint": "^5.20.1",
"typescript": "~3.7.4",
"typescript": "~5",
"url-loader": "^3.0.0",
"webpack": "^4.41.5"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"build": "webpack",
"clean": "rimraf built",
"test": "npm run test:default",
"test": "jlpm run test:default",
"test:default": "echo \"No test specified\""
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion ipywidgets/widgets/tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Utility stuff
#-----------------------------------------------------------------------------

from .utils import setup, teardown
from .utils import setup

def f(**kwargs):
pass
Expand Down
2 changes: 1 addition & 1 deletion ipywidgets/widgets/tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from .. import jslink, jsdlink, ToggleButton
from .utils import setup, teardown
from .utils import setup

def test_jslink_args():
with pytest.raises(TypeError):
Expand Down
21 changes: 6 additions & 15 deletions ipywidgets/widgets/tests/test_send_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from traitlets import Bool, Tuple, List

from .utils import setup, teardown, DummyComm
from .utils import setup

from ..widget import Widget

Expand All @@ -12,29 +12,20 @@
# A widget with simple traits
class SimpleWidget(Widget):
a = Bool().tag(sync=True)
b = Tuple(Bool(), Bool(), Bool(), default_value=(False, False, False)).tag(sync=True)
b = Tuple(Bool(), Bool(), Bool(), default_value=(False, False, False)).tag(
sync=True
)
c = List(Bool()).tag(sync=True)


def test_empty_send_state():
w = SimpleWidget()
w.send_state([])
assert w.comm.messages == []


def test_empty_hold_sync():
w = SimpleWidget()
with w.hold_sync():
pass
assert w.comm.messages == []


def test_control():
comm = DummyComm()
Widget.close_all()
w = SimpleWidget()
Widget.handle_control_comm_opened(
comm, dict(metadata={'version': __control_protocol_version__})
)
Widget._handle_control_comm_msg(dict(content=dict(
data={'method': 'request_states'}
)))
assert comm.messages
2 changes: 1 addition & 1 deletion ipywidgets/widgets/tests/test_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from traitlets import Bool, Tuple, List, Instance, CFloat, CInt, Float, Int, TraitError, observe

from .utils import setup, teardown
from .utils import setup

import ipywidgets
from ipywidgets import Widget
Expand Down
16 changes: 7 additions & 9 deletions ipywidgets/widgets/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
NEW_COMM_PACKAGE = False

import ipykernel.comm

import pytest

class DummyComm():
comm_id = 'a-b-c-d'
Expand All @@ -34,18 +34,13 @@ def send(self, *args, **kwargs):
def close(self, *args, **kwargs):
pass

class DummyCommManager():

def unregister_comm(self, comm):
pass


def dummy_create_comm(**kwargs):
return DummyComm()


def dummy_get_comm_manager(**kwargs):
return DummyCommManager()
return {}


_widget_attrs = {}
Expand Down Expand Up @@ -92,8 +87,11 @@ def teardown_test_comm():
setattr(Widget, attr, value)
_widget_attrs.clear()

@pytest.fixture(autouse=True)
def setup():
setup_test_comm()

def teardown():
yield
teardown_test_comm()

def call_method(method, *args, **kwargs):
method(*args, **kwargs)
42 changes: 21 additions & 21 deletions jupyterlab_widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@
"@jupyter-widgets/base": "^4.1.6",
"@jupyter-widgets/controls": "^3.1.7",
"@jupyter-widgets/output": "^4.1.6",
"@jupyterlab/application": "^3.0.0",
"@jupyterlab/docregistry": "^3.0.0",
"@jupyterlab/logconsole": "^3.0.0",
"@jupyterlab/mainmenu": "^3.0.0",
"@jupyterlab/nbformat": "^3.0.0",
"@jupyterlab/notebook": "^3.0.0",
"@jupyterlab/outputarea": "^3.0.0",
"@jupyterlab/rendermime": "^3.0.0",
"@jupyterlab/rendermime-interfaces": "^3.0.0",
"@jupyterlab/services": "^6.0.0",
"@jupyterlab/settingregistry": "^3.0.0",
"@lumino/algorithm": "^1.1.0",
"@lumino/coreutils": "^1.3.0",
"@lumino/disposable": "^1.1.1",
"@lumino/messaging": "^1.2.1",
"@lumino/properties": "^1.1.0",
"@lumino/signaling": "^1.2.0",
"@lumino/widgets": "^1.3.0",
"@jupyterlab/application": "^3 || ^4",
"@jupyterlab/docregistry": "^3 || ^4",
"@jupyterlab/logconsole": "^3 || ^4",
"@jupyterlab/mainmenu": "^3 || ^4",
"@jupyterlab/nbformat": "^3 || ^4",
"@jupyterlab/notebook": "^3 || ^4",
"@jupyterlab/outputarea": "^3 || ^4",
"@jupyterlab/rendermime": "^3 || ^4",
"@jupyterlab/rendermime-interfaces": "^3 || ^4",
"@jupyterlab/services": "^6 || ^7",
"@jupyterlab/settingregistry": "^3 || ^4",
"@lumino/algorithm": "^1 || ^2",
"@lumino/coreutils": "^1 || ^2",
"@lumino/disposable": "^1 || ^2",
"@lumino/messaging": "^1 || ^2",
"@lumino/properties": "^1 || ^2",
"@lumino/signaling": "^1 || ^2",
"@lumino/widgets": "^1 || ^2",
"@types/backbone": "^1.4.1",
"jquery": "^3.1.1",
"semver": "^6.1.1"
},
"devDependencies": {
"@jupyterlab/builder": "^3.0.0",
"@jupyterlab/cells": "^3.0.0",
"@jupyterlab/builder": "^4",
"@jupyterlab/cells": "^3 || ^4",
"@types/semver": "^6.0.1",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
Expand All @@ -85,7 +85,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^1.19.0",
"rimraf": "^3.0.2",
"typescript": "~3.9.0"
"typescript": "~5"
},
"jupyterlab": {
"extension": true,
Expand Down
5 changes: 2 additions & 3 deletions jupyterlab_widgets/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ class WidgetManager extends ManagerBase<Widget> implements IDisposable {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore JupyterLab 4 support
if (this._context.model.setMetadata) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore JupyterLab 4 support
this._context.model.setMetadata('widgets', {
'application/vnd.jupyter.widget-state+json': state,
});
} else {
// @ts-ignore JupyterLab 3 support
this._context.model.metadata.set('widgets', {
'application/vnd.jupyter.widget-state+json' : state
});
Expand Down Expand Up @@ -242,8 +241,8 @@ class WidgetManager extends ManagerBase<Widget> implements IDisposable {
// @ts-ignore JupyterLab 4 support
const widget_md = notebook.getMetadata
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore JupyterLab 4 support
(notebook.getMetadata('widgets') as any)
// @ts-ignore JupyterLab 3 support
: notebook.metadata.get('widgets');
// Restore any widgets from saved state that are not live
if (widget_md && widget_md[WIDGET_STATE_MIMETYPE]) {
Expand Down
Loading
Loading