-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
224 lines (167 loc) · 5.62 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
219
220
221
222
223
224
SHELL := /usr/bin/env bash
PYTHON_VERSION := 3.12
PYTHON_VERSION_CONDENSED := 312
PACKAGE_NAME := vaxstats
PACKAGE_PATH := $(PACKAGE_NAME)/
TESTS_PATH := tests/
CONDA_NAME := $(PACKAGE_NAME)-dev
CONDA := conda run -n $(CONDA_NAME)
CONDA_LOCK_OPTIONS := -p linux-64 -p osx-64 -p win-64 --channel conda-forge
# Default target
all:
@echo "Available targets:"
@echo " environment : Install conda environment named $(CONDA_NAME) with dependencies"
@echo " locks : Fresh install conda environment and rewrite lock files"
@echo " serve : Serve website documentation that watches and rebuilds on file changes"
@echo " docs : Build static website files in public/"
@echo " help : Display this help message"
help: all
### ENVIRONMENT ###
# See https://github.com/pypa/pip/issues/7883#issuecomment-643319919
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
.PHONY: conda-create
conda-create:
@ echo "Initializing conda environment: $(CONDA_NAME)"
@ echo -n "Preparing ... "
@- conda deactivate
@ conda remove -y -n $(CONDA_NAME) --all
@ conda create -y -n $(CONDA_NAME)
@ echo "done."
@ echo -n "Installing core dependencies ... "
@ $(CONDA) conda install -y -c conda-forge python=$(PYTHON_VERSION)
@ $(CONDA) conda install -y conda-lock
# Default packages that we always need.
.PHONY: conda-setup
conda-setup:
@ $(CONDA) conda install -y conda-forge::setuptools
@ $(CONDA) conda install -y conda-forge::poetry
@ $(CONDA) conda install -y conda-forge::pre-commit
@ $(CONDA) conda install -y conda-forge::conda-poetry-liaison
@ echo "done."
# Conda-only packages specific to this project.
.PHONY: conda-dependencies
conda-dependencies:
@ echo "No conda-only packages are required."
.PHONY: nodejs-dependencies
nodejs-dependencies:
$(CONDA) conda install -y -c conda-forge nodejs
$(CONDA) npm install markdownlint-cli2 --global
.PHONY: conda-lock
conda-lock:
- rm conda-lock.yml
$(CONDA) conda env export --from-history | grep -v "^prefix" > environment.yml
$(CONDA) conda-lock -f environment.yml $(CONDA_LOCK_OPTIONS)
$(CONDA) cpl-deps pyproject.toml --env_name $(CONDA_NAME)
$(CONDA) cpl-clean --env_name $(CONDA_NAME)
.PHONY: from-conda-lock
from-conda-lock:
$(CONDA) conda-lock install -n $(CONDA_NAME) conda-lock.yml
$(CONDA) cpl-clean --env_name $(CONDA_NAME)
.PHONY: pre-commit-install
pre-commit-install:
$(CONDA) pre-commit install
# Reads `pyproject.toml`, solves environment, then writes lock file.
.PHONY: poetry-lock
poetry-lock:
$(CONDA) poetry lock --no-interaction
.PHONY: install
install:
$(CONDA) poetry install --no-interaction
- mkdir .mypy_cache
- $(CONDA) mypy --install-types --non-interactive --explicit-package-bases $(PACKAGE_NAME)
.PHONY: environment
environment: conda-create from-conda-lock pre-commit-install install
.PHONY: locks
locks: conda-create conda-setup conda-dependencies nodejs-dependencies conda-lock pre-commit-install poetry-lock install
### FORMATTING ###
.PHONY: validate
validate:
- $(CONDA) markdownlint-cli2 "**/*.{md,markdown}" --config .markdownlint.yaml
- $(CONDA) pre-commit run --all-files
.PHONY: formatting
formatting:
- $(CONDA) markdownlint-cli2 "**/*.{md,markdown}" --fix --config .markdownlint.yaml
- $(CONDA) isort --settings-path pyproject.toml ./
- $(CONDA) black --config pyproject.toml ./
### TESTING ###
.PHONY: test
test:
$(CONDA) pytest -c pyproject.toml --cov=$(PACKAGE_NAME) --cov-report=xml --junit-xml=report.xml --color=yes $(TESTS_PATH)
.PHONY: coverage
coverage:
$(CONDA) coverage report
### LINTING ###
.PHONY: check-codestyle
check-codestyle:
$(CONDA) isort --diff --check-only $(PACKAGE_PATH)
$(CONDA) black --diff --check --config pyproject.toml $(PACKAGE_PATH)
- $(CONDA) pylint --rcfile pyproject.toml $(PACKAGE_PATH)
.PHONY: mypy
mypy:
- $(CONDA) mypy --config-file pyproject.toml $(PACKAGE_PATH)
.PHONY: lint
lint: check-codestyle mypy
### DEPLOY ###
.PHONY: build
build:
$(CONDA) poetry build
.PHONY: publish-test
publish-test:
$(CONDA) python3 -m twine upload --repository testpypi dist/*
.PHONY: publish
publish:
$(CONDA) python3 -m twine upload dist/*
### CLEANING ###
.PHONY: pycache-remove
pycache-remove:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf
.PHONY: dsstore-remove
dsstore-remove:
find . | grep -E ".DS_Store" | xargs rm -rf
.PHONY: mypycache-remove
mypycache-remove:
find . | grep -E ".mypy_cache" | xargs rm -rf
.PHONY: ipynbcheckpoints-remove
ipynbcheckpoints-remove:
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
.PHONY: pytestcache-remove
pytestcache-remove:
find . | grep -E ".pytest_cache" | xargs rm -rf
.PHONY: pytest-coverage
pytest-coverage:
rm report.xml coverage.xml .coverage
.PHONY: build-remove
build-remove:
rm -rf build/
.PHONY: cleanup
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove
### DOCS ###
.PHONY: docs-env
docs-env:
$(CONDA) poetry install --no-interaction --only docs
mkdocs_port := $(shell \
start_port=3000; \
max_attempts=100; \
for i in $$(seq 0 $$(($$max_attempts - 1))); do \
current_port=$$(($$start_port + i)); \
if ! lsof -i :$$current_port > /dev/null; then \
echo $$current_port; \
break; \
fi; \
if [ $$i -eq $$(($$max_attempts - 1)) ]; then \
echo "Error: Unable to find an available port after $$max_attempts attempts."; \
exit 1; \
fi; \
done \
)
.PHONY: serve
serve:
@ echo "Serving documentation at http://127.0.0.1:$(mkdocs_port)/"
@ $(CONDA) mkdocs serve -a localhost:$(mkdocs_port)
.PHONY: docs
docs:
$(CONDA) mkdocs build -d public/
- rm -f public/gen_ref_pages.py
.PHONY: open-docs
open-docs:
xdg-open public/index.html 2>/dev/null