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 |