-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
207 lines (185 loc) · 6.28 KB
/
Copy pathTaskfile.yaml
File metadata and controls
207 lines (185 loc) · 6.28 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
# https://taskfile.dev
#
# This is a generated file. We do not suggest to edit it.
# Instead, create a file `TaskfileCustom.yaml` and add your additions there.
---
version: '3'
dotenv: ['.copier-answers.env', '.env']
vars:
# $package_dir is expanded by the shell, from the .copier-answers.env entry
# that `dotenv` above loads. An exported package_dir of your own outranks that
# entry, which the `package:exists` task below turns into a loud failure
# instead of a check that quietly looks at nothing.
PACKAGE: $package_dir
DIST_DIR: dist
includes:
custom:
taskfile: ./TaskfileCustom.yaml
optional: true
flatten: true
plugin:
taskfile: .tasks-plugin.yml
optional: true
flatten: true
tasks:
default:
summary: |
Just a list of documented tasks
silent: true
cmds:
- task --list
# {{{ preparation tasks
# These are plain internal tasks rather than a YAML anchor on purpose. A merge
# key only supplies keys the mapping does not already have, so a task with any
# `deps` of its own silently loses everything the anchor meant to add - which
# is what `build` used to do. Naming them in a `deps` list composes instead.
package:exists:
internal: true
summary: |
fail loudly when PACKAGE does not name a directory
run: once
preconditions:
- sh: '[ -d "$package_dir" ]'
msg: >
The package directory does not exist. Its name comes from the
package_dir entry of .copier-answers.env, and an exported package_dir
of your own silently outranks that entry - unset it. Without this
check, an empty value dropped the package from every command line and
the checks passed having looked at nothing but tests.
prepare:
internal: true
summary: |
everything a check or format task needs first: the virtualenv, a package
directory that exists, and the directory the reports are written to
run: once
deps:
- poetry:install
- package:exists
cmds:
- mkdir -p {{.DIST_DIR}}/coverage
poetry:install:
desc: Install dependencies managed by Poetry
run: once
cmds:
- poetry install
# Neither format task depends on `poetry:install`, unlike the check tasks.
# `format:fix` is what the Claude Code PostToolUse hook runs after every edit,
# and `poetry install` refuses to run while pyproject.toml has been changed
# without the lock file being regenerated - exactly what a dependency bump or
# a template update looks like. Formatting would then quietly stop for the
# rest of the session. On a clone with no virtualenv yet, run `task check` or
# `task poetry:install` first.
format:fix:
desc: Format Python files and fix obvious issues
deps:
- package:exists
cmds:
- poetry run ruff format tests {{.PACKAGE}}
- poetry run ruff check tests {{.PACKAGE}} --fix-only
format:fix-unsafe:
desc: Format Python files and fix 'unsafe' issues
deps:
- package:exists
cmds:
- poetry run ruff format tests {{.PACKAGE}}
- poetry run ruff check tests {{.PACKAGE}} --fix-only --unsafe-fixes
clean:
desc: Removes dist, *.pyc and some caches
cmds:
- rm -rf {{.DIST_DIR}} .mypy_cache .pytest_cache
- find . -name "*.pyc" -print0 | xargs -0 rm || echo ""
# }}}
# {{{ check tasks
check:
desc: Run whole test suite incl. unit and integration tests
cmds:
- task: check:linters
- task: check:pytest
check:linters:
desc: Run all linter and static code analysis tests
cmds:
- task: check:ruff
- task: check:mypy
- task: check:deptry
- task: check:trivy
check:pytest:
desc: Run unit and integration tests
platforms: [darwin, linux, windows]
deps:
- prepare
cmds:
# --memray is not used on windows
- platforms: [windows]
cmd: >
poetry run pytest --junitxml={{.JUNIT_FILE}}
--cov-report term --cov-report xml:{{.COVERAGE_FILE}}
--cov-report html:{{.COVERAGE_DIR}} --cov={{.PACKAGE}}
--html={{.HTML_FILE}} --self-contained-html
- platforms: [darwin, linux]
cmd: >
poetry run pytest --memray --junitxml={{.JUNIT_FILE}}
--cov-report term --cov-report xml:{{.COVERAGE_FILE}}
--cov-report html:{{.COVERAGE_DIR}} --cov={{.PACKAGE}}
--html={{.HTML_FILE}} --self-contained-html
- cmd: >
poetry run genbadge coverage -l
-i {{.COVERAGE_FILE}} -o {{.BADGE_COVERAGE}}
- cmd: >
poetry run genbadge tests -l
-i {{.JUNIT_FILE}} -o {{.BADGE_TESTS}}
vars:
BADGE_COVERAGE: ./{{.DIST_DIR}}/badge-coverage.svg
BADGE_TESTS: ./{{.DIST_DIR}}/badge-tests.svg
COVERAGE_DIR: ./{{.DIST_DIR}}/coverage
COVERAGE_FILE: ./{{.DIST_DIR}}/coverage.xml
HTML_FILE: ./{{.DIST_DIR}}/pytest.html
JUNIT_FILE: ./{{.DIST_DIR}}/junit-pytest.xml
check:mypy:
desc: Complain about typing errors
deps:
- prepare
cmds:
- poetry run mypy -p tests -p {{.PACKAGE}} --junit-xml {{.JUNIT_FILE}}
vars:
JUNIT_FILE: ./{{.DIST_DIR}}/junit-mypy.xml
check:trivy:
desc: Scan for vulnerabilities using Trivy
deps:
- prepare
cmds:
- >
poetry run trivy fs
--include-dev-deps
--scanners vuln
--skip-files .poetry/plugins/poetry.lock
--exit-code 1
.
check:deptry:
desc: Complain about unused or missing dependencies
deps:
- prepare
cmds:
- poetry run deptry .
check:ruff:
desc: Complain about everything else
deps:
- prepare
cmds:
- poetry run ruff check --exit-zero tests {{.PACKAGE}} {{.XML_PARAMS}}
- poetry run ruff check --output-format=concise tests {{.PACKAGE}}
- poetry run ruff format --check tests {{.PACKAGE}}
vars:
JUNIT_FILE: ./{{.DIST_DIR}}/junit-ruff.xml
XML_PARAMS: --output-format junit --output-file {{.JUNIT_FILE}}
# }}}
build:
desc: Build a tarball and a wheel package
# `prepare` is deliberately not among these: `build` does not write into
# dist/coverage, and it would race with `clean`, since Task runs deps in
# parallel.
deps:
- poetry:install
- clean
cmds:
- poetry build
- poetry export --without=dev -f requirements.txt >dist/requirements.txt