| 1 |
PACKAGE := aiomusiccast |
| 2 |
MODULES := $(wildcard $(PACKAGE)/*.py) |
| 3 |
|
| 4 |
# MAIN TASKS ################################################################## |
| 5 |
|
| 6 |
.PHONY: all |
| 7 |
all: install |
| 8 |
|
| 9 |
.PHONY: ci |
| 10 |
ci: format check test mkdocs ## Run all tasks that determine CI status |
| 11 |
|
| 12 |
.PHONY: watch |
| 13 |
watch: install .clean-test ## Continuously run all CI tasks when files chanage |
| 14 |
poetry run sniffer |
| 15 |
|
| 16 |
.PHONY: run ## Start the program |
| 17 |
run: install |
| 18 |
poetry run python $(PACKAGE)/__main__.py |
| 19 |
|
| 20 |
.PHONY: ipython ## Launch an IPython session |
| 21 |
ipython: install |
| 22 |
poetry run ipython --ipython-dir=notebooks |
| 23 |
|
| 24 |
# SYSTEM DEPENDENCIES ######################################################### |
| 25 |
|
| 26 |
.PHONY: doctor |
| 27 |
doctor: ## Confirm system dependencies are available |
| 28 |
bin/verchew |
| 29 |
|
| 30 |
# PROJECT DEPENDENCIES ######################################################## |
| 31 |
|
| 32 |
VIRTUAL_ENV ?= .venv |
| 33 |
DEPENDENCIES := $(VIRTUAL_ENV)/.poetry-$(shell bin/checksum pyproject.toml poetry.lock) |
| 34 |
|
| 35 |
.PHONY: install |
| 36 |
install: $(DEPENDENCIES) .cache |
| 37 |
|
| 38 |
$(DEPENDENCIES): poetry.lock |
| 39 |
@ rm -rf $(VIRTUAL_ENV)/.poetry-* |
| 40 |
@ poetry config virtualenvs.in-project true |
| 41 |
poetry install |
| 42 |
@ touch $@ |
| 43 |
|
| 44 |
ifndef CI |
| 45 |
poetry.lock: pyproject.toml |
| 46 |
poetry lock --no-update |
| 47 |
@ touch $@ |
| 48 |
endif |
| 49 |
|
| 50 |
.cache: |
| 51 |
@ mkdir -p .cache |
| 52 |
|
| 53 |
# CHECKS ###################################################################### |
| 54 |
|
| 55 |
.PHONY: format |
| 56 |
format: install |
| 57 |
poetry run isort $(PACKAGE) tests notebooks |
| 58 |
poetry run black $(PACKAGE) tests notebooks |
| 59 |
@ echo |
| 60 |
|
| 61 |
.PHONY: check |
| 62 |
check: install format ## Run formaters, linters, and static analysis |
| 63 |
ifdef CI |
| 64 |
git diff --exit-code |
| 65 |
endif |
| 66 |
poetry run mypy $(PACKAGE) tests --config-file=.mypy.ini |
| 67 |
poetry run pylint $(PACKAGE) tests --rcfile=.pylint.ini |
| 68 |
poetry run pydocstyle $(PACKAGE) tests |
| 69 |
|
| 70 |
# TESTS ####################################################################### |
| 71 |
|
| 72 |
RANDOM_SEED ?= $(shell date +%s) |
| 73 |
FAILURES := .cache/v/cache/lastfailed |
| 74 |
|
| 75 |
PYTEST_OPTIONS := --random --random-seed=$(RANDOM_SEED) |
| 76 |
ifndef DISABLE_COVERAGE |
| 77 |
PYTEST_OPTIONS += --cov=$(PACKAGE) |
| 78 |
endif |
| 79 |
PYTEST_RERUN_OPTIONS := --last-failed --exitfirst |
| 80 |
|
| 81 |
.PHONY: test |
| 82 |
test: test-all ## Run unit and integration tests |
| 83 |
|
| 84 |
.PHONY: test-unit |
| 85 |
test-unit: install |
| 86 |
@ ( mv $(FAILURES) $(FAILURES).bak || true ) > /dev/null 2>&1 |
| 87 |
poetry run pytest $(PACKAGE) $(PYTEST_OPTIONS) |
| 88 |
@ ( mv $(FAILURES).bak $(FAILURES) || true ) > /dev/null 2>&1 |
| 89 |
ifndef DISABLE_COVERAGE |
| 90 |
poetry run coveragespace update unit |
| 91 |
endif |
| 92 |
|
| 93 |
.PHONY: test-int |
| 94 |
test-int: install |
| 95 |
@ if test -e $(FAILURES); then poetry run pytest tests $(PYTEST_RERUN_OPTIONS); fi |
| 96 |
@ rm -rf $(FAILURES) |
| 97 |
poetry run pytest tests $(PYTEST_OPTIONS) |
| 98 |
ifndef DISABLE_COVERAGE |
| 99 |
poetry run coveragespace update integration |
| 100 |
endif |
| 101 |
|
| 102 |
.PHONY: test-all |
| 103 |
test-all: install |
| 104 |
@ if test -e $(FAILURES); then poetry run pytest $(PACKAGE) tests $(PYTEST_RERUN_OPTIONS); fi |
| 105 |
@ rm -rf $(FAILURES) |
| 106 |
poetry run pytest $(PACKAGE) tests $(PYTEST_OPTIONS) |
| 107 |
ifndef DISABLE_COVERAGE |
| 108 |
poetry run coveragespace update overall |
| 109 |
endif |
| 110 |
|
| 111 |
.PHONY: read-coverage |
| 112 |
read-coverage: |
| 113 |
bin/open htmlcov/index.html |
| 114 |
|
| 115 |
# DOCUMENTATION ############################################################### |
| 116 |
|
| 117 |
MKDOCS_INDEX := site/index.html |
| 118 |
|
| 119 |
.PHONY: docs |
| 120 |
docs: mkdocs uml ## Generate documentation and UML |
| 121 |
|
| 122 |
.PHONY: mkdocs |
| 123 |
mkdocs: install $(MKDOCS_INDEX) |
| 124 |
$(MKDOCS_INDEX): docs/requirements.txt mkdocs.yml docs/*.md |
| 125 |
@ mkdir -p docs/about |
| 126 |
@ cd docs && ln -sf ../README.md index.md |
| 127 |
@ cd docs/about && ln -sf ../../CHANGELOG.md changelog.md |
| 128 |
@ cd docs/about && ln -sf ../../CONTRIBUTING.md contributing.md |
| 129 |
@ cd docs/about && ln -sf ../../LICENSE.md license.md |
| 130 |
poetry run mkdocs build --clean --strict |
| 131 |
|
| 132 |
docs/requirements.txt: poetry.lock |
| 133 |
@ poetry export --dev --without-hashes | grep mkdocs > $@ |
| 134 |
@ poetry export --dev --without-hashes | grep pygments >> $@ |
| 135 |
|
| 136 |
.PHONY: uml |
| 137 |
uml: install docs/*.png |
| 138 |
docs/*.png: $(MODULES) |
| 139 |
poetry run pyreverse $(PACKAGE) -p $(PACKAGE) -a 1 -f ALL -o png --ignore tests |
| 140 |
- mv -f classes_$(PACKAGE).png docs/classes.png |
| 141 |
- mv -f packages_$(PACKAGE).png docs/packages.png |
| 142 |
|
| 143 |
.PHONY: mkdocs-serve |
| 144 |
mkdocs-serve: mkdocs |
| 145 |
eval "sleep 3; bin/open http://127.0.0.1:8000" & |
| 146 |
poetry run mkdocs serve |
| 147 |
|
| 148 |
# BUILD ####################################################################### |
| 149 |
|
| 150 |
DIST_FILES := dist/*.tar.gz dist/*.whl |
| 151 |
EXE_FILES := dist/$(PACKAGE).* |
| 152 |
|
| 153 |
.PHONY: dist |
| 154 |
dist: install $(DIST_FILES) |
| 155 |
$(DIST_FILES): $(MODULES) pyproject.toml |
| 156 |
rm -f $(DIST_FILES) |
| 157 |
poetry build |
| 158 |
|
| 159 |
.PHONY: exe |
| 160 |
exe: install $(EXE_FILES) |
| 161 |
$(EXE_FILES): $(MODULES) $(PACKAGE).spec |
| 162 |
# For framework/shared support: https://github.com/yyuu/pyenv/wiki |
| 163 |
poetry run pyinstaller $(PACKAGE).spec --noconfirm --clean |
| 164 |
|
| 165 |
$(PACKAGE).spec: |
| 166 |
poetry run pyi-makespec $(PACKAGE)/__main__.py --onefile --windowed --name=$(PACKAGE) |
| 167 |
|
| 168 |
# RELEASE ##################################################################### |
| 169 |
|
| 170 |
.PHONY: upload |
| 171 |
upload: dist ## Upload the current version to PyPI |
| 172 |
git diff --name-only --exit-code |
| 173 |
poetry publish |
| 174 |
bin/open https://pypi.org/project/$(PACKAGE) |
| 175 |
|
| 176 |
# CLEANUP ##################################################################### |
| 177 |
|
| 178 |
.PHONY: clean |
| 179 |
clean: .clean-build .clean-docs .clean-test .clean-install ## Delete all generated and temporary files |
| 180 |
|
| 181 |
.PHONY: clean-all |
| 182 |
clean-all: clean |
| 183 |
rm -rf $(VIRTUAL_ENV) |
| 184 |
|
| 185 |
.PHONY: .clean-install |
| 186 |
.clean-install: |
| 187 |
find $(PACKAGE) tests -name '__pycache__' -delete |
| 188 |
rm -rf *.egg-info |
| 189 |
|
| 190 |
.PHONY: .clean-test |
| 191 |
.clean-test: |
| 192 |
rm -rf .cache .pytest .coverage htmlcov |
| 193 |
|
| 194 |
.PHONY: .clean-docs |
| 195 |
.clean-docs: |
| 196 |
rm -rf docs/*.png site |
| 197 |
|
| 198 |
.PHONY: .clean-build |
| 199 |
.clean-build: |
| 200 |
rm -rf *.spec dist build |
| 201 |
|
| 202 |
# HELP ######################################################################## |
| 203 |
|
| 204 |
.PHONY: help |
| 205 |
help: all |
| 206 |
@ grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 207 |
|
| 208 |
.DEFAULT_GOAL := help |