-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
101 lines (69 loc) · 2.28 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This Makefile requires the following commands to be available:
# * python3.9
# * pip
# * docker
# * poetry
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MAKEFILE_DIR := $(shell dirname $(MAKEFILE_PATH))
IMAGE=bday-reminder-api
PYTHON=python3.9
export PYTHONPATH=$(shell echo $(MAKEFILE_DIR))/src
RUN_WITH_PYTHON_PATH=
# When we are not in Docker we assume poetry usage
ifneq ($(IN_DOCKER), 1)
RUN_WITH_PYTHON_PATH=poetry run
endif
run:
$(RUN_WITH_PYTHON_PATH) $(PYTHON) src/manage.py runserver
# migrate on dev environment
.PHONY: migrate
migrate:
$(RUN_WITH_PYTHON_PATH) $(PYTHON) src/manage.py migrate --noinput
@echo 'migrate done!'
# ********** Static files **********
collectstatic:
$(RUN_WITH_PYTHON_PATH) $(PYTHON) src/manage.py collectstatic --noinput
@echo 'collectstatic done!'
# ********** Docker **********
docker/build/%:
docker build --no-cache -t $(IMAGE):$* .
docker/run: requirements.txt docker/build/dev
docker run --rm -p 8000:8000 -e DEBUG=true $(IMAGE):dev
# ****** Tests ******
.PHONY: prepare_dev_packages
test_local: prepare_dev_packages lint pytest
@echo 'Tests are done!'
ifneq ($(IN_DOCKER), 1)
prepare_dev_packages:
@poetry install
else
prepare_dev_packages:
# install globally since we are in docker
pip install -r requirements.dev.txt
endif
pytest:
$(RUN_WITH_PYTHON_PATH) py.test src/tests -svv --cov-report=term-missing --cov-report=html --cov-report=xml --cov=src --tb=short
# ********** Code style **********
.PHONY: lint lint/isort lint/flake8 lint/black format format/isort format/black
lint: lint/flake8 lint/isort lint/black
lint/isort:
$(RUN_WITH_PYTHON_PATH) isort -c src
lint/flake8:
$(RUN_WITH_PYTHON_PATH) flake8 src
lint/black:
$(RUN_WITH_PYTHON_PATH) black --check src
format: format/isort format/black
format/isort:
$(RUN_WITH_PYTHON_PATH) isort src
format/black:
$(RUN_WITH_PYTHON_PATH) black --verbose src
# ********** Requirements **********
.PHONY: requirements.txt requirements.dev.txt
requirements: requirements.dev.txt requirements.txt
requirements.txt: poetry.lock
@poetry export -f requirements.txt --output requirements.txt
requirements.dev.txt: poetry.lock
poetry export --dev -f requirements.txt --output requirements.dev.txt
# Helper for docker build
install_requirements_txt:
pip install -r requirements.txt