index.md 2.56 KB
Newer Older
Amy Qualls's avatar
Amy Qualls committed
1 2 3
---
stage: none
group: unassigned
4
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
Amy Qualls's avatar
Amy Qualls committed
5 6
---

7 8
# Python Development Guidelines

9
GitLab requires Python as a dependency for [reStructuredText](https://docutils.sourceforge.io/rst.html)
10 11 12 13 14 15
markup rendering.

As of GitLab 11.10, we require Python 3.

## Installation

16 17 18
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](https://github.com/pyenv/pyenv). It works and behaves similarly to its counterpart in the
Ruby world: [rbenv](https://github.com/rbenv/rbenv).
19 20 21 22 23

### macOS

To install `pyenv` on macOS, you can use [Homebrew](https://brew.sh/) with:

24
```shell
25 26 27 28 29 30 31
brew install pyenv
```

### Linux

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

32
```shell
33
curl "https://pyenv.run" | bash
34 35
```

David CHALON's avatar
David CHALON committed
36
Alternatively, you may find `pyenv` available as a system package via your distro package manager.
37 38 39 40 41

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

### Shell integration

42
Pyenv installation adds required changes to Bash. If you use a different shell,
43 44
check for any additional steps required for it.

45
For Fish, you can install a plugin for [Fisher](https://github.com/jorgebucaran/fisher):
46

47
```shell
48 49 50 51 52
fisher add fisherman/pyenv
```

Or for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish):

53
```shell
54 55 56 57 58 59
omf install pyenv
```

## Dependency management

While GitLab doesn't directly contain any Python scripts, because we depend on Python to render
60
[reStructuredText](https://docutils.sourceforge.io/rst.html) markup, we need to keep track on dependencies
61 62 63 64 65
on the main project level, so we can run that on our development machines.

Recently, an equivalent to the `Gemfile` and the [Bundler](https://bundler.io/) project has been introduced to Python:
`Pipfile` and [Pipenv](https://pipenv.readthedocs.io/en/latest/).

66
A `Pipfile` with the dependencies now exists in the root folder. To install them, run:
67

68
```shell
69 70 71
pipenv install
```

72
Running this command installs both the required Python version as well as required pip dependencies.
73 74 75

## Use instructions

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

79
```shell
80 81 82
pipenv shell
```

83
After running that command, you can run GitLab on the same shell and it uses the Python and dependencies
84
installed from the `pipenv install` command.