Skip to content

Commit

Permalink
Specify JupyterLab extension from single JS file (#778)
Browse files Browse the repository at this point in the history
* first try

* yay

* doc update

* automation test

* fixed test

* ts support
  • Loading branch information
akarukappadath authored Feb 15, 2019
1 parent b042d46 commit 41739a2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [{
id: 'example_lab_extension',
autoStart: true,
activate: function(app) {
console.log('JupyterLab extension example_lab_extension is activated!');
console.log(app.commands);
}
}];
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,21 @@ final class NotebookCustomizationSpec extends FreeSpec
}
}
}

"should install user specified lab extensions from a js file" in {
withProject { project => implicit token =>
val exampleLabExtensionFile = ResourceFile("bucket-tests/example_lab_extension.js")
withResourceFileInBucket(project, exampleLabExtensionFile, "text/plain") { exampleLabExtensionBucketPath =>
val clusterRequestWithLabExtension = ClusterRequest(userJupyterExtensionConfig = Some(UserJupyterExtensionConfig(labExtensions = Map("example_lab_extension" -> exampleLabExtensionBucketPath.toUri))))
withNewCluster(project, request = clusterRequestWithLabExtension) { cluster =>
withWebDriver { implicit driver =>
withNewNotebook(cluster) { notebookPage =>
notebookPage.executeCell("!jupyter labextension list").get should include("example_lab_extension")
}
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions docker/jupyter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ RUN apt-get update \
&& pip3 install python-datauri \
&& pip3 install jupyter_contrib_nbextensions \
&& pip3 install jupyter_nbextensions_configurator \
&& pip3 install cookiecutter \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ set -e

if [ -n "$1" ]; then
JUPYTER_EXTENSION=$1
jupyter labextension install $JUPYTER_EXTENSION
if [[ ${JUPYTER_EXTENSION} == *'.js' ]]; then
# use jupyterlab extension template to create an extension using the specified JS file
# see https://github.com/jupyterlab/extension-cookiecutter-js
JUPYTER_EXTENSION_NAME=`basename ${JUPYTER_EXTENSION%%.*}`
cookiecutter --no-input https://github.com/jupyterlab/extension-cookiecutter-js extension_name=${JUPYTER_EXTENSION_NAME}
cp -f ${JUPYTER_EXTENSION} ${JUPYTER_EXTENSION_NAME}/lib/plugin.js
cd ${JUPYTER_EXTENSION_NAME}
jlpm
jupyter labextension install .
elif [[ ${JUPYTER_EXTENSION} == *'.ts' ]]; then
# same as above but in typescript, see https://github.com/jupyterlab/extension-cookiecutter-ts
JUPYTER_EXTENSION_NAME=`basename ${JUPYTER_EXTENSION%%.*}`
cookiecutter --no-input https://github.com/jupyterlab/extension-cookiecutter-ts extension_name=${JUPYTER_EXTENSION_NAME}
cp -f ${JUPYTER_EXTENSION} ${JUPYTER_EXTENSION_NAME}/src/index.ts
cd ${JUPYTER_EXTENSION_NAME}
jlpm
jupyter labextension install .
else
jupyter labextension install $JUPYTER_EXTENSION
fi
fi

2 changes: 1 addition & 1 deletion src/main/resources/swagger/api-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ definitions:
labExtensions:
type: object
description: |
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.
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.
SubsystemStatus:
description: status of a subsystem Leonardo depends on
Expand Down

0 comments on commit 41739a2

Please sign in to comment.