Skip to content

Feature/594 add linting for python code to ci cd

What does this MR do and why?

Fixes #595 (closed)

Adds flake8 linting as a first stage in the gitlab ci, meaning none of the other stages run if the linting fails. This should save CI minutes by not building/testing broken code and gives an extra check for external contributors (who might not have the pre-commit hooks set up)

I used tox for the configuration, because it allows you to easily run the linting locally in the same setup as it runs in the CI (in a virtual environment with the same python version, with pinned versions for the linting tools, and with the same arguments). It actually helped me pick up on an issue that flake8 does report errors when you run it in python 3.12, that it does not report when ran with python 3.11.

I think using tox for testing/linting configuration will also be useful for the other tasks in &2.

How to set up and validate locally

# install tox manually
pip install tox 
# or install it via the new 'lint' requirements
pip install -e .[lint]
# simple version
tox
# list all test environments
tox -l
# run specific linting environment
tox -e py311-lint 

Note that this requires tox to be able to find a python 3.11 interpreter in whatever environment you are running tox

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • Includes tests for added/modified code
  • Added or modified the documentation if relevant
  • Docstrings added/modified for new/modified functions
  • Committer/reviewer has ran the documentation stage when ready to merge
Edited by Miron van der Kolk

Merge request reports