-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
195 lines (147 loc) · 4.51 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
SHELL=/bin/bash
.DEFAULT_GOAL := _help
# NOTE: must put a <TAB> character and two pound "\t##" to show up in this list. Keep it brief! IGNORE_ME
.PHONY: _help
_help:
ifeq ($(OS),Windows_NT)
@echo Our make _help target does not support Windows right now,
@echo but every other target should work!
@echo To list targets, use Git Bash: 'OS=unix make',
@echo linux subsystem, or look inside the Makefile.
else
@grep -h "##" $(MAKEFILE_LIST) | grep -v IGNORE_ME | sed -e 's/##//' | column -t -s $$'\t'
endif
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# init, venv, and deps
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TODO: should this just be "python3"?
PY_SYS_INTERPRETER ?= /usr/bin/python3
PY_VIRTUAL_INTERPRETER ?= python
.PHONY: init
init: ## Set up a Python virtual environment
git submodule update --init
rm -rf .venv
$(PY_SYS_INTERPRETER) -m venv .venv
if [-z "${CI}" ]; then ${PY_SYS_INTERPRETER} -m venv --upgrade-deps .venv; fi
- direnv allow
@echo NOTE: activate venv, and run 'make deps'
@echo HINT: run 'source .venv/bin/activate'
@echo on Win32 'call .venv\Scripts\activate.bat'
PYTHON ?= $(shell which python)
PWD ?= $(shell pwd)
.PHONY: _venv
_venv:
: # Test to enforce venv usage across important make targets
[[ "$(PYTHON)" =~ ".venv/bin/python" ]] || [[ "$(PYTHON)" =~ ".venv/Scripts/python" ]]
PIP ?= $(PY_VIRTUAL_INTERPRETER) -m pip
.PHONY: _deps
_deps:
$(PIP) install wheel
$(PIP) install -r requirements.txt
$(PIP) install -r requirements-test.txt
$(PIP) install -r requirements-lint.txt
.PHONY: deps
deps: _venv ## Install requirements
deps: _deps
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Test
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TEST_HOME := tests/
IT_HOME := tests/integration/it*
.PHONY: _test
_test:
coverage run -m pytest -v -s -p no:cacheprovider -o log_cli=true $(TEST_HOME)
coverage report
.PHONY: test
test: _venv ## Run unit tests
test: _test
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Lint
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.PHONY: _format
_format:
isort $(LINT_LOCS)
autopep8 --recursive --in-place --max-line-length 88 $(LINT_LOCS)
black $(LINT_LOCS)
.PHONY: format
format: _venv ## Format Python files
format: _format
APP_HOME := ntserv/
LINT_LOCS := $(APP_HOME) $(TEST_HOME) setup.py
YAML_LOCS := .*.yml .github/
RST_LOCS := *.rst
.PHONY: _lint
_lint:
# check formatting: Python
pycodestyle --max-line-length=88 --statistics $(LINT_LOCS)
autopep8 --recursive --diff --max-line-length 88 --exit-code $(LINT_LOCS)
isort --diff --check $(LINT_LOCS)
black --check $(LINT_LOCS)
# lint RST
doc8 --quiet $(RST_LOCS)
# lint YAML
yamllint $(YAML_LOCS)
# lint Python
bandit -q -c .banditrc -r $(LINT_LOCS)
mypy $(LINT_LOCS)
flake8 --statistics --doctests $(LINT_LOCS)
pylint $(LINT_LOCS)
.PHONY: lint
lint: _venv ## Lint code and documentation
lint: _lint
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Run
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.PHONY: _run
_run:
test -n "${NTSERV_HOST}"
test -n "${NTSERV_PORT}"
sanic ntserv.routes:app --host=${NTSERV_HOST} --port=${NTSERV_PORT} --debug --auto-reload
.PHONY: run
run: _venv ## Start the server
run: _run
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Build & Install
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.PHONY: build
build: _venv ## Create an sdist
$(PY_VIRTUAL_INTERPRETER) setup.py sdist
.PHONY: install
install: ## Pip install (user)
echo \"\"\"Auto-generated from Makefile\"\"\" >ntserv/__sha__.py
echo COMMIT_SHA = \"$(shell git rev-parse --short HEAD)\" >>ntserv/__sha__.py
echo COMMIT_DATE = \"$(shell git show -s --format=%cs)\" >>ntserv/__sha__.py
$(PY_SYS_INTERPRETER) -m pip install .
.PHONY: sql/upgrade
sql/upgrade: ## Attempt to run any SQL upgrades
# NOTE: the module does NOT yet support command line usage like this
# $(PY_SYS_INTERPRETER) -m ntserv sql upgrade
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Clean
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.PHONY: clean
clean: ## Clean up __pycache__ and leftover bits
rm -f .coverage
rm -f ntserv/__sha__.py
rm -rf .mypy_cache .pytest_cache __pycache__ *.egg-info build
# Find recursively & remove cache directories
find $(APP_HOME) $(TEST_HOME) \
-name __pycache__ \
-o -name .pytest_cache \
| xargs rm -rf
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Extras
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CLOC_ARGS ?=
.PHONY: extras/cloc
extras/cloc: ## Count lines of source code
- cloc \
--exclude-dir=\
.venv,venv,\
.mypy_cache,.pytest_cache,\
.idea,\
resources,\
build,dist \
--exclude-ext=svg \
$(CLOC_ARGS) \
.