Skip to content

Commit e07d534

Browse files
authored
Merge pull request #90 from ianhi/jlab-3
Update for Jlab 3
2 parents 78716a6 + 2a5dd88 commit e07d534

File tree

14 files changed

+153
-796
lines changed

14 files changed

+153
-796
lines changed

.github/workflows/build.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
cookiecutter . --config-file tests/testconfig.yaml --no-input
5757
pushd jupyter-widget-testwidgets
5858
python -m pip install --upgrade -v -e ".[test, examples, docs]"
59-
npm run lint:check
59+
yarn run lint:check
6060
6161
# TODO: re-enable tests
6262
# pytest
@@ -74,11 +74,14 @@ jobs:
7474
pip uninstall -y jupyter_widget_testwidgets
7575
cd jupyter-widget-testwidgets
7676
pip install .
77-
jupyter nbextension enable --py --sys-prefix jupyter_widget_testwidgets
77+
7878
# Validate nbextension (enable does not use exit code):
79+
jupyter nbextension enable --py --sys-prefix jupyter_widget_testwidgets
7980
python -c "from notebook.nbextensions import validate_nbextension; import sys; sys.exit(validate_nbextension('jupyter_widget_testwidgets/extension') or 0)"
80-
pip install jupyterlab
81+
82+
# Validate labextension
83+
pip install -U jupyterlab~=3.0 jupyter_packaging~=0.7
8184
# Make sure our lab extension was installed.
8285
jupyter labextension list 2>&1 | grep -ie "jupyter-widget-testwidgets.*OK"
83-
# Make sure our lab extension can be linked.
84-
jupyter labextension link
86+
# Make sure our lab extension can be develop installed.
87+
jupyter labextension develop . --overwrite

README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ After this, you will have a directory containing files used for creating a
3939
custom Jupyter widget. To check that eveything is set up as it should be,
4040
you should run the tests:
4141

42+
Create a dev environment:
43+
```bash
44+
conda create -n {{ cookiecutter.python_package_name }}-dev -c conda-forge nodejs yarn python jupyterlab
45+
conda activate {{ cookiecutter.python_package_name }}-dev
46+
```
47+
48+
Install the python. This will also build the TS package.
49+
4250
```bash
4351
# First install the python package. This will also build the JS packages.
4452
pip install -e ".[test, examples]"
@@ -47,15 +55,15 @@ pip install -e ".[test, examples]"
4755
py.test
4856

4957
# Run the JS tests. This should again, only give TODO errors (Expected 'Value' to equal 'Expected value'):
50-
npm test
58+
yarn test
5159
```
5260

5361
When developing your extensions, you need to manually enable your extensions with the
5462
notebook / lab frontend. For lab, this is done by the command:
5563

5664
```
57-
jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
58-
jupyter labextension install .
65+
jupyter labextension develop --overwrite .
66+
yarn run build
5967
```
6068

6169
For classic notebook, you can run:
@@ -71,6 +79,23 @@ you might also need another flag instead of `--sys-prefix`, but we won't cover t
7179
of those flags here.
7280

7381

82+
### How to see your changes
83+
#### Typescript:
84+
If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different
85+
terminals to watch for changes in the extension's source and automatically rebuild the widget.
86+
87+
```bash
88+
# Watch the source directory in one terminal, automatically rebuilding when needed
89+
yarn run watch
90+
# Run JupyterLab in another terminal
91+
jupyter lab
92+
```
93+
94+
After a change wait for the build to finish and then refresh your browser and the changes should take effect.
95+
96+
#### Python:
97+
If you make a change to the python code then you will need to restart the notebook kernel to have it take effect.
98+
7499
## Releasing your initial packages:
75100

76101
- Add tests

{{cookiecutter.github_project_name}}/.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
- name: Test the extension
5050
run: |
5151
python -m pip install --upgrade -v -e ".[test, examples, docs]"
52-
npm run lint:check
52+
yarn run lint:check
5353
pytest
54-
npm run test:ci
54+
yarn run test:ci
5555
- name: Check docs can be build + links
5656
run: |
5757
pushd docs

{{cookiecutter.github_project_name}}/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ $RECYCLE.BIN/
145145
# ----
146146

147147
**/node_modules/
148-
{{ cookiecutter.python_package_name }}/nbextension/static/index.*
148+
{{ cookiecutter.python_package_name }}/nbextension/index.*
149149
{{ cookiecutter.python_package_name }}/labextension/*.tgz
150150

151151
# Coverage data

{{cookiecutter.github_project_name}}/README.md

+18-19
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,37 @@
1212
You can install using `pip`:
1313

1414
```bash
15-
pip install {{ cookiecutter.python_package_name }}
16-
```
17-
18-
Or if you use jupyterlab:
19-
20-
```bash
21-
pip install {{ cookiecutter.python_package_name }}
22-
jupyter labextension install @jupyter-widgets/jupyterlab-manager
15+
pip install {{ cookiecutter.python_package_name }}
2316
```
2417

2518
If you are using Jupyter Notebook 5.2 or earlier, you may also need to enable
2619
the nbextension:
2720
```bash
28-
jupyter nbextension enable --py [--sys-prefix|--user|--system] {{ cookiecutter.python_package_name }}
21+
jupyter nbextension enable --py [--sys-prefix|--user|--system] {{ cookiecutter.python_package_name }}
2922
```
3023

3124
## Development Installation
3225

26+
Create a dev environment:
27+
```bash
28+
conda create -n {{ cookiecutter.python_package_name }}-dev -c conda-forge nodejs yarn python jupyterlab
29+
conda activate {{ cookiecutter.python_package_name }}-dev
30+
```
3331

32+
Install the python. This will also build the TS package.
3433
```bash
35-
# First install the python package. This will also build the JS packages.
3634
pip install -e ".[test, examples]"
3735
```
3836

3937
When developing your extensions, you need to manually enable your extensions with the
4038
notebook / lab frontend. For lab, this is done by the command:
4139

4240
```
43-
jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
44-
jupyter labextension install .
41+
jupyter labextension develop --overwrite .
42+
yarn run build
4543
```
4644

47-
For classic notebook, you can run:
45+
For classic notebook, you need to run:
4846

4947
```
5048
jupyter nbextension install --sys-prefix --symlink --overwrite --py {{ cookiecutter.python_package_name }}
@@ -58,13 +56,14 @@ of those flags here.
5856

5957
### How to see your changes
6058
#### Typescript:
61-
To continuously monitor the project for changes and automatically trigger a rebuild, start Jupyter in watch mode:
62-
```bash
63-
jupyter lab --watch
64-
```
65-
And in a separate session, begin watching the source directory for changes:
59+
If you use JupyterLab to develop then you can watch the source directory and run JupyterLab at the same time in different
60+
terminals to watch for changes in the extension's source and automatically rebuild the widget.
61+
6662
```bash
67-
npm run watch
63+
# Watch the source directory in one terminal, automatically rebuilding when needed
64+
yarn run watch
65+
# Run JupyterLab in another terminal
66+
jupyter lab
6867
```
6968

7069
After a change wait for the build to finish and then refresh your browser and the changes should take effect.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageManager": "python",
3+
"packageName": "{{ cookiecutter.python_package_name }}",
4+
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package {{ cookiecutter.python_package_name }}"
5+
}

{{cookiecutter.github_project_name}}/package.json

+21-12
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@
2929
"url": "https://github.com/{{ cookiecutter.github_organization_name }}/{{ cookiecutter.github_project_name }}"
3030
},
3131
"scripts": {
32-
"build": "npm run build:lib && npm run build:nbextension",
33-
"build:labextension": "npm run clean:labextension && mkdirp {{ cookiecutter.python_package_name }}/labextension && cd {{ cookiecutter.python_package_name }}/labextension && npm pack ../..",
32+
"build": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension:dev",
33+
"build:prod": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension",
34+
"build:labextension": "jupyter labextension build .",
35+
"build:labextension:dev": "jupyter labextension build --development True .",
3436
"build:lib": "tsc",
35-
"build:nbextension": "webpack -p",
36-
"build:all": "npm run build:labextension && npm run build:nbextension",
37-
"clean": "npm run clean:lib && npm run clean:nbextension",
37+
"build:nbextension": "webpack",
38+
"clean": "yarn run clean:lib && yarn run clean:nbextension && yarn run clean:labextension",
3839
"clean:lib": "rimraf lib",
3940
"clean:labextension": "rimraf {{ cookiecutter.python_package_name }}/labextension",
4041
"clean:nbextension": "rimraf {{ cookiecutter.python_package_name }}/nbextension/static/index.js",
4142
"lint": "eslint . --ext .ts,.tsx --fix",
4243
"lint:check": "eslint . --ext .ts,.tsx",
43-
"prepack": "npm run build:lib",
44-
"test": "npm run test:firefox",
44+
"prepack": "yarn run build:lib",
45+
"test": "yarn run test:firefox",
4546
"test:chrome": "karma start --browsers=Chrome tests/karma.conf.js",
4647
"test:debug": "karma start --browsers=Chrome --singleRun=false --debug=true tests/karma.conf.js",
4748
"test:firefox": "karma start --browsers=Firefox tests/karma.conf.js",
@@ -51,9 +52,10 @@
5152
"watch:nbextension": "webpack --watch"
5253
},
5354
"dependencies": {
54-
"@jupyter-widgets/base": "^1.1.10 || ^2 || ^3"
55+
"@jupyter-widgets/base": "^1.1.10 || ^2 || ^3 || ^4"
5556
},
5657
"devDependencies": {
58+
"@jupyterlab/builder": "^3.0.0",
5759
"@phosphor/application": "^1.6.0",
5860
"@phosphor/widgets": "^1.6.0",
5961
"@types/expect.js": "^0.3.29",
@@ -85,11 +87,18 @@
8587
"source-map-loader": "^0.2.4",
8688
"style-loader": "^1.0.0",
8789
"ts-loader": "^5.2.1",
88-
"typescript": "~3.8",
89-
"webpack": "^4.20.2",
90-
"webpack-cli": "^3.1.2"
90+
"typescript": "~4.1.3",
91+
"webpack": "^5",
92+
"webpack-cli": "^4"
9193
},
9294
"jupyterlab": {
93-
"extension": "lib/plugin"
95+
"extension": "lib/plugin",
96+
"outputDir": "{{ cookiecutter.python_package_name }}/labextension/",
97+
"sharedPackages": {
98+
"@jupyter-widgets/base": {
99+
"bundled": false,
100+
"singleton": true
101+
}
102+
}
94103
}
95104
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["jupyter_packaging==0.7.9", "jupyterlab==3.*", "setuptools>=40.8.0", "wheel"]
3+
build-backend = "setuptools.build_meta"

{{cookiecutter.github_project_name}}/setup.py

+23-19
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,58 @@
66

77
from __future__ import print_function
88
from glob import glob
9+
import os
910
from os.path import join as pjoin
11+
from setuptools import setup, find_packages
1012

1113

12-
from setupbase import (
13-
create_cmdclass, install_npm, ensure_targets,
14-
find_packages, combine_commands, ensure_python,
15-
get_version, HERE
14+
from jupyter_packaging import (
15+
create_cmdclass,
16+
install_npm,
17+
ensure_targets,
18+
combine_commands,
19+
get_version,
1620
)
1721

18-
from setuptools import setup
22+
HERE = os.path.dirname(os.path.abspath(__file__))
23+
24+
1925

2026

2127
# The name of the project
2228
name = '{{ cookiecutter.python_package_name }}'
2329

24-
# Ensure a valid python version
25-
ensure_python('>=3.4')
26-
27-
# Get our version
30+
# Get the version
2831
version = get_version(pjoin(name, '_version.py'))
2932

30-
nb_path = pjoin(HERE, name, 'nbextension', 'static')
31-
lab_path = pjoin(HERE, name, 'labextension')
3233

3334
# Representative files that should exist after a successful build
3435
jstargets = [
35-
pjoin(nb_path, 'index.js'),
36+
pjoin(HERE, name, 'nbextension', 'index.js'),
3637
pjoin(HERE, 'lib', 'plugin.js'),
3738
]
3839

40+
3941
package_data_spec = {
4042
name: [
41-
'nbextension/static/*.*js*',
42-
'labextension/*.tgz'
43+
'nbextension/**js*',
44+
'labextension/**'
4345
]
4446
}
4547

48+
4649
data_files_spec = [
47-
('share/jupyter/nbextensions/{{ cookiecutter.python_package_name}}',
48-
nb_path, '*.js*'),
49-
('share/jupyter/lab/extensions', lab_path, '*.tgz'),
50-
('etc/jupyter/nbconfig/notebook.d' , HERE, '{{ cookiecutter.python_package_name}}.json')
50+
('share/jupyter/nbextensions/{{ cookiecutter.python_package_name }}', '{{ cookiecutter.python_package_name }}/nbextension', '**'),
51+
('share/jupyter/labextensions/{{ cookiecutter.npm_package_name }}', '{{ cookiecutter.python_package_name }}/labextension', '**'),
52+
('share/jupyter/labextensions/{{ cookiecutter.npm_package_name }}', '.', 'install.json'),
53+
('etc/jupyter/nbconfig/notebook.d', '.', '{{ cookiecutter.npm_package_name }}.json'),
5154
]
5255

5356

5457
cmdclass = create_cmdclass('jsdeps', package_data_spec=package_data_spec,
5558
data_files_spec=data_files_spec)
5659
cmdclass['jsdeps'] = combine_commands(
57-
install_npm(HERE, build_cmd='build:all'),
60+
install_npm(HERE, build_cmd='build:prod'),
5861
ensure_targets(jstargets),
5962
)
6063

@@ -85,6 +88,7 @@
8588
'Framework :: Jupyter',
8689
],
8790
include_package_data = True,
91+
python_requires=">=3.6",
8892
install_requires = [
8993
'ipywidgets>=7.0.0',
9094
],

0 commit comments

Comments
 (0)