-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
218 lines (162 loc) · 5.68 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Makefile.
#
# This is intended for convenience.
# All commands should be usable even without make.
# --- Variables
ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
PROJECT := vanadium
PIP_REQ_MAIN := requirements.txt
PIP_REQ_DEV := requirements-dev.txt
DOCKER_TAG := $(PROJECT)
DOCKER_APP := $(PROJECT)-app
DOCKER_HOST := localhost
DOCKER_PORT := 8080
MKDOCS_SITE_PATH := $(ROOT)/build/docs
MKDOCS_SERVER_HOST := localhost
MKDOCS_SERVER_PORT := 8001
MKDOCS_SERVER_ADDRESS := $(MKDOCS_SERVER_HOST):$(MKDOCS_SERVER_PORT)
SERVER_APP_PATH := $(ROOT)
SERVER_APP_NAME := $(PROJECT).app.main:application
SERVER_HOST := 127.0.0.1
SERVER_PORT := 8080
SERVER_MAIN_FLAGS := --host $(SERVER_HOST) --port $(SERVER_PORT) $(SERVER_APP_NAME)
SERVER_TEST_FLAGS := --reload $(SERVER_MAIN_FLAGS)
SERVER_APP_PATH := $(ROOT)
SERVER_APP_ENTRY := $(PROJECT).app.main:application
SERVER_HOST := 127.0.0.1
SERVER_PORT := 8080
# Note: '--factory' needed because app entry is a factory function not an instance/
SERVER_MAIN_FLAGS := --host $(SERVER_HOST) --port $(SERVER_PORT) --factory
SERVER_TEST_FLAGS := $(SERVER_MAIN_FLAGS) --reload
COVERAGE_CONF := $(ROOT)/.coveragerc
COVERAGE_DATA := $(shell grep -E "datafile =" $(COVERAGE_CONF) | cut -d ' ' -f 3)
# --- Rules
help:
@echo "Make targets:"
@echo ""
@echo "Project builds:"
@echo ""
@echo " Notes:"
@echo " - These commands need an active virtualenv and use Poetry."
@echo " There are Pip equivalents but they are not make targets."
@echo ""
@echo " install - Install non-dev dependencies and main package"
@echo " develop - Install all dependencies and main package"
@echo " depends - Install all dependencies without the main package"
@echo ""
@echo " build - Build all distributable Python packages"
@echo " build-sdist - Build project as source tarball"
@echo " build-wheel - Build project as wheel"
@echo ""
@echo " clean - Remove all built Python packages"
@echo " clean-sdist - Remove built tarballs"
@echo " clean-wheel - Remove built wheels"
@echo ""
@echo " docs - Rebuild all documentation"
@echo " docs-changed - Rebuild only changed documentation"
@echo " docs-clean - Remove built documentation"
@echo " docs-serve - Run a local mkdocs server"
@echo ""
@echo "Pip requirements:"
@echo ""
@echo " pip-requirements - Export Pip requirements files with hashes"
@echo " pip-requirements-base - Export Pip requirements files without hashes"
@echo ""
@echo "Docker image:"
@echo ""
@echo " docker-build - Build Docker image from Dockerfile"
@echo " docker-run - Run Docker container"
@echo ""
@echo "PyTest: common commands"
@echo ""
@echo " test-all - Run all test cases"
@echo " test-one - Run until first failing case"
@echo " test-debug - Run debugger if any cases fail"
@echo ""
@echo "Coverage:"
@echo ""
@echo " cover-test - Run coverage over pytest"
@echo " cover-report - Generate text report of coverage"
@echo " Skips files with complete coverage"
@echo " cover-report-full - Generate full text report of coverage"
@echo " cover-html - Generate HTML report of coverage"
@echo " Skips files with complete coverage"
@echo " cover-html-full - Generate full HTML report of coverage"
@echo " cover-clean - Clear out existing coverage data"
@echo " cover-redo - Clear out existing data and run tests again"
@echo ""
@echo "Uvicorn server"
@echo ""
@echo " serve - Run uvicorn server, simulating prodction"
@echo " serve-test - Run uvicorn server for development"
@echo " Automatically reloads when source changes"
@echo ""
# Project builds
install:
poetry install --no-dev
develop:
poetry install
depends:
poetry install --no-root
build: build-sdist build-wheel
clean: clean-sdist clean-wheel
build-sdist:
poetry build -f sdist
clean-sdist:
rm -f dist/$(PROJECT)*.tar.gz
rmdir --ignore-fail-on-non-empty dist
build-wheel:
poetry build -f wheel
clean-wheel:
rm -f dist/$(PROJECT)*.whl
rmdir --ignore-fail-on-non-empty dist
# Doc builds
docs: $(MKDOCS_SITE_PATH)
poetry run mkdocs build -d $(MKDOCS_SITE_PATH)
docs-changed: $(MKDOCS_SITE_PATH)
poetry run mkdocs build --dirty -d $(MKDOCS_SITE_PATH)
docs-clean:
rm -rf $(MKDOCS_SITE_PATH)
docs-serve:
poetry run mkdocs serve -a $(MKDOCS_SERVER_ADDRESS)
$(MKDOCS_SITE_PATH):
mkdir -p $@
.PHONY: docs docs-changed docs-clean
# Pip requirements
pip-requirements:
poetry export -f requirements.txt > $(PIP_REQ_MAIN)
poetry export --dev -f requirements.txt > $(PIP_REQ_DEV)
pip-requirements-base:
poetry export --without-hashes -f requirements.txt > $(PIP_REQ_MAIN)
poetry export --without-hashes --dev -f requirements.txt > $(PIP_REQ_DEV)
# Docker
docker-build:
docker build -t "$(DOCKER_TAG)" .
docker-run:
docker run -it --rm --name "$(DOCKER_APP)" -p "$(DOCKER_PORT):$(DOCKER_PORT)" "$(DOCKER_TAG)"
# PyTest
test-all:
poetry run pytest
test-one:
poetry run pytest -x
test-debug:
poetry run pytest -x --pdb
# PyTest + Coverage
cover-test:
poetry run coverage run -m pytest
cover-report: $(COVERAGE_DATA)
poetry run coverage report --skip-covered --skip-empty
cover-report-full: $(COVERAGE_DATA)
poetry run coverage report
cover-html: $(COVERAGE_DATA)
poetry run coverage html --skip-covered --skip-empty
cover-html-full: $(COVERAGE_DATA)
poetry run coverage html
cover-clean:
poetry run coverage erase
cover-redo: cover-clean cover-test
# Uvicorn
serve:
poetry run uvicorn $(SERVER_MAIN_FLAGS) $(SERVER_APP_ENTRY)
serve-test:
poetry run uvicorn $(SERVER_TEST_FLAGS) $(SERVER_APP_ENTRY)