Python Development Guidelines

GitLab requires Python as a dependency for reStructuredText markup rendering.

As of GitLab 11.10, we require Python 3.

Installation

There are several ways of installing python on your system. To be able to use the same version we use in production, we suggest you use pyenv. It works and behave similar to its counterpart in the ruby world: rbenv.

macOS

To install pyenv on macOS, you can use Homebrew with:

brew install pyenv

Linux

To install pyenv on Linux, you can run the command below:

curl https://pyenv.run | bash

Alternatively, you may find pypenv available as a system package via your distro package manager.

You can read more about it in: https://github.com/pyenv/pyenv-installer#prerequisites.

Shell integration

Pyenv installation will add required changes to Bash. If you use a different shell, check for any additional steps required for it.

For Fish, you can install a plugin for Fisher:

fisher add fisherman/pyenv

Or for Oh My Fish:

omf install pyenv

Dependency management

While GitLab doesn’t directly contain any Python scripts, because we depend on Python to render reStructuredText markup, we need to keep track on dependencies on the main project level, so we can run that on our development machines.

Recently, an equivalent to the Gemfile and the Bundler project has been introduced to Python: Pipfile and Pipenv.

You will now find a Pipfile with the dependencies in the root folder. To install them, run:

pipenv install

Running this command will install both the required Python version as well as required pip dependencies.

Use instructions

To run any python code under the Pipenv environment, you need to first start a virtualenv based on the dependencies of the application. With Pipenv, this is a simple as running:

pipenv shell

After running that command, you can run GitLab on the same shell and it will be using the Python and dependencies installed from the pipenv install command.