-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (105 loc) · 3.61 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
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
NO_VENV?=
export UV_SYSTEM_PYTHON=$(if $(NO_VENV),$(NO_VENV),0)
ifndef VERBOSE
# Usage:
# make help # don't print commands ran
# VERBOSE=1 make help # print commands ran
.SILENT:
endif
.PHONY: help
help:
echo 'Check README for usage examples'
.PHONY: venv
# create a virtual environment in the current directory
venv:
uv venv
.PHONY: ensure.venv
# abort if running outside of a virtual environment
# override with `NO_VENV=1 make ...`
ensure.venv:
if [ $(NO_VENV) ]; then exit 0; fi;
IS_VENV=`python -m tools.is_virtualenv`
if [ $$IS_VENV != 'True' ]; then
echo 'Not in a virtual environment, aborting';
echo 'Use `NO_VENV=1 make <...>` or run `make venv` followed by activate';
exit 1;
fi
.PHONY: dev
# setup development environment
dev: ensure.venv dev.python dev.hooks
.PHONY: dev.python
# install Python dependencies for development
dev.python: ensure.venv
uv pip install -r requirements-dev.txt
.PHONY: dev.python.outdated
# install valid but outdated production requirements for development
dev.python.outdated: ensure.venv
uv pip install -r requirements.out
.PHONY: dev.hooks
# install pre-commit hooks for development
dev.hooks: ensure.venv
pre-commit install --install-hooks
.PHONY: lint
# run all project style, design and type checkers
lint: ensure.venv
pre-commit run --all-files
.PHONY: test
# run all project unit tests and print coverage misses
test: ensure.venv
python -m pytest --cov --cov-report=term-missing
.PHONY: test.coverage
# run all project unit tests and save coverage report for upload
test.coverage: ensure.venv
python -m coverage run --parallel -m pytest
.PHONY: update
# update dependency definitions after .in-file modifications
update: ensure.venv
UV_PYTHON=3.8 uv pip compile --no-header requirements.in > requirements.txt
UV_PYTHON=3.8 uv pip compile --no-header requirements-dev.in > requirements-dev.txt
python -m tools.freezenuts requirements.in > requirements.out
.PHONY: upgrade
# upgrade all dependencies to the latest valid version
upgrade: ensure.venv
UV_PYTHON=3.8 uv pip compile --upgrade --no-header requirements.in > requirements.txt
UV_PYTHON=3.8 uv pip compile --upgrade --no-header requirements-dev.in > requirements-dev.txt
python -m tools.freezenuts requirements.in > requirements.out
pre-commit autoupdate
.PHONY: run
# run package as a module
run: ensure.venv
python -m myproject
.PHONY: install
# install the package to current the virtual environment as an editable,
# and add all the configured executables to the environment `/bin`
install: ensure.venv
uv pip install -e .
echo -e '\nTry running `myproject` in the command line'
.PHONY: uninstall
# uninstall any `pip` installation of this package, but doesn't touch dependencies
uninstall: ensure.venv
uv pip uninstall myproject
.PHONY: version
# increment package version and create a tagged git commit
# Usage: make version bump=minor # 'major', 'minor' or 'patch'
version: ensure.venv
python -m tools.bump myproject/VERSION $(bump)
git reset
git add myproject/VERSION
VERSION=`cat myproject/VERSION`
git commit -m "Become $$VERSION"
git tag -a $$VERSION -m "$$VERSION"
echo -e '\nCreated a new tagged commit, remember to later push it with `git push --follow-tags`'
.PHONY: build
# compile the current package version as distributables under `/dist`
build: ensure.venv
python -m build
.PHONY: publish
# upload the current version distributables to PyPI for sharing
publish: ensure.venv
VERSION=`cat myproject/VERSION`
hatch publish -r test dist/myproject-$$VERSION*