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

Clean all downloaded & built files

clean-cache

Clean cache files, e.g. Python’s *.pyc & __pycache__

clean-test

Clean test (configuration) files

clean-build

Clean built files, e.g. the build/ directory

clean-venv

Clean the Python venv

Install Targets

Target

Usage

venv

Create a Python venv

develop

Install the project or package for development (incl. all dev requirements)

install

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

isort

Fix the Python imports via isort

server

Run the development server, e.g. Django runserver

migrate

Run the database migrations, e.g. Django migrations

Test Targets

Target

Usage

test

Run all tests for the project or package

test-commits

Validate the commits with the help of git-tools’ Validate Commits

test-isort

Run the isort linter

test-pycodestyle

Run the pycodestyle linter

test-pylint

Run the Pylint linter

test-unittest

Run the unit tests, e.g. Python unittest

test-django

Run the Django tests

test-coverage

Show the coverage report, e.g. Coverage.py

Build Targets

Target

Usage

build

Build the project or package

sdist

Build the Python source distribution

wheel

Build the Python wheel binary package

Documentation Targets

Target

Usage

docs

Build the Documentation

autdocs

Watch the source and live build the Documentation on changes