-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
103 lines (83 loc) · 2.54 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
PROJNAME=glinkfix
ifeq (${MAKECMDGOALS},coverage)
WEBPATH=htmlcov/index.html
endif
# --------------------------------------------
define BROWSER_PYSCRIPT
import webbrowser
from pathlib import Path
p = Path('.').resolve()/'${WEBPATH}'
webbrowser.open(f'file://{p}', new=2)
endef
export BROWSER_PYSCRIPT
BROWSER?=python3 -c "$$BROWSER_PYSCRIPT"
# --------------------------------------------
all: help
# --------------------------------------------
.PHONY: setup
setup: ## initialize the project and python venv
ifeq (,$(wildcard .init/setup))
@(which poetry > /dev/null 2>&1) || \
(echo "pymids requires poetry. See README for instructions."; exit 1)
mkdir .init
@if [ ! -d "./scratch" ]; then \
mkdir -p scratch; \
fi
touch .init/setup
poetry install
else
@echo "Initial setup is already complete. If you are having issues, run:"
@echo
@echo "make reset"
@echo "make setup"
@echo
endif
# --------------------------------------------
.PHONY: dev
dev: ## add development dependencies (run make setup first)
ifneq (,$(wildcard .init/setup))
poetry install
@touch .init/dev
else
@echo "Please run \"make setup\" first"
endif
# --------------------------------------------
.PHONY: reset
reset: clean ## reinitialize the project
@echo Resetting project state
@rm -rf .mypy_cache
@rm -rf .venv .init
# --------------------------------------------
.PHONY: clean
clean: ## Purge project build artifacts
@echo Cleaning project build artifacts
@rm -rf build/
@rm -rf dist/
@find . -type d -name __pycache__ -exec rm -rf {} \; -prune
@find . -type d -name .ipynb_checkpoints -exec rm -rf {} \; -prune
@find . -type d -name .pytest_cache -exec rm -rf {} \; -prune
@find . -type d -name .eggs -exec rm -rf {} \; -prune
@find . -type d -name htmlcov -exec rm -rf {} \; -prune
@find . -type d -name *.egg-info -exec rm -rf {} \; -prune
@find . -type f -name *.egg -delete
@find . -type f -name *.pyc -delete
@find . -type f -name *.pyo -delete
@find . -type f -name *.coverage -delete
# --------------------------------------------
.PHONY: coverage
coverage: ## Generate an html code coverage report
coverage run -m pytest
coverage report -m
coverage html
${BROWSER}
# --------------------------------------------
.PHONY: test
test: ## Run pytest with --tb=short option
pytest --tb=short
# --------------------------------------------
.PHONY: help
help: ## Show help
@echo Please specify a target. Choices are:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk \
'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'