forked from tekumara/fakesnow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-common.mk
66 lines (50 loc) · 1.69 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
MAKEFLAGS += --warn-undefined-variables
SHELL = /bin/bash -o pipefail
.DEFAULT_GOAL := help
.PHONY: help clean install format check 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): $(if $(value CI),|,) .python-version
# create venv using system python even when another venv is active
PATH=$${PATH#$${VIRTUAL_ENV}/bin:} python3 -m venv --clear $(venv)
$(venv)/bin/python --version
$(pip) install --upgrade pip~=24.0
$(venv): $(if $(value CI),|,) pyproject.toml $(pip)
$(pip) install -e '.[dev$(if $(value CI),,,notebook)]'
touch $(venv)
node_modules: package.json
npm install --no-save
touch node_modules
# delete the venv
clean:
rm -rf $(venv)
## create venv and install this package and hooks
install: $(venv) node_modules $(if $(value CI),,install-hooks)
## format, lint and type check
check: export SKIP=test
check: hooks
## format and lint
format: export SKIP=pyright,test
format: hooks
## pyright type check
pyright: node_modules $(venv)
node_modules/.bin/pyright
## run tests
test: $(venv)
$(venv)/bin/pytest
## build python distribution
dist: $(venv)
rm -rf 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: node_modules $(venv)
$(venv)/bin/pre-commit run --color=always --all-files --hook-stage push
install-hooks: .git/hooks/pre-push
.git/hooks/pre-push: $(venv)
$(venv)/bin/pre-commit install --install-hooks -t pre-push