-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMakefile
More file actions
159 lines (121 loc) · 4.43 KB
/
Makefile
File metadata and controls
159 lines (121 loc) · 4.43 KB
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
PACKAGE := datafiles
MODULES := $(wildcard $(PACKAGE)/*.py)
# MAIN TASKS ##################################################################
.PHONY: all
all: doctor format check test mkdocs ## Run all tasks that determine CI status
.PHONY: dev
dev: install ## Continuously run all CI tasks when files change
poetry run ptw
.PHONY: shell
shell: install
poetry run ipython --ipython-dir=notebooks
.PHONY: demo
demo: install
poetry run nbstripout notebooks/*.ipynb
poetry run jupyter notebook --notebook-dir=notebooks --browser=firefox
# SYSTEM DEPENDENCIES #########################################################
.PHONY: bootstrap
bootstrap: ## Attempt to install system dependencies
asdf plugin add python || asdf plugin update python
asdf plugin add poetry || asdf plugin update poetry
asdf install
.PHONY: doctor
doctor: ## Confirm system dependencies are available
bin/verchew --exit-code
# 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 docs/requirements.txt
@ rm -rf $(VIRTUAL_ENV)/.poetry-*
@ poetry config virtualenvs.in-project true
poetry install
@ touch $@
ifndef CI
poetry.lock: pyproject.toml
poetry lock
@ touch $@
docs/requirements.txt: poetry.lock
@ rm -f $@
poetry export --all-groups --without-hashes | grep jinja2 >> $@
poetry export --all-groups --without-hashes | grep markdown >> $@
poetry export --all-groups --without-hashes | grep mkdocs >> $@
poetry export --all-groups --without-hashes | grep pygments >> $@
endif
.cache:
@ mkdir -p .cache
# CHECKS ######################################################################
.PHONY: format
format: install
poetry run isort $(PACKAGE) tests
poetry run black $(PACKAGE) tests
@ echo
.PHONY: check
check: install format ## Run formatters, linters, and static analysis
ifdef CI
git diff --exit-code
endif
poetry run mypy $(PACKAGE) tests --config-file=.mypy.ini
poetry run pylint $(PACKAGE) tests --rcfile=.pylint.ini
poetry run pydocstyle $(PACKAGE) tests
# TESTS #######################################################################
.PHONY: test
test: install ## Run unit and integration tests
poetry run pytest --random
poetry run coveragespace update overall
.PHONY: test-repeat
test-repeat: install
poetry run pytest --count=2 --random --exitfirst --cov-report=xml
.PHONY: test-profile
test-profile: install
poetry run pytest tests/test_profiling.py --profile-svg
# DOCUMENTATION ###############################################################
MKDOCS_INDEX := site/index.html
.PHONY: docs
docs: mkdocs uml notebooks ## Generate documentation and UML
.PHONY: mkdocs
mkdocs: install $(MKDOCS_INDEX)
$(MKDOCS_INDEX): mkdocs.yml docs/*.md
@ mkdir -p docs/about
@ cd docs/about && ln -sf ../../CHANGELOG.md changelog.md
@ cd docs/about && ln -sf ../../CONTRIBUTING.md contributing.md
@ cd docs/about && ln -sf ../../LICENSE.md license.md
poetry run mkdocs build --clean --strict
.PHONY: mkdocs-serve
mkdocs-serve: mkdocs
eval "sleep 3; bin/open http://127.0.0.1:8000" &
poetry run mkdocs serve
.PHONY: uml
uml: install docs/*.png
docs/*.png: $(MODULES)
poetry run pyreverse $(PACKAGE) -p $(PACKAGE) -a 1 -f ALL -o png --ignore tests
- mv -f classes_$(PACKAGE).png docs/classes.png
- mv -f packages_$(PACKAGE).png docs/packages.png
.PHONY: notebooks
notebooks: install
@ cd notebooks; for filename in *.ipynb; do \
poetry run papermill $$filename $$filename; \
done
poetry run nbstripout --keep-output notebooks/*.ipynb
# RELEASE #####################################################################
DIST_FILES := dist/*.tar.gz dist/*.whl
.PHONY: dist
dist: install $(DIST_FILES)
$(DIST_FILES): $(MODULES) pyproject.toml
rm -f $(DIST_FILES)
poetry build
.PHONY: upload
upload: dist ## Upload the current version to PyPI
git diff --name-only --exit-code
poetry publish
bin/open https://pypi.org/project/$(PACKAGE)
# CLEANUP #####################################################################
.PHONY: clean
clean: ## Delete all generated and temporary files
rm -rf .venv
# 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