Skip to content
Snippets Groups Projects
README.md 15.19 KiB

GitLab CI template for Python

This project implements a generic GitLab CI template for Python.

It provides several features, usable in different modes (by configuration) following those recommendations

Usage

In order to include this template in your project, add the following to your gitlab-ci.yml:

include:
  - project: 'to-be-continuous/python'
    ref: '1.2.0'
    file: '/templates/gitlab-ci-python.yml'

Global configuration

The Python template uses some global configuration used throughout all jobs.

Name description default value
PYTHON_IMAGE The Docker image used to run Python. It is highly recommended to set the specific version your project needs python:3-slim
PIP_INDEX_URL Python repository url none
PYTHON_PROJECT_DIR Python project root directory .
REQUIREMENTS_FILE Path to requirements file (relative to $PYTHON_PROJECT_DIR) requirements.txt
PIP_OPTS pip extra options none

The cache policy also declares the .cache/pip directory as cached (not to download Python dependencies over and over again).

Default configuration follows this Python project structure

Poetry support

The Python template supports Poetry as packaging and dependency management tool.

If a pyproject.toml and poetry.lock file is detected at the root of your project structure, requirements will automatically be generated from Poetry.

⚠️ as stated in Poetry documentation, You should commit the poetry.lock file to your project repo so that all people working on the project are locked to the same versions of dependencies.

Jobs

Lint jobs

py-pylint job

This job is disabled by default and performs code analysis based on pylint Python lib. It is activated by setting $PYLINT_ENABLED.

It is bound to the build stage, and uses the following variables: