Skip to content

Commit 41739a2

Browse files
Specify JupyterLab extension from single JS file (#778)
* first try * yay * doc update * automation test * fixed test * ts support
1 parent b042d46 commit 41739a2

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = [{
2+
id: 'example_lab_extension',
3+
autoStart: true,
4+
activate: function(app) {
5+
console.log('JupyterLab extension example_lab_extension is activated!');
6+
console.log(app.commands);
7+
}
8+
}];

automation/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/NotebookCustomizationSpec.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,21 @@ final class NotebookCustomizationSpec extends FreeSpec
9292
}
9393
}
9494
}
95+
96+
"should install user specified lab extensions from a js file" in {
97+
withProject { project => implicit token =>
98+
val exampleLabExtensionFile = ResourceFile("bucket-tests/example_lab_extension.js")
99+
withResourceFileInBucket(project, exampleLabExtensionFile, "text/plain") { exampleLabExtensionBucketPath =>
100+
val clusterRequestWithLabExtension = ClusterRequest(userJupyterExtensionConfig = Some(UserJupyterExtensionConfig(labExtensions = Map("example_lab_extension" -> exampleLabExtensionBucketPath.toUri))))
101+
withNewCluster(project, request = clusterRequestWithLabExtension) { cluster =>
102+
withWebDriver { implicit driver =>
103+
withNewNotebook(cluster) { notebookPage =>
104+
notebookPage.executeCell("!jupyter labextension list").get should include("example_lab_extension")
105+
}
106+
}
107+
}
108+
}
109+
}
110+
}
95111
}
96112
}

docker/jupyter/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ RUN apt-get update \
285285
&& pip3 install python-datauri \
286286
&& pip3 install jupyter_contrib_nbextensions \
287287
&& pip3 install jupyter_nbextensions_configurator \
288+
&& pip3 install cookiecutter \
288289
&& apt-get clean \
289290
&& rm -rf /var/lib/apt/lists/*
290291

docker/jupyter/scripts/extension/jupyter_install_lab_extension.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ set -e
55

66
if [ -n "$1" ]; then
77
JUPYTER_EXTENSION=$1
8-
jupyter labextension install $JUPYTER_EXTENSION
8+
if [[ ${JUPYTER_EXTENSION} == *'.js' ]]; then
9+
# use jupyterlab extension template to create an extension using the specified JS file
10+
# see https://github.com/jupyterlab/extension-cookiecutter-js
11+
JUPYTER_EXTENSION_NAME=`basename ${JUPYTER_EXTENSION%%.*}`
12+
cookiecutter --no-input https://github.com/jupyterlab/extension-cookiecutter-js extension_name=${JUPYTER_EXTENSION_NAME}
13+
cp -f ${JUPYTER_EXTENSION} ${JUPYTER_EXTENSION_NAME}/lib/plugin.js
14+
cd ${JUPYTER_EXTENSION_NAME}
15+
jlpm
16+
jupyter labextension install .
17+
elif [[ ${JUPYTER_EXTENSION} == *'.ts' ]]; then
18+
# same as above but in typescript, see https://github.com/jupyterlab/extension-cookiecutter-ts
19+
JUPYTER_EXTENSION_NAME=`basename ${JUPYTER_EXTENSION%%.*}`
20+
cookiecutter --no-input https://github.com/jupyterlab/extension-cookiecutter-ts extension_name=${JUPYTER_EXTENSION_NAME}
21+
cp -f ${JUPYTER_EXTENSION} ${JUPYTER_EXTENSION_NAME}/src/index.ts
22+
cd ${JUPYTER_EXTENSION_NAME}
23+
jlpm
24+
jupyter labextension install .
25+
else
26+
jupyter labextension install $JUPYTER_EXTENSION
27+
fi
928
fi
1029

src/main/resources/swagger/api-docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ definitions:
975975
labExtensions:
976976
type: object
977977
description: |
978-
Optional, map of extension name and lab extension. The extension should be a verified jupyterlab extension that is uploaded to npm (list of public extensions here: https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories), a gzipped tarball made using 'npm pack', a folder structured by 'jlpm build', or a URL to either of the latter.
978+
Optional, map of extension name and lab extension. The extension should be a verified jupyterlab extension that is uploaded to npm (list of public extensions here: https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories), a gzipped tarball made using 'npm pack', a folder structured by 'jlpm build', a JS file to be inserted into an JL extension template (see https://github.com/jupyterlab/extension-cookiecutter-js), or a URL to one of the last three options.
979979
980980
SubsystemStatus:
981981
description: status of a subsystem Leonardo depends on

0 commit comments

Comments
 (0)