Skip to content

Commit bc27465

Browse files
authored
Merge pull request #350 from agoose77/jlab-3-light
Feature: JupyterLab 3.0 Support Cleanup
2 parents 5857d54 + 761a513 commit bc27465

File tree

8 files changed

+68
-37
lines changed

8 files changed

+68
-37
lines changed

MANIFEST.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ recursive-include pythreejs/static *.*
22

33
include setupbase.py
44

5-
include LICENSE
6-
include README.md
75
include pytest.ini
86
include screencast.gif
97

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,8 @@ jupyter nbextension install --py --symlink --sys-prefix pythreejs
7474
# To clean out generated files, run:
7575
npm run clean
7676

77+
# To symlink the jupyter lab extension
78+
jupyter labextension develop .. --overwrite
79+
80+
7781
```

install.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageManager": "python",
3+
"packageName": "pythreejs",
4+
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package pythreejs"
5+
}

js/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@
2626
"build:all": "npm run build:labextension",
2727
"build:bundles": "webpack -d && node ./scripts/post-build.js --debug",
2828
"build:bundles-prod": "webpack -p && node ./scripts/post-build.js",
29-
"build:labextension": "rimraf lab-dist && mkdirp lab-dist && cd lab-dist && npm pack ..",
29+
"build:labextension": "rimraf lab-dist && mkdirp lab-dist && cd lab-dist && npm pack .. && cd .. && jupyter labextension build .",
3030
"clean": "rimraf dist && rimraf ../pythreejs/static && rimraf lab-dist && node ./scripts/clean-generated-files.js",
3131
"prepack": "npm run build:bundles-prod",
3232
"prepare": "npm run autogen",
3333
"update:deps": "update-dependency --minimal --regex \"^(?!@jupyter-widgets|three)\"",
3434
"watch": "webpack -d -w"
3535
},
3636
"dependencies": {
37-
"@jupyter-widgets/base": "^1.2.5 || ^2.0.0 || ^3.0.0",
37+
"@jupyter-widgets/base": "^1.2.5 || ^2.0.0 || ^3.0.0 || ^4.0.0",
3838
"bluebird": "^3.5.5",
3939
"jupyter-dataserializers": "^2.2.0",
4040
"three": "^0.97.0",
4141
"underscore": "^1.8.3"
4242
},
4343
"devDependencies": {
44+
"@jupyterlab/builder": "^3.0.0",
4445
"@jupyterlab/buildutils": "^2.0.2",
4546
"eslint": "^6.8.0",
4647
"fs-extra": "^8.1.0",
@@ -53,6 +54,13 @@
5354
},
5455
"jupyterlab": {
5556
"extension": "src/jupyterlab-plugin",
57+
"outputDir": "../pythreejs/labextension",
58+
"sharedPackages": {
59+
"@jupyter-widgets/base": {
60+
"bundled": false,
61+
"singleton": true
62+
}
63+
},
5664
"discovery": {
5765
"kernel": [
5866
{

js/scripts/templates/py_top_level_init.mustache

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ from __future__ import absolute_import
88
from {{ module.pyRelativePath }} import *
99
{{/each}}
1010

11+
12+
def _prefix():
13+
import sys
14+
from pathlib import Path
15+
prefix = sys.prefix
16+
here = Path(__file__).parent
17+
# for when in dev mode
18+
if (here.parent / 'setup.py').exists():
19+
prefix = here.parent
20+
return prefix
21+
22+
23+
def _jupyter_labextension_paths():
24+
return [{
25+
'src': f'{_prefix()}/share/jupyter/labextensions/{npm_pkg_name}/',
26+
'dest': f'{npm_pkg_name}',
27+
}]
28+
29+
1130
def _jupyter_nbextension_paths():
1231
return [{
1332
'section': 'notebook',

js/src/jupyterlab-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
console.error(err);
2020
reject(err);
2121
},
22-
'jupyter-threejs'
22+
'jupyter-threejs-chunk'
2323
);
2424
});
2525
}

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["jupyterlab~=3.0", "setuptools>=40.8.0", "wheel"]
3+
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
3-
from __future__ import print_function
4-
import os
5-
import sys
2+
from pathlib import Path
63

74
from setupbase import (
85
log,
@@ -12,50 +9,45 @@
129
ensure_targets,
1310
get_version,
1411
)
15-
16-
from setuptools import setup
12+
import setuptools
1713

1814

19-
log.set_verbosity(log.DEBUG)
20-
log.info('setup.py entered')
21-
log.info('$PATH=%s' % os.environ['PATH'])
22-
2315
LONG_DESCRIPTION = 'A Python/ThreeJS bridge utilizing the Jupyter widget infrastructure.'
2416

25-
here = os.path.abspath(os.path.dirname(sys.argv[0]))
17+
HERE = Path(__file__).parent.resolve()
2618
name = 'pythreejs'
27-
version = get_version(os.path.join(here, name, '_version.py'))
19+
py_path = (HERE / name)
20+
js_path = (HERE / "js")
21+
lab_path = (py_path / "labextension")
2822

23+
version = get_version(HERE / name / '_version.py')
2924

3025
cmdclass = create_cmdclass(
3126
'js',
3227
data_files_spec=[
33-
('share/jupyter/nbextensions/jupyter-threejs',
34-
name + '/static',
35-
'*.js'),
36-
('share/jupyter/nbextensions/jupyter-threejs',
37-
name + '/static',
38-
'*.js.map'),
39-
('share/jupyter/lab/extensions',
40-
'js/lab-dist',
41-
'jupyter-threejs-*.tgz'),
42-
('etc/jupyter/nbconfig',
43-
'jupyter-config',
44-
'**/*.json'),
28+
# Support JupyterLab 3.x prebuilt extension
29+
("share/jupyter/labextensions/jupyter-threejs", str(lab_path), "**"),
30+
("share/jupyter/labextensions/jupyter-threejs", str(HERE), "install.json"),
31+
# Support JupyterLab 2.x
32+
('share/jupyter/lab/extensions', str(js_path/'lab-dist'), 'jupyter-threejs-*.tgz'),
33+
# Support Jupyter Notebook
34+
('etc/jupyter/nbconfig', str(HERE/'jupyter-config'), '**/*.json'),
35+
('share/jupyter/nbextensions/jupyter-threejs', str(py_path/'static'), '**/*.js'),
36+
('share/jupyter/nbextensions/jupyter-threejs', str(py_path/'static'), '**/*.js.map')
4537
],
4638
)
4739
cmdclass['js'] = combine_commands(
4840
install_npm(
49-
path=os.path.join(here, 'js'),
50-
build_dir=os.path.join(here, name, 'static'),
51-
source_dir=os.path.join(here, 'js'),
41+
path=str(js_path),
42+
build_dir=str(py_path/'static'),
43+
source_dir=str(js_path),
5244
build_cmd='build:all'
5345
),
5446
ensure_targets([
55-
name + '/static/extension.js',
56-
name + '/static/index.js',
57-
'js/src/core/BufferAttribute.autogen.js',
58-
name + '/core/BufferAttribute_autogen.py',
47+
str(py_path/'static'/'extension.js'),
48+
str(py_path/'static'/'index.js'),
49+
str(js_path/'src'/'core'/'BufferAttribute.autogen.js'),
50+
str(py_path/'core'/'BufferAttribute_autogen.py'),
5951
]),
6052
)
6153

@@ -109,4 +101,6 @@
109101
],
110102
}
111103

112-
setup(**setup_args)
104+
105+
if __name__ == "__main__":
106+
setuptools.setup(**setup_args)

0 commit comments

Comments
 (0)