Detect if JupyterLab needs building

In repo2docker we install jupyterlab for users as well as add some extensions. This works well until a repository lists jupyterlab as a dependency in its environment.yml. Then the user is greeted with a message that jupyterlab needs building because of extensions.

An example is https://mybinder.org/v2/gh/alanderex/pydata-pandas-workshop/master?urlpath=lab where we get told we need to build lab because of nbdime and offlinenotebooks.

I think this is because repo2docker installs jupyterlab, then builds extensions and then (later) updates jupyterlab because it is mentioned in the environment.yml.

Is there a command-line tool we could run as part of repo2docker after installing all the user specified packages to detect if lab needs rebuilding?

1 Like

@betatim The command jupyter labextension list will tell you whether a build is recommended. I don’t think there is any way to determine it based on return code, but the stdout will say Build recommended, please run `jupyter lab build`

There is also probably a way to determine it via python by importing jupyterlab, but I haven’t thought it through.

1 Like

Thanks! Shell commands that are not too fragile to parse via grep are Ok, though more robust is always better :smiley:

What do you think of adding something like this to repo2docker as a built in step?

I think that makes good sense! Unfortunately builds are still kind of expensive, but maybe it’s not too bad.

Took a closer look at the python approach. The build_check function returns a list of stale extensions, so something like this might be more robust than the grep approach:

from jupyterlab.commands import build, build_check
if len(build_check()) != 0:
    build()

Nods. Even better would be not to need builds but in the mean time it seems better to do the build (if needed) at “image build time” instead of each time the user starts the image.