-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
63 lines (43 loc) · 2.03 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
VENV:=.venv
HOST:=0.0.0.0
DEBUG?=true
SHOPPING_API_PORT ?= 8087
export
.DEFAULT_GOAL=help
$(VENV):
virtualenv -p python3 $(VENV)
requires-venv:
@[ -d $(VENV) ] || make install
help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development targets
install: $(VENV) ## Install development dependencies in a virtualenv
$(VENV)/bin/pip install -r requirements/dev.txt
lock: ## Pin latest versions of dependencies compatible with requirements/prod in requirements/lock file
virtualenv -p python3 .tmp-venv
.tmp-venv/bin/pip install -r requirements/prod.txt
.tmp-venv/bin/pip freeze > requirements/lock.txt
rm -rf .tmp-venv
format: requires-venv ## Format code according to project conventions
$(VENV)/bin/isort -l 120 shopping tests
$(VENV)/bin/black --line-length 120 shopping tests
serve: requires-venv ## Start API server in debug mode
$(VENV)/bin/uvicorn --host $(HOST) --port $(SHOPPING_API_PORT) shopping.__main__:api
##@ Validation targets
tests: requires-venv ## Run unit and functional tests
rm -rf tests/output && mkdir tests/output
echo '<h1>Test results</h1><ul><li><a href="coverage">Coverage</a></li><li><a href="results">Results</a></li></ul>' > tests/output/index.html
$(VENV)/bin/python -m pytest -vvv --cov=shopping/ --cov-report=html:tests/output/coverage --cov-fail-under=30 --html=tests/output/results/index.html tests/
lint: requires-venv ## Check code formatting and quality
$(VENV)/bin/isort -l 120 --profile black --check shopping/ tests/
$(VENV)/bin/black --line-length 120 --check shopping/ tests/
$(VENV)/bin/flake8 --max-line-length 120 shopping/ tests/
##@ Docker targets
build:
@docker build -t sylvanld/shopping-api:latest .
start:
@docker run -d --name shopping-api -p 8000:8000 sylvanld/shopping-api:latest
stop:
@docker stop shopping-api && docker rm shopping-api
shell:
@docker exec -it shopping-api sh