-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskfile.yaml
More file actions
140 lines (122 loc) · 4.14 KB
/
Copy pathtaskfile.yaml
File metadata and controls
140 lines (122 loc) · 4.14 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
version: '3'
vars:
MATRIX: '{{ .MATRIX | default "0" }}'
VERSIONS: '{{ .VERSIONS | default "" }}'
PY_FROM_PYPROJECT:
sh: |
uv run --no-sync --isolated --python 3.13 - <<'PY'
import re, sys, pathlib, tomllib
data = tomllib.loads(pathlib.Path("pyproject.toml").read_text())
cl = data.get("project", {}).get("classifiers", [])
vers = [m.group(1) for s in cl if (m:=re.search(r"Python :: (\d\.\d+)$", s))]
print(" ".join(sorted(set(vers))))
PY
ALL_PY: '{{ .PY_FROM_PYPROJECT }}'
PY_CURRENT:
sh: |
python - <<'PY'
import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")
PY
PY_LIST:
sh: |
if [ -n "{{.VERSIONS}}" ]; then
echo "{{.VERSIONS}}" | tr ',' ' '
elif [ "{{.MATRIX}}" = "1" ]; then
echo "{{ .ALL_PY }}"
else
echo "{{ .PY_CURRENT }}"
fi
SELECTED_PY_VERSIONS:
sh: |
if [ -n "{{.VERSIONS}}" ]; then
echo "{{.VERSIONS}}" | tr ',' ' '
elif [ "{{.MATRIX}}" = "1" ]; then
echo "{{ .PY_LIST }}"
else
echo "{{ .PY_CURRENT }}"
fi
tasks:
setup:
desc: Install deps
cmd: uv sync --extra dev --inexact --quiet
default:
desc: Run all checks
deps: [ typecheck, lint, test ]
license:
cmd: reuse annotate --license MIT --copyright "Arseny Boykov (Bobronium) <hi@bobronium.me>" -y $(date +%Y)-present
format:
desc: Format
cmd: uv run --no-project ruff format src tests
lint:
desc: Lint
deps: [ format ]
cmd: uv run --no-project ruff check src tests --fix
clear:
desc: Clear __pycache__
cmds:
- rm -rf ./**/*/__pycache__ ./**/__pycache__ ./__pycache__
silent: true
typecheck:
desc: Typecheck
env:
MYPYPATH: src
cmd: |
bash -euo pipefail << 'PY'
run_typecheck () {
local PYV="$1"
echo "▶ Typechecking Python $PYV"
uv sync --inexact --quiet --extra typecheck
uv run --no-sync mypy tests/api --python-version "$PYV"
uv run --no-sync pyright tests/api --pythonversion "$PYV"
}
if [ "{{.MATRIX}}" != "1" ] && [ -z "{{.VERSIONS}}" ]; then
run_typecheck "{{ .PY_CURRENT }}"; exit 0; fi
for v in {{ .SELECTED_PY_VERSIONS }}; do run_typecheck "$v"; done
PY
test:
desc: Run tests
cmd: |
bash -euo pipefail << 'PY'
if [ "{{.MATRIX}}" != "1" ] && [ -z "{{.VERSIONS}}" ]; then
echo "▶ Tests on current environment"
uv sync --inexact --quiet --extra test --no-install-project
uv pip install . --quiet
uv run --no-sync pytest
exit 0
fi
for V in {{ .SELECTED_PY_VERSIONS }}; do
echo "▶ Tests on Python $V"
VENV=".task/venv${V}"
if [ ! -d "$VENV" ]; then uv venv --clear --no-project --python "$V" "$VENV"; fi
ACT="$VENV/bin/activate"; [ -f "$VENV/Scripts/activate" ] && ACT="$VENV/Scripts/activate"
. "$ACT"
uv sync --active --inexact --quiet --extra test --no-install-project
uv pip install . --quiet
uv run --no-sync --active pytest tests {{.CLI_ARGS}}
deactivate
done
PY
build:wheel:
desc: Regular optimized wheel (LTO + -O3 by default)
cmds:
- python -m pip install -U build
- COPIUM_LTO=${COPIUM_LTO:-1} COPIUM_O3=${COPIUM_O3:-1} python -m build --wheel
pgo:train:
desc: Two-stage PGO training pass (instrument + pytest + merge)
cmds:
- chmod +x tools/pgo_train.sh
- COPIUM_PGO_PROFILE_DIR={{.PROFILE_DIR}} bash tools/pgo_train.sh
pgo:build:
desc: Final wheel compiled with PGO profile data
cmds:
- python -m pip install -U build
- COPIUM_PGO=use COPIUM_PGO_PROFILE_DIR={{.PROFILE_DIR}} python -m build --wheel
compile_commands:
desc: Generate compile_commands.json for C files and CPython sources
vars:
PYTHON_VERSION: '{{ .PY | default .PY_CURRENT }}'
CPYTHON_SRC: '{{ .CPYTHON_SRC | default "" }}'
env:
CPYTHON_SRC: '{{ .CPYTHON_SRC }}'
cmds:
- uv run --no-sync --isolated --python {{ .PYTHON_VERSION }} python tools/generate_compile_commands.py