Skip to main content

JupyterLab viewer for GitLab repositories

Project description

JupyterLab GitLab

A JupyterLab extension for browsing GitLab repositories (in read-only mode).

This extension is based on jupyterlab-github. All credit to the JupyterLab team, and especially Ian Rose, for the github extension!

Thanks as well to Mark Ghiorso for the jupyterlab_gitlab extension where I took some inspiration. It didn't fit my needs (no server extension) so I decided to create my own based on a recent version of jupyterlab-github instead (v0.10.0).

This extension is composed of a Python package named jupyterlab_gitlab for the server extension and a NPM package named jupyterlab-gitlab for the frontend extension.

The purpose of the server extension is to add GitLab credentials that you will need to acquire from https://gitlab.com/profile/personal_access_tokens, and then to proxy your request to GitLab. Note that OAuth2 token are also supported.

Introduction

What this extension is

When you install this extension, an additional filebrowser tab will be added to the left area of JupyterLab. This filebrowser allows you to select GitLab groups and users, browse their repositories, and open the files in those repositories. If those files are notebooks, you can run them just as you would any other notebook. You can also attach a kernel to text files and run those. Basically, you should be able to open any file in a repository that JupyterLab can handle.

WARNING! Subgroups are currently not supported.

Here is a screenshot of the plugin opening this very file on GitLab: gitception

What this extension is not

This is not an extension that provides full GitLab access, such as saving files, making commits, forking repositories, etc.

If you want to use git from JupyterLab, you should look at the jupyterlab-git extension.

Requirements

  • JupyterLab >= 3.0
  • JupyterLab 1.x for version 1.x
  • JupyterLab 2.x for version 2.x
  • JupyterLab 3.x for version 3.x
  • A GitLab account for the server extension

Installation

Install the server and lab extension

For Jupyterlab >= 3.0, both extensions are installed from the Python package:

pip install jupyterlab-gitlab

For Jupyterlab < 3.0, you have to install the server and lab extensions separately:

jupyter labextension install jupyterlab-gitlab
pip install jupyterlab-gitlab

Getting your credentials from GitLab

  1. Go to https://gitlab.com/profile/personal_access_tokens or from GitLab, go to your Settings > Access Tokens.
  2. Under Name, enter a short description, to identify the purpose of this token. I recommend something like: jupyterlab-gitlab.
  3. Under Scopes, check the api scope.
  4. Click Create personal access token. You will see your new personal access token (a 21 characters string). Click on the copy to clipboard icon and and paste it locally in a text file for now. If you have a password manager like 1password, use that.

This is the only time you'll see this token in GitLab. If you lose it, you'll need to create another one.

You should now add the credentials you got from GitLab to your notebook configuration file. Instructions for generating a configuration file can be found here. Once you have identified this file, add the following line to it:

c.GitLabConfig.access_token = "< YOUR_ACCESS_TOKEN >"

where < YOUR_ACCESS_TOKEN > is the string value you obtained above. It can also be an OAuth2 token.

Customization

Customizing the server extension

You saw how to add your access_token to the notebook configuration file. There are other parameters than you can modify using that file. Those are the default values:

c.GitLabConfig.allow_client_side_access_token = False
c.GitLabConfig.url = "https://gitlab.com"
c.GitLabConfig.validate_cert = True

If you run your own GitLab instance for example, update c.GitLabConfig.url to point to it.

Customizing the lab extension

You can set the plugin to start showing a particular repository at launch time. Open the "Advanced Settings" editor in the JupyterLab Settings menu, and under the GitLab settings add

{
  "baseUrl": "https://gitlab.com",
  "defaultRepo": "owner/repository"
}

where owner is the GitLab user or group, and repository is the name of the repository you want to open.

The baseUrl can also be updated to point to your own GitLab instance. If you use the server extension, this url is only used for the Open this repository on GitLab button.

Troubleshoot

If you are seeing the frontend extension, but it is not working, check that the server extension is enabled:

jupyter server extension list

If the server extension is installed and enabled, but you are not seeing the frontend extension, check the frontend extension is installed:

jupyter labextension list

Contributing

Development install

Note: You will need NodeJS to build the extension package.

The jlpm command is JupyterLab's pinned version of yarn that is installed with JupyterLab. You may use yarn or npm in lieu of jlpm below.

# Clone the repo to your local environment
# Change directory to the jupyterlab-gitlab directory
# Install package in development mode
pip install -e .
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the jlpm run build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

jupyter lab build --minimize=False

Uninstall

pip uninstall jupyterlab-gitlab

For JupyterLab < 3, you will also need to run the following command after removing the Python package:

jupyter labextension uninstall jupyterlab-gitlab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterlab_gitlab-3.0.0.tar.gz (138.1 kB view details)

Uploaded Source

Built Distribution

jupyterlab_gitlab-3.0.0-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file jupyterlab_gitlab-3.0.0.tar.gz.

File metadata

  • Download URL: jupyterlab_gitlab-3.0.0.tar.gz
  • Upload date:
  • Size: 138.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.11

File hashes

Hashes for jupyterlab_gitlab-3.0.0.tar.gz
Algorithm Hash digest
SHA256 5b0367b82e3170d8274465285a36be9c331dac5674d9ba7e8e2b5dd4972d64f7
MD5 7f00f35bc6b25de26a1778ccc0fc98b6
BLAKE2b-256 cf26826cdff9b7e7dc8e7e3fd4f3959408614ccc389ab7c6d23b52611a955276

See more details on using hashes here.

File details

Details for the file jupyterlab_gitlab-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: jupyterlab_gitlab-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.11

File hashes

Hashes for jupyterlab_gitlab-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf58a5359843f50cb838f5d21d9232e36494adf16d4fb3a91c868c0f53b4bcf3
MD5 59b92135c28c731c62ee40158f6cf044
BLAKE2b-256 672df7d56ce4f0400debc7a3e8c2c195f1d1e481869149218de4a34cd6793c88

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page