Skip to content

Instantly share code, notes, and snippets.

@larsyencken
Last active May 23, 2020 08:26
Show Gist options
  • Save larsyencken/71fc694fc6f3f458c94c856c4be52a3f to your computer and use it in GitHub Desktop.
Save larsyencken/71fc694fc6f3f458c94c856c4be52a3f to your computer and use it in GitHub Desktop.
Makefile for Python
#
# defaults.mk
#
# Sensible defaults for any Python project.
#
# You must define variables:
#
# CODE_LOCATIONS - The folders you keep code in, including your tests
# COVERAGE_LIMIT - A number between 0 and 100, your minimum coverage level
#
OK_MSG = \x1b[32m ✔\x1b[0m
SHELL=bash
default: test
test-default: format lint mypy unittest
@echo -e "All tests complete $(OK_MSG)"
format-default: .venv
@echo -n "==> Checking that code is autoformatted with black..."
@.venv/bin/black --check --quiet --exclude '(.venv|vendor)' .
@echo -e "$(OK_MSG)"
lint-default: .venv
@echo -n "==> Running flake8..."
@.venv/bin/flake8 --show-source --statistics $(CODE_LOCATIONS) --exclude=.venv
@echo -e "$(OK_MSG)"
mypy-default: .venv
@echo -n "==> Type checking..."
@.venv/bin/mypy --no-error-summary $(CODE_LOCATIONS)
@echo -e "$(OK_MSG)"
unittest-default: .venv
@echo "==> Running tests..."
@PYTHONPATH=. .venv/bin/pytest $(CODE_LOCATIONS) --cov-report term-missing:skip-covered --cov $(CODE_LOCATIONS) --no-cov-on-fail --cov-fail-under=$(COVERAGE_LIMIT) -W ignore::DeprecationWarning -vv
.venv: requirements.txt test-requirements.txt
@echo "==> Creating virtualenv..."
test -d .venv || python3 -m venv .venv
# build wheels when developing locally
test -z "$$CI" && .venv/bin/pip install -U pip wheel || true
.venv/bin/pip install -r test-requirements.txt
touch .venv
blacken-default: .venv
.venv/bin/black --exclude '(.venv|vendor)' .
clean-default:
rm -rf .venv
watch-default: .venv
.venv/bin/watchmedo -c 'clear; make test' --drop $(CODE_LOCATIONS)
%: %-default
@ true
[flake8]
max-line-length = 88
extend-ignore = E203
ignore = E501
[coverage:report]
show_missing = True
omit =
.venv/*
[mypy-pytest]
ignore_missing_imports = true
-r requirements.txt
pytest
flake8
mypy
watchdog
argh
PyYAML
black
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment