π οΈ MakefileΒΆ
Why Makefiles?ΒΆ
Weβre using Makefiles in our projects because we want to have a clear & simple interface for all common actions. This interface is used for:
Preparing the local development environment
Running local tasks during the development
Running the same tasks in CI/CD pipelines
There might be alternative solutions out there, but Makefiles and make
do the job just fine and theyβre widely accepted. Makefiles can get messy, but all of our Makefiles are and will always be simple.
Important
It is important that tasks in the CI/CD pipelines are executed similar to the tasks executed locally (e.g. for testing), thus the unified interface. Most of the GitLab CI files use exactly these Makefiles.
Common targetsΒΆ
Usually most of our projects include Makefiles which use common targets.
Prepare development environmentΒΆ
Preparing the development environment for most of our Python projects & packages is quite similar and looks like this:
make venv
source .venv/bin/activate
make develop
Clean targetsΒΆ
Target |
Usage |
---|---|
|
Clean all downloaded & built files |
|
Clean cache files, e.g. Pythonβs |
|
Clean test (configuration) files |
|
Clean built files, e.g. the |
|
Clean the Python venv |
Install targetsΒΆ
Target |
Usage |
---|---|
|
Create a Python venv |
|
Install the project or package for development (incl. all dev requirements) |
|
Install the Python dependencies for the project or package for development |
|
Install the Node dependencies for the project or package for development |
|
Install the project or package |
Hint
You can also install dependent Python packages locally without depending on the PyPi Server. Simply clone the Git repository of the dependent Python package and use one of the following commands while the projectβs Python venv is active:
# Install Python package for the use in a project.
make -C {local Git repository} install
# Develop on a Python package while in use in a project (i.e. library development).
make -C {local Git repository} develop
Hint
In case youβre not in our private networks, installing PyPi packages might fail because our PyPi Server is not available publicly. In this case, you can often overwrite the PYPI_INDEX
like this:
make develop PYPI_INDEX=https://pypi-public.confirm.ch
Development targetsΒΆ
Target |
Usage |
---|---|
|
Fix the Python imports via isort |
|
Run the development server, e.g. Django runserver |
|
Run the database migrations, e.g. Django migrations |
Test targetsΒΆ
Common test targets:
Target |
Usage |
---|---|
|
Run all tests for the project or package |
|
Validate the commits with the help of git-toolsβ Validate Commits |
|
Run the unit tests, e.g. Python unittest |
|
Run vulnerability checks on 3rd-party packages, e.g. pip-audit |
Python test targets:
Target |
Usage |
---|---|
|
Run the isort linter |
|
Run the pycodestyle linter |
|
Run the Pylint linter |
|
Run the Django tests |
|
Show the coverage report, e.g. Coverage.py |
Static files test targets:
Visual regression test targets:
Target |
Usage |
---|---|
|
Run the visual regression tests |
|
Approve the visual regression tests |
|
Open the visual regresion test report |
|
Run the remote server for the visual regression test report |
Build targetsΒΆ
Target |
Usage |
---|---|
|
Build the project or package |
|
Build the Python source distribution |
|
Build the Python wheel binary package |
Documentation targetsΒΆ
Target |
Usage |
---|---|
|
Build the π Documentation |
|
Watch the source and live build the π Documentation on changes |