debian-mirror-gitlab/doc/development/python_guide/index.md

85 lines
2.6 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
stage: none
group: unassigned
2021-02-22 17:27:13 +05:30
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
2021-01-29 00:20:46 +05:30
---
2019-07-07 11:18:12 +05:30
# Python Development Guidelines
2020-03-13 15:44:24 +05:30
GitLab requires Python as a dependency for [reStructuredText](https://docutils.sourceforge.io/rst.html)
2019-07-07 11:18:12 +05:30
markup rendering.
As of GitLab 11.10, we require Python 3.
## Installation
2019-12-04 20:38:33 +05:30
There are several ways of installing Python on your system. To be able to use the same version we use in production,
2021-03-11 19:13:27 +05:30
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).
2019-07-07 11:18:12 +05:30
### macOS
To install `pyenv` on macOS, you can use [Homebrew](https://brew.sh/) with:
2020-03-13 15:44:24 +05:30
```shell
2019-07-07 11:18:12 +05:30
brew install pyenv
```
### Linux
To install `pyenv` on Linux, you can run the command below:
2020-03-13 15:44:24 +05:30
```shell
2021-02-22 17:27:13 +05:30
curl "https://pyenv.run" | bash
2019-07-07 11:18:12 +05:30
```
2021-02-22 17:27:13 +05:30
Alternatively, you may find `pyenv` available as a system package via your distribution's package manager.
2019-07-07 11:18:12 +05:30
2021-03-11 19:13:27 +05:30
You can read more about it in [the `pyenv` prerequisites](https://github.com/pyenv/pyenv-installer#prerequisites).
2019-07-07 11:18:12 +05:30
### Shell integration
2021-03-11 19:13:27 +05:30
`Pyenv` installation adds required changes to Bash. If you use a different shell,
2019-07-07 11:18:12 +05:30
check for any additional steps required for it.
2019-09-30 21:07:59 +05:30
For Fish, you can install a plugin for [Fisher](https://github.com/jorgebucaran/fisher):
2019-07-07 11:18:12 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-07-07 11:18:12 +05:30
fisher add fisherman/pyenv
```
Or for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish):
2020-03-13 15:44:24 +05:30
```shell
2019-07-07 11:18:12 +05:30
omf install pyenv
```
## Dependency management
While GitLab doesn't directly contain any Python scripts, because we depend on Python to render
2020-03-13 15:44:24 +05:30
[reStructuredText](https://docutils.sourceforge.io/rst.html) markup, we need to keep track on dependencies
2019-07-07 11:18:12 +05:30
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/).
2021-02-22 17:27:13 +05:30
A `Pipfile` with the dependencies now exists in the root folder. To install them, run:
2019-07-07 11:18:12 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-07-07 11:18:12 +05:30
pipenv install
```
2021-02-22 17:27:13 +05:30
Running this command installs both the required Python version as well as required pip dependencies.
2019-07-07 11:18:12 +05:30
## Use instructions
2019-12-04 20:38:33 +05:30
To run any Python code under the Pipenv environment, you need to first start a `virtualenv` based on the dependencies
2019-07-07 11:18:12 +05:30
of the application. With Pipenv, this is a simple as running:
2020-03-13 15:44:24 +05:30
```shell
2019-07-07 11:18:12 +05:30
pipenv shell
```
2021-02-22 17:27:13 +05:30
After running that command, you can run GitLab on the same shell and it uses the Python and dependencies
2019-07-07 11:18:12 +05:30
installed from the `pipenv install` command.