-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-common.mk
69 lines (52 loc) · 1.86 KB
/
Makefile-common.mk
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
MAKEFLAGS += --warn-undefined-variables
SHELL = /bin/bash -o pipefail
.DEFAULT_GOAL := help
.PHONY: help clean install format check lint pyright test dist hooks install-hooks
## display help message
help:
@awk '/^##.*$$/,/^[~\/\.0-9a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?##"}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | sort
venv ?= .venv
pip := $(venv)/bin/pip
$(pip):
# create venv using system python even when another venv is active
PATH=$${PATH#$${VIRTUAL_ENV}/bin:} python3.10 -m venv --clear $(venv)
$(venv)/bin/python3.10 --version
$(pip) install pip~=23.0 wheel~=0.40
$(venv): pyproject.toml $(pip)
$(pip) install -e '.[dev]'
touch $(venv)
# delete the venv
clean:
rm -rf $(venv)
## create venv and install this package and hooks
install: $(venv) node_modules $(if $(value CI),,install-hooks)
## lint code and run static type check
check: lint pyright
## lint and format code
lint: $(venv)
SKIP=pyright,test $(venv)/bin/pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage push
node_modules: package.json
npm install --no-save
touch node_modules
## pyright
pyright: node_modules $(venv)
# activate venv so pyright can find dependencies
PATH="$(venv)/bin:$$PATH" node_modules/.bin/pyright
## run tests
test: $(venv)
$(venv)/bin/pytest
## build python distribution
#dist: $(venv)
# rm -rf build dist *.egg-info
# $(venv)/bin/python -m build --sdist --wheel
## publish to pypi
publish: $(venv)
$(venv)/bin/twine upload dist/*
## run pre-commit git hooks on all files
hooks: $(venv)
$(venv)/bin/pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage push
install-hooks: .git/hooks/pre-commit .git/hooks/pre-push
.git/hooks/pre-commit: $(venv)
$(venv)/bin/pre-commit install -t pre-commit
.git/hooks/pre-push: $(venv)
$(venv)/bin/pre-commit install -t pre-push