Makefile 2.17 KB
Newer Older
Gmodena's avatar
Gmodena committed
1
2
# This Makefile provides some boilerplate to run conda-dist,
# test, lint and typechecking targets.
fab's avatar
wip    
fab committed
3
4
5
# A docker image is available to perform all CI steps
# locally, in an enviroment that matches Gitlab's CI container.
#
Gmodena's avatar
Gmodena committed
6
7
8
9
10
11
12
13
14
15
# Example:
#
# $ make docker-conda
# To generate a suitable python3 + miniconda docker image.
#
# $ make env
# pacakges knowledge-gaps in docker and produces a linux x86_64 binary distribution.
#
# $ make env SKIP_DOCKER=true
# Will run the conda-dist command natively.
Gmodena's avatar
Gmodena committed
16
17
18
19
20
21

# Metadata for development cond dist archives.
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT_HASH := $(shell git rev-parse --short=8 HEAD)
# A docker image based atop debian buster and miniconda3.
# It provides the same run-time as Gitlab CI.
Gmodena's avatar
Gmodena committed
22
23
DOCKER_IMG := research/miniconda3
DOCKERFILE := Dockerfile
Gmodena's avatar
Gmodena committed
24
# Generate x86_64 binaries when running docker on non x86 platform (e.g. apple m1).
Gmodena's avatar
Gmodena committed
25
26
DOCKER_PLATFORM := linux/amd64
PROJECT_NAME := knowledge-gaps
Gmodena's avatar
Gmodena committed
27
# Do not modify PROJECT_VERSION manually. Use bump2version instead.
Gmodena's avatar
Gmodena committed
28
PROJECT_VERSION := 0.1.0
Gmodena's avatar
Gmodena committed
29
CONDA_DIST := ./dist/${PROJECT_NAME}-${PROJECT_VERSION}.conda-${GIT_BRANCH}-${GIT_COMMIT_HASH}
Gmodena's avatar
Gmodena committed
30
31
32

REQUIREMENTS_FILE := requirements_dev.txt

Gmodena's avatar
Gmodena committed
33
34
35
36
# Build an x86_64-linux docker image.
docker-conda:
	docker buildx build --platform ${DOCKER_PLATFORM} -t ${DOCKER_IMG} -f ${DOCKERFILE} .

Gmodena's avatar
Gmodena committed
37
38
39
ifneq ($(SKIP_DOCKER),true)
CURRENT_DIR := $(shell pwd)
DOCKER_CMD := docker run -it \
Gmodena's avatar
Gmodena committed
40
41
42
43
44
			  --rm \
			  --platform ${DOCKER_PLATFORM} \
			  -v ${CURRENT_DIR}:/root \
			  -e SKIP_DOCKER=true \
			  -w /root ${DOCKER_IMG}
Gmodena's avatar
Gmodena committed
45

fab's avatar
wip    
fab committed
46
# The research/miniconda3 image is required to run
Gmodena's avatar
Gmodena committed
47
48
49
50
51
52
# CI targets in a docker container.
env: docker-conda
test: docker-conda
lint: docker-conda
typecheck: docker-conda
endif
Gmodena's avatar
Gmodena committed
53

Gmodena's avatar
Gmodena committed
54
55
# Create a conda dist archive, containing this project and all
# its dependencies.
fab's avatar
wip    
fab committed
56
57
58
env:
	${DOCKER_CMD} bash -c "source /opt/conda/etc/profile.d/conda.sh && \
	conda activate && \
fab's avatar
fab committed
59
	conda-dist --dist-env-prefix=${CONDA_DIST}"
Gmodena's avatar
Gmodena committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73

# Run the pytest suite.
test:
	${DOCKER_CMD} bash -c "tox -e pytest"

# Run linting with flake8.
lint:
	${DOCKER_CMD} bash -c "tox -e flake8"

# Run compile time type-checks.
typecheck:
	${DOCKER_CMD} bash -c "tox -e mypy"

.PHONY: docker-conda env test lint typecheck