-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (96 loc) · 3.26 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
# colors
GREEN=\033[0;32m
RED=\033[0;31m
BLUE=\033[0;34m
NC=\033[0m
# test envs
PYTHON_VERSIONS ?= 3.8.12 3.9.18 3.10.13 3.11.5
RUFF_PYTHON_VERSION ?= py38
PROJECT=$(shell basename $(CURDIR))
PACKAGE_NAME=`cat .pypi-template | grep "^package_module_name" | cut -d":" -f2 | xargs`
LOG_LEVEL?=ERROR
SILENT?=yes
RUN_CMD?=LOG_LEVEL=$(LOG_LEVEL) python -m $(PACKAGE_NAME)
RUN_ARGS?=
TEST_ENVS=$(addprefix $(PROJECT)-test-,$(PYTHON_VERSIONS))
install: install-env-run install-env-docs install-env-test
@echo "👷♂️ $(BLUE)installing requirements in $(PROJECT)$(NC)"
pyenv local $(PROJECT)
pip install -U pip > /dev/null
pip install -U wheel twine > /dev/null
install-env-run:
@echo "👷♂️ $(BLUE)creating virtual environment $(PROJECT)-run$(NC)"
pyenv local --unset
-pyenv virtualenv $(PROJECT)-run > /dev/null
pyenv local $(PROJECT)-run
pip install -U pip > /dev/null
pip install -r requirements.txt > /dev/null
[ -f requirements.run.txt ] && pip install -r requirements.run.txt > /dev/null || true
install-env-docs:
@echo "👷♂️ $(BLUE)creating virtual environment $(PROJECT)-docs$(NC)"
pyenv local --unset
-pyenv virtualenv $(PROJECT)-docs > /dev/null
pyenv local $(PROJECT)-docs
pip install -U pip > /dev/null
pip install -r requirements.docs.txt > /dev/null
install-env-test: $(TEST_ENVS)
$(PROJECT)-test-%:
@echo "👷♂️ $(BLUE)creating virtual test environment $@$(NC)"
pyenv local --unset
-pyenv virtualenv $* $@ > /dev/null
pyenv local $@
pip install -U pip > /dev/null
pip install -U ruff tox coverage > /dev/null
uninstall: uninstall-envs
uninstall-envs: uninstall-env-test uninstall-env-docs uninstall-env-run env clean-env
uninstall-env-test: $(addprefix uninstall-env-test-,$(PYTHON_VERSIONS))
$(addprefix uninstall-env-test-,$(PYTHON_VERSIONS)) uninstall-env-docs uninstall-env-run: uninstall-env-%:
@echo "👷♂️ $(RED)deleting virtual environment $(PROJECT)-$*$(NC)"
-pyenv virtualenv-delete $(PROJECT)-$*
clean-env:
@echo "👷♂️ $(RED)deleting all packages from current environment$(NC)"
pip freeze | cut -d"@" -f1 | cut -d'=' -f1 | xargs pip uninstall -y > /dev/null
upgrade:
@pip list --outdated | tail +3 | cut -d " " -f 1 | xargs -n1 pip install -U
# env switching
env-%:
@echo "👷♂️ $(BLUE)activating $* environment$(NC)"
@pyenv local $(PROJECT)-$*
env:
@echo "👷♂️ $(BLUE)activating project environment$(NC)"
@pyenv local $(PROJECT)
env-test:
@echo "👷♂️ $(BLUE)activating test environments$(NC)"
@pyenv local $(TEST_ENVS)
# functional targets
run: env-run
@echo "👷♂️ $(BLUE)running$(GREEN) $(RUN_CMD) $(RUN_ARGS)$(NC)"
@$(RUN_CMD) $(RUN_ARGS)
test: env-test lint
ifeq ($(SILENT),yes)
tox -q
else
tox
endif
coverage: test
coverage report
coverage lcov
lint: env-test
ruff check --target-version=$(RUFF_PYTHON_VERSION) .
docs: env-docs
cd docs; make html
open docs/_build/html/index.html
# packaging targets
publish-test: env dist
twine upload --repository testpypi dist/*
publish: env dist
twine upload dist/*
dist: env dist-clean
python setup.py sdist bdist_wheel
dist-clean: clean
rm -rf dist build *.egg-info
clean:
find . -type f -name "*.backup" | xargs rm
.PHONY: dist docs test
# include optional a personal/local touch
-include Makefile.mak