-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile-common.mk
72 lines (56 loc) · 2.07 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
70
71
72
MAKEFLAGS += --warn-undefined-variables --check-symlink-times
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
# this is a symlink so we set the --check-symlink-times makeflag above
python := $(venv)/bin/python
# use uv if present, else fall back to pip
# set VIRTUAL_ENV to avoid uv installing into a different activated venv
pip = $(shell command -v uv >/dev/null && echo "VIRTUAL_ENV=$(venv) uv pip" || echo "$(venv)/bin/pip")
$(python): $(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)
$(python) --version
$(pip) install --upgrade pip~=24.0
$(venv): $(if $(value CI),|,) pyproject.toml $(python)
# TODO use uv sync
$(pip) install -e '.[dev,server$(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)
# start with a clean slate (see setuptools/#2347)
rm -rf build dist *.egg-info
$(venv)/bin/python -m build --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