-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskfile.yml
More file actions
435 lines (397 loc) · 11.1 KB
/
taskfile.yml
File metadata and controls
435 lines (397 loc) · 11.1 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
version: '3.38'
includes:
ci:
taskfile: .ci/taskfile.ci.yml
set: [nounset, pipefail, errexit, xtrace]
vars:
PROJECT_NAME: python-aisec
REPO_ROOT:
sh: >-
echo -n "${CI_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}"
PYTHON_MIN_VERSION: >-
3.9
PUBLISH_URL_PYPI_MAIN: https://upload.pypi.org/legacy/
PUBLISH_URL_PYPI_TEST: https://test.pypi.org/legacy/
env:
UV_NATIVE_TLS: true
UV_DEFAULT_INDEX: https://pypi.org/simple/
HATCH_ENV_TYPE_VIRTUAL_UV_PATH:
sh: |
command -v uv || true
tasks:
default:
desc: "Show task --help and task --list"
interactive: true
aliases:
- help
- list
cmds:
- task --help
- task --list
setup:uv:
desc: "Install 'pipx' and 'uv' (Python Project & Dependency Management)"
interactive: true
# language=sh
cmds:
- |
if !command -v pipx &>/dev/null; then
python3 -m pip install pipx --user
fi
python3 -m pipx install uv
status:
- command -v uv
setup:ruff:
desc: "Install 'Ruff' (Python Linting and Formatting) using 'uv'"
deps:
- setup:uv
# language=sh
cmds:
- uv tool install --upgrade ruff
preconditions:
- command -v uv
status:
- command -v ruff
setup:pre-commit:
desc: "Install pre-commit and pre-commit hooks"
# language=sh
cmds:
- uv tool install pre-commit
- uv tool run pre-commit install --install-hooks
preconditions:
- command -v uv
# language=sh
status:
- command -v pre-commit
- test -f .git/hooks/pre-commit
- grep -q '\.pre-commit-config\.yaml' .git/hooks/pre-commit
sync:
desc: "uv sync --all-extras"
run: once
silent: true
# language=sh
cmds:
- >-
{{if not .SKIP_SYNC}}uv sync --all-extras {{.SYNC_ARGS}} {{.CLI_ARGS}}{{end}}
- |
cat <<'EOT' | tee requirements.txt requirements.in &>/dev/null
#
# THIS FILE IS AUTO-GENERATED
# YOUR CHANGES WILL BE OVERWRITTEN
# DO NOT MANUALLY EDIT THIS FILE
#
# Add dependencies with 'uv add':
#
# for package/release dependencies:
# uv add package_name
#
# for development dependencies:
# uv add --dev package_name
#
# Regenerate this file with:
# 'task sync' or 'task export'
EOT
- uv export --frozen --no-emit-project --no-hashes >> requirements.txt
- |
uv tree --frozen --depth 1 --no-dev --no-default-groups |
awk 'NR==1 { next; } { print $2; }' |
sort -b >> requirements.in
export:
run: once
desc: "uv export > requirements.txt"
cmds:
- task: sync
vars:
SKIP_SYNC: true
dep:
desc: "Ensure Python package dependencies are installed"
deps:
- task: setup:uv
# language=sh
cmds:
- uv tool install --upgrade hatch
- task: export
update:
desc: "Update Python Dependencies"
# language=sh
cmds:
- uv tool install --upgrade hatch
- uv sync --all-extras --reinstall --upgrade
- task: export
vars:
SKIP_SYNC: true
deps:
- task: setup:uv
venv:
desc: "(Re)Create a Python Virtual Environment (.venv)"
aliases:
- .venv
- virtualenv
summary: |-
(Re)Create a '.venv' directory using the 'uv venv' command.
Optionally pass additional arguments to uv using 'task venv -- <EXTRA_UV_VENV_OPTS>'
Examples:
task venv
task -v venv -- --python 3.13 --native-tls
deps:
- task: setup:uv
# language=sh
cmds:
- uv venv --seed --prompt {{.PROJECT_NAME}} {{.CLI_ARGS}}
- task: dep
preconditions:
- command -v uv
_hatch:
internal: true
run: once
env:
UV_FROZEN: 1
# language=sh
cmds:
- uv tool install hatch
preconditions:
- command -v uv
status:
- command -v hatch
clean:
desc: "Remove all local build and test artifacts"
run: once
deps:
- task: _hatch
# language=sh
cmds:
- |
cd "{{.REPO_ROOT}}"
uv tool run hatch clean
rm -rf .mypy_cache/ .pytest_cache/ .coverage
[[ -d dist ]] && find dist \! -name .gitignore -mindepth 1 | xargs rm -rf;
find . -type d \( \
-name __pycache__ \
-or -name ".*cache" \
-or -name ".coverage*" \
\) -exec rm -rf "{}" "+"
find . -type f \( -name "*.pyc" -or -name "*.log" -or -name "*.tmp" \) -exec rm -f "{}" "+"
preconditions:
- command -v hatch
test:unit:
desc: "Run project unit tests"
# language=sh
cmds:
- >-
uv run --all-extras --frozen pytest
-ra
--tb=short
--numprocesses=auto
--cov-report=term-missing
--ignore=tests/*/{functional,performance}
{{.CLI_ARGS}}
preconditions:
- command -v uv
test:full:
desc: "Run test suite with all currently supported Python Versions"
deps:
- task: _hatch
# language=sh
cmds:
- uv run --frozen hatch test --all --cover
test:mypy:
desc: "Run mypy type-checking tests"
# language=sh
cmds:
- uv run --all-extras --frozen mypy check {{.CLI_ARGS}}
test:pyright:
desc: "Run mypy & pyright type-checking tests"
# language=sh
cmds:
- uv run --all-extras --frozen pyright {{.CLI_ARGS}}
build:
desc: "Build the project artifacts"
deps:
- task: _hatch
- task: clean
env:
UV_FROZEN: 1
# language=sh
cmds:
- uv run --frozen hatch build
build:inspect:
desc: "Build and Inspect project artifacts"
deps:
- task: build
# language=sh
cmds:
- |
latest_whl="$(find dist/ -name "*.whl" | sort --version-sort | tail -n 1 | xargs basename)" &&
whl_dst="${latest_whl%%-py3-none-any.whl}_py3_none_any_whl" &&
{ [[ ! -d "dist/${whl_dst}" ]] || rm -rf "dist/${whl_dst}"; } &&
unzip -d "dist/${whl_dst}" "dist/${latest_whl}"
- |
latest_tar_gz="$(find dist/ -name "*.tar.gz" | sort --version-sort | tail -n 1 | xargs basename)" &&
tar_gz_dst="${latest_tar_gz%%.tar.gz}_tar_gz"
{ [[ ! -d "dist/${tar_gz_dst}" ]] || rm -rf "dist/${tar_gz_dst}"; } &&
mkdir -p "dist/${tar_gz_dst}" &&
tar -C "dist/${tar_gz_dst}" --strip-components=1 -zxvf "dist/${latest_tar_gz}"
bump:
desc: "Bump the project version. See 'hatch version' docs: https://hatch.pypa.io/latest/version/"
deps:
- task: _hatch
env:
UV_FROZEN: 1
# language=sh
cmds:
- uv run --frozen hatch version {{.CLI_ARGS | default "dev" }}
_publish:
internal: true
silent: false
deps:
- task: _hatch
- task: build
env:
UV_FROZEN: 1
HATCH_INDEX_REPO: "{{.HATCH_INDEX_REPO}}"
requires:
vars:
- HATCH_INDEX_REPO
# language=sh
cmds:
- uv run --frozen .ci/scripts/check_version.py --index={{.HATCH_INDEX_REPO}}
- uv run --frozen hatch publish
publish:test.pypi.org:
desc: "Publish project artifacts to test.pypi.org"
silent: false
cmds:
- task: _publish
vars:
HATCH_INDEX_REPO: test
publish:pypi.org:
desc: "Publish project artifacts to pypi.org"
cmds:
- task: _publish
vars:
HATCH_INDEX_REPO: main
fmt:
desc: "Automatically format project files"
deps:
- task: fmt:py
- task: fmt:yaml
fmt:py:
desc: "Automatically format Python files"
# language=sh
cmds:
- ruff format .
fmt:yaml:
desc: "Automatically format YAML files"
# language=sh
cmds:
- yamlfmt -conf {{.REPO_ROOT}}/.yamlfmt.yaml -gitignore_excludes -dstar "**.yaml" "**.yml"
lint:
desc: "ruff check --fix --preview --unsafe-fixes"
# language=sh
cmds:
- ruff check --fix --preview --unsafe-fixes
pre-commit:
desc: "Run pre-commit hooks"
# language=sh
cmds:
- uv tool run pre-commit run -v
preconditions:
- command -v pre-commit
sec:
desc: "Run Security Linters"
cmds:
- task: sec:bandit
- task: sec:trufflehog
sec:bandit:
desc: "Run Bandit security linter"
vars:
BANDIT_SEVERITY_LEVEL: medium
BANDIT_CONFIDENCE_LEVEL: medium
BANDIT_SCAN_PATH: >-
{{.REPO_ROOT}}
cmds:
# language=sh
- >-
uvx --from="bandit[toml]" bandit
--configfile pyproject.toml
--confidence-level {{.BANDIT_CONFIDENCE_LEVEL}}
--severity-level {{.BANDIT_SEVERITY_LEVEL}}
--recursive {{.BANDIT_SCAN_PATH}}
preconditions:
- command -v uv
sec:trufflehog:
desc: "Run Trufflehog security linter"
# language=sh
cmds:
- >-
uvx trufflehog --regex --entropy=true
--exclude_paths .trufflehogignore .
preconditions:
- command -v git
- command -v uv
readme:generate-toc:
desc: Generate the Table of Contents in README.md
# language=sh
cmds:
- uvx --from md-toc md_toc --in-place cmark README.md
preconditions:
- sh: command -v uvx
msg: "Command not found: uvx"
readme:render:
desc: Render README.md using PyPi's Markdown to HTML Renderer (readme-renderer)
deps:
- task: readme:generate-toc
# language=sh
cmds:
- mkdir -p .local
- uv run --all-extras --frozen -m readme_renderer -f md README.md -o .local/index.html
- screen -dmS http.server .venv/bin/python3 -m http.server -d .local
- open http://[::]:8000
- screen -r http.server
keyring:update-key:main:
desc: Update {{.PUBLISH_URL_PYPI_MAIN}} API Token using 'keyring' (secure password storage)
# language=sh
cmds:
- >-
uvx keyring set {{.PUBLISH_URL_PYPI_MAIN}} __token__
keyring:update-key:test:
desc: Update {{.PUBLISH_URL_PYPI_TEST}} API Token using 'keyring' (secure password storage)
# language=sh
cmds:
- >-
uvx keyring set {{.PUBLISH_URL_PYPI_TEST}} __token__
github:sync:
set: [xtrace, nounset, pipefail, errexit]
# language=sh
cmds:
- |
rsync \
{{.CLI_ARGS}} \
--checksum --recursive \
#--update --recursive \
--links --safe-links --perms --times --crtimes --open-noatime --group --owner \
--one-file-system --delete --fsync \
--debug=FILTER \
--filter="- /.gitlab-ci.yml" \
--filter="- /tests/integration_tests/***" \
--filter="- /tests/config/***" \
--filter="+ /tests/***" \
--filter="+ LICENSE" \
--filter="+ README.md" \
--filter="+ CHANGELOG.md" \
--filter="+ src/***" \
--filter="+ examples/***" \
--filter="+ .*ignore" \
--filter="+ /.ci/***" \
--filter="+ /*.y*ml" \
--filter="+ /*.toml" \
--filter="+ /uv.lock" \
--filter="- *" \
* .* \
"{{.DEST_DIR}}"
preconditions:
- sh: test -n "{{.DEST_DIR}}"
msg: "Destination directory must be set"
- sh: test -d "{{.DEST_DIR}}"
msg: "Destination directory {{.DEST_DIR}} does not exist"
requires:
vars:
- DEST_DIR