-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
122 lines (86 loc) · 2.94 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
# 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`
RUN_CMD?=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 > /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-%:
pyenv local $(PROJECT)-$*
env:
pyenv local $(PROJECT)
env-test:
pyenv local $(TEST_ENVS)
# functional targets
run: env-run
$(RUN_CMD) $(RUN_ARGS)
test: env-test lint
tox
coverage: test
coverage report
lint: env-test
ruff --select=E9,F63,F7,F82 --target-version=$(RUFF_PYTHON_VERSION) .
ruff --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