Most users of renku are familiar with the JupyterLab interface - it is
widely used and usually the default for most renku projects. However, for
daily work, the notebook environment leaves quite a lot to be desired, and
especially those who are used to working within an IDE or a more powerful
editor of some kind feel frustrated with the limited functionality of JupyterLab.
Luckily there is an easy solution! Visual Studio Code (VSCode) is quite a
popular editor gaining lots of traction also among those who like to work with
notebooks. It offers an excellent editor with some IDE capabilities and is very
customizable via its extension system. These extensions include a Python
extension with some very nice
features for debugging, formatting, linting, etc. In addition, it allows you to
designate sections of python scripts as cells and execute them interactively,
or to simply run Jupyter notebooks directly from the editor. I highly recomment
that you check it out if you spend a lot of time writing code in interactive sessions.
Installing VSCode in your interactive sessions
To enable VSCode in your renkulab sessions, you need to modify your Dockerfile
slightly. If you are using a recent template, your Dockerfile
will look
something like this
ARG RENKU_BASE_IMAGE=renku/renkulab-py:3.7-0.7.3
FROM ${RENKU_BASE_IMAGE}
...
To add VSCode, simply add these lines below FROM ${RENKU_BASE_IMAGE}
:
RUN curl -s https://raw.githubusercontent.com/SwissDataScienceCenter/renkulab-docker/master/scripts/install-vscode.sh | bash
This will run a script that installs VSCode and a few additional components
needed to make it play nice with the Jupyter notebook server.
Once you push this change, your image will be built by renkulab and once it is
ready you can launch a new interactive session as normal. However, you will
notice that you have a new launcher icon in your JupyterLab session:
You can click the icon to go to VSCode. This is now a fully-functional VSCode
session, running inside your interactive session. You can use it like you would
use VSCode on your own computer with the Python extension pre-installed.
The extension allows you to execute .py
files “cell” by cell,
run Jupyter notebooks
or use the fully-featured debugger
Using this functionality on RenkuLab is fairly new and not very thoroughly tested, so
please report back if you run into problems or (even better) come up with interesting
use-cases!
Python extension issues
The Python extension, as amazing as it is, seems to be somewhat unstable. That is why a specific version is installed by the installation script - if you update the Python extension it most likely will no longer work. If you do update and it works - let us know! We can update the script accordingly. Because of these problems, automatically updating extensions is also disabled by the install script.
Installing extensions
Because your VSCode session is spawned from your Docker image, the extensions that you install “on-the-fly” (e.g. by using the extensions marketplace within VSCode) will not persist the next time you start up a session. To install them permanently, you need to do it through the Dockerfile
. The easiest way is to find the extension you want in the VSCode marketplace and look up its identifier - e.g. here is the GitHub Pull Requests extension with its identifier:
In your Dockerfile
, after the line that installs VSCode, you would add a line like
RUN code-server --install-extension GitHub.vscode-pull-request-github
Now, the next time you start a fresh session, this extension will be pre-installed for you. Note that not all VSCode extensions are available for code-server, but most of them should be.
Changing the VSCode version
If, for some reason, you want to install a specific version of VSCode, you can do so by adding
an environment variable to your Dockerfile
before the VSCode installation script is called.
You can look up a code-server release and add
the version to your Dockerfile
like this:
ENV VSCODE_VERSION=3.8.0