-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
183 lines (140 loc) · 4.81 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
PROJECT := allusgov
PACKAGE := allusgov
MODULES := $(wildcard $(PACKAGE)/*.py)
# MAIN TASKS ##################################################################
.PHONY: all
all: doctor format check test ## Run all tasks that determine CI status
.PHONY: dev
dev: install .clean-test ## Continuously run CI tasks when files chanage
poetry run sniffer
# SYSTEM DEPENDENCIES #########################################################
.PHONY: boostrap
boostrap: ## Attempt to install system dependencies
asdf plugin add python || asdf plugin update python
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git || asdf plugin update poetry
asdf install
.PHONY: doctor
doctor: ## Confirm system dependencies are available
bin/verchew
# PROJECT DEPENDENCIES ########################################################
VIRTUAL_ENV ?= .venv
DEPENDENCIES := $(VIRTUAL_ENV)/.poetry-$(shell bin/checksum pyproject.toml poetry.lock)
.PHONY: install
install: $(DEPENDENCIES) .cache ## Install project dependencies
$(DEPENDENCIES): poetry.lock
@ rm -rf $(VIRTUAL_ENV)/.poetry-*
@ poetry config virtualenvs.in-project true
poetry install
@ touch $@
ifndef CI
poetry.lock: pyproject.toml
poetry lock --no-update
@ touch $@
endif
.cache:
@ mkdir -p .cache
# TEST ########################################################################
RANDOM_SEED ?= $(shell date +%s)
FAILURES := .cache/pytest/v/cache/lastfailed
PYTEST_OPTIONS := --random --random-seed=$(RANDOM_SEED)
ifndef DISABLE_COVERAGE
PYTEST_OPTIONS += --cov=$(PACKAGE)
endif
ifdef CI
PYTEST_OPTIONS += --cov-report=xml
endif
PYTEST_RERUN_OPTIONS := --last-failed --exitfirst
.PHONY: test
test: test-all ## Run unit and integration tests
.PHONY: test-unit
test-unit: install
@ ( mv $(FAILURES) $(FAILURES).bak || true ) > /dev/null 2>&1
poetry run pytest $(PACKAGE) $(PYTEST_OPTIONS)
@ ( mv $(FAILURES).bak $(FAILURES) || true ) > /dev/null 2>&1
ifndef DISABLE_COVERAGE
poetry run coveragespace update unit
endif
.PHONY: test-int
test-int: install
@ if test -e $(FAILURES); then poetry run pytest tests $(PYTEST_RERUN_OPTIONS); fi
@ rm -rf $(FAILURES)
poetry run pytest tests $(PYTEST_OPTIONS)
ifndef DISABLE_COVERAGE
poetry run coveragespace update integration
endif
.PHONY: test-all
test-all: install
@ if test -e $(FAILURES); then poetry run pytest $(PACKAGE) tests $(PYTEST_RERUN_OPTIONS); fi
@ rm -rf $(FAILURES)
poetry run pytest $(PACKAGE) tests $(PYTEST_OPTIONS)
ifndef DISABLE_COVERAGE
poetry run coveragespace update overall
endif
.PHONY: read-coverage
read-coverage:
bin/open htmlcov/index.html
# CHECK #######################################################################
.PHONY: format
format: install
poetry run isort $(PACKAGE) tests notebooks
poetry run black $(PACKAGE) tests notebooks
@ echo
.PHONY: check
check: install format ## Run formaters, linters, and static analysis
ifdef CI
git diff --exit-code
endif
poetry run mypy $(PACKAGE) tests
poetry run pylint $(PACKAGE) tests --rcfile=.pylint.ini
poetry run pydocstyle $(PACKAGE) tests
# DEMO ########################################################################
.PHONY: run
run: install ## Start the program
poetry run python $(PACKAGE)/__main__.py
.PHONY: shell
shell: install ## Launch an IPython session
poetry run ipython --ipython-dir=notebooks
# BUILD #######################################################################
DIST_FILES := dist/*.tar.gz dist/*.whl
EXE_FILES := dist/$(PACKAGE).*
.PHONY: dist
dist: install $(DIST_FILES)
$(DIST_FILES): $(MODULES) pyproject.toml
rm -f $(DIST_FILES)
poetry build
.PHONY: exe
exe: install $(EXE_FILES)
$(EXE_FILES): $(MODULES) $(PACKAGE).spec
poetry run pyinstaller $(PACKAGE).spec --noconfirm --clean
$(PACKAGE).spec:
poetry run pyi-makespec $(PACKAGE)/__main__.py --onefile --windowed --name=$(PACKAGE)
# RELEASE #####################################################################
.PHONY: upload
upload: dist ## Upload the current version to PyPI
git diff --name-only --exit-code
poetry publish
bin/open https://pypi.org/project/$(PROJECT)
# CLEANUP #####################################################################
.PHONY: clean
clean: .clean-build .clean-docs .clean-test .clean-install ## Delete all generated and temporary files
.PHONY: clean-all
clean-all: clean
rm -rf $(VIRTUAL_ENV)
.PHONY: .clean-install
.clean-install:
find $(PACKAGE) tests -name '__pycache__' -delete
rm -rf *.egg-info
.PHONY: .clean-test
.clean-test:
rm -rf .cache .pytest .coverage htmlcov
.PHONY: .clean-docs
.clean-docs:
rm -rf docs/*.png site
.PHONY: .clean-build
.clean-build:
rm -rf *.spec dist build
# HELP ########################################################################
.PHONY: help
help: install
@ grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help