-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (126 loc) · 4.46 KB
/
Copy pathMakefile
File metadata and controls
164 lines (126 loc) · 4.46 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Use bash syntax, mitigates dash's printf on Debian
SHELL:=/usr/bin/env bash
export TOP:=$(shell dirname "$(abspath $(lastword $(MAKEFILE_LIST)))")
name:=$(shell basename "$(TOP)")
export PIP_FIND_LINKS:=$(abspath $(TOP)/whl_local/)
export PYTHONPATH:=$(TOP)/src
RPM_VER ?= $$( \
{ ver=$$(git tag --sort=-version:refname 2>/dev/null | grep -E '^v?[0-9]' | head -1 | sed 's/^v//'); \
[ -n "$$ver" ] || ver=$$(grep -m1 '__version__' src/$(name)/__init__.py | cut -d'"' -f2); \
echo "$$ver"; } \
)
RPM_REV ?= 0
outdir ?= dist
.PHONY: help
help:
@echo
@echo "▍Help"
@echo "▀▀▀▀▀▀"
@echo
@echo "Available targets:"
@echo " lint: run linters"
@echo " typecheck: run pyright type checker"
@echo " test: run tests"
@echo " check: test + lint + typecheck"
@echo " coverage: run tests and collect code coverage"
@echo
@echo " format: auto-format code with autopep8"
@echo
@echo " run: sync dev environment and run the app (development mode)"
@echo
@echo " build: build the source and whl package, look for */dist/*.whl"
@echo " srpm: build source RPM package (optional: outdir=/path)"
@echo " rpm: build RPM package"
@echo " rpmmock: build RPM package using mock (recommended)"
@echo
@echo " release: tag a new release (required: V=X.Y.Z), e.g. make V=1.0.0 release"
@echo " test_upload: upload to test.pypi.org"
@echo " upload: upload to pypi.org"
@echo
@echo " clean: clean the build tree"
@echo " distclean (dc): clean everything (even the virtual environment)"
@echo
@printf "Makefile debug info:\n\t- name=%q\n\t- PYTHONPATH=%q\n\t- PIP_FIND_LINKS=%q\n\tRPM_VER=%q\n\n" \
"$(name)" "$(PYTHONPATH)" "$(PIP_FIND_LINKS)" "$(RPM_VER)"
.PHONY: lint
lint:
uv run isort --check-only src/ tests/
uv run ruff check src/ tests/
uv run autopep8 --diff --recursive src/ tests/
.PHONY: typecheck
typecheck:
uv run pyright src/
.PHONY: test
test:
uv run pytest -v
.PHONY: check
check: lint typecheck test
.PHONY: coverage
coverage:
uv run pytest -v --cov . --cov-report=term-missing
.PHONY: format
format:
uv run isort src/ tests/
uv run autopep8 --in-place --recursive src/ tests/
uv run ruff check --fix src/ tests/
.PHONY: run
run:
uv sync --group dev
uv run "$(name)"
.PHONY: build
build:
uv build || python3 -m build
mkdir -p "$(PIP_FIND_LINKS)/"
cp dist/*.whl "$(PIP_FIND_LINKS)/"
.PHONY: rpmprep
rpmprep:
@[ -n "$(RPM_VER)" ] || { echo "Error: RPM_VER could not be determined (no release tags found)."; exit 1; }
uv build --sdist || python3 -m build --sdist
cp rpm/* dist/
mv "dist/$(name).spec.in" "dist/$(name).spec"
sed -i "s|^Version:.*|Version: $(RPM_VER)|g" "dist/$(name).spec"
sed -i "s|^Release:.*|Release: $(RPM_REV)%{?dist}|g" "dist/$(name).spec"
rpmbuild --define "_sourcedir $(TOP)/dist" --define "_srcrpmdir $(TOP)/dist" --define "_rpmdir $(TOP)/dist" \
-bs "dist/$(name).spec"
.PHONY: srpm
srpm: rpmprep
rm -f "$(outdir)"/*.rpm
rpmbuild --define "_sourcedir $(TOP)/dist" --define "_srcrpmdir $(outdir)" \
-bs "dist/$(name).spec"
.PHONY: rpm
rpm: srpm
rpmbuild --define "_rpmdir $(TOP)/dist" --rebuild dist/*.src.rpm
mv dist/noarch/* dist/
rmdir dist/noarch
.PHONY: rpmmock
rpmmock: srpm
mock --rebuild dist/*.src.rpm --resultdir=dist/ # --no-cleanup-after
.PHONY: release
release:
@[ -n "$(V)" ] || { echo "Error: V is not set. Usage: make V=X.Y.Z release"; exit 1; }
@uv run python3 -u release.py "$(V)"
.PHONY: clean
clean:
# -uv run coverage erase
rm -f .coverage
rm -rf dist/*
find . -depth -type d \( -name '__pycache__' -o -name '*.egg-info' -o -name '*.dist-info' \) \
-not -path './.git/*' -not -path './.venv/*' \
-exec rm -rf {} +
find . -depth -type f \( -name '*.pyc' -o -name '*.pyo' -o -name '*.pyd' -o -name '*.py,cover' \) \
-not -path './.git/*' -not -path './.venv/*' \
-exec rm -f {} +
.PHONY: distclean
distclean: clean
rm -rf .venv .ruff_cache dist .tox .pytest_cache build whl_local/* uv.lock
.PHONY: dc
dc: distclean
# https://packaging.python.org/en/latest/guides/using-testpypi/
# Upload to https://test.pypi.org/
.PHONY: test_upload
test_upload:
twine upload --repository testpypi dist/"$(name)"-*.whl dist/"$(name)"-*.tar.gz
# Upload to https://pypi.org/
.PHONY: upload
upload:
twine upload dist/"$(name)"-*.whl dist/"$(name)"-*.tar.gz