forked from ansible-collections/amazon.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtox.ini
More file actions
353 lines (326 loc) · 10 KB
/
Copy pathtox.ini
File metadata and controls
353 lines (326 loc) · 10 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
# It would be nice to merge this into pyproject.toml, unfortunately as of 4.23.2 they don't support generative environments when using TOML
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist =
ansible{2.17}-py{310,311,312}-{with_constraints,without_constraints}
ansible{2.18,2.19}-py{311,312,313}-{with_constraints,without_constraints}
ansible{2.20}-py{312,313,314}-{with_constraints,without_constraints}
[common]
collection_name = amazon.aws
collection_path = amazon/aws
format_dirs = {toxinidir}/plugins {toxinidir}/tests
lint_dirs = {toxinidir}/plugins {toxinidir}/tests
community_aws_install = sh -c 'VERSION=$(grep "^version:" {toxinidir}/galaxy.yml | cut -d" " -f2); \
if echo "$VERSION" | grep -q -- "-dev"; then BRANCH="main"; \
else MAJOR=$(echo "$VERSION" | cut -d. -f1); BRANCH="stable-$MAJOR"; fi; \
ansible-galaxy collection install "git+https://github.com/ansible-collections/community.aws.git,$BRANCH" 2>/dev/null || \
ansible-galaxy collection install git+https://github.com/ansible-collections/community.aws.git'
ansible_desc =
ansible2.17: Ansible-core 2.17
ansible2.18: Ansible-core 2.18
ansible2.19: Ansible-core 2.19
ansible2.20: Ansible-core 2.20
const_desc =
with_constraints: (With boto3/botocore constraints)
ansible_home = {envtmpdir}/ansible_home
ansible_collections_path = {[common]ansible_home}/collections
full_collection_path = {[common]ansible_home}/collections/ansible_collections/{[common]collection_path}
[testenv]
description = Run the unit tests {[common]ansible_desc}/{base_python} {[common]const_desc}
set_env =
ANSIBLE_HOME={[common]ansible_home}
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path}
# ansible_pytest_collections is more aggressive than pytest_ansible when injecting collections into the import path
# not needed if unit tests are under tests/unit/plugins rather than directly under tests/unit
# ANSIBLE_CONTROLLER_MIN_PYTHON_VERSION=3.11
# PYTEST_PLUGINS=ansible_test._util.target.pytest.plugins.ansible_pytest_collections
labels =
unit
ansible2.17-py310-with_constraints: unit-oldest
ansible2.20-py314-without_constraints: unit-newest
deps =
pytest
mock
pytest-mock
pytest-cov
pytest-ansible
pytest-xdist
pytest-memray
-rtest-requirements.txt
-rtests/unit/requirements.txt
ansible2.17: ansible-core>2.17,<2.18
ansible2.18: ansible-core>2.18,<2.19
ansible2.19: ansible-core>2.19,<2.20
ansible2.20: ansible-core>2.20,<2.21
with_constraints: -rtests/unit/constraints.txt
allowlist_externals = rsync, sh
change_dir = {[common]full_collection_path}
commands_pre =
rsync --delete --filter=':- .gitignore' --exclude=/.git -qraugpo {toxinidir}/ {[common]full_collection_path}/
{[common]community_aws_install}
commands =
pytest \
--cov \
--cov-report html \
--cov-report xml \
--ansible-host-pattern localhost \
{posargs:tests/unit/}
[testenv:clean]
description = Remove test results and caches
allowlist_externals = rm, find
deps = coverage
skip_install = true
change_dir = {toxinidir}
commands_pre =
commands =
coverage erase
find .tox -name coverage.xml -delete
rm -rf tests/output/ htmlcov/ .mypy_cache/ complexity/ .ruff_cache/
[testenv:diff-cover]
description = Check coverage on new code against origin/main (requires prior unit test run)
labels = coverage
deps =
diff-cover
allowlist_externals = sh
passenv = DIFF_COMPARE_BRANCH
set_env =
DIFF_COMPARE_BRANCH={env:DIFF_COMPARE_BRANCH:origin/main}
change_dir = {toxinidir}
commands =
sh -c 'COVERAGE_FILE=$(find .tox -path "*/ansible_collections/amazon/aws/coverage.xml" -type f -printf "%T@ %p\n" | sort -rn | head -1 | cut -d" " -f2-); \
if [ -z "$COVERAGE_FILE" ]; then \
echo "Error: No coverage.xml found. Run unit tests first (e.g., tox -m unit-newest)"; \
exit 1; \
fi; \
echo "Comparing against: $DIFF_COMPARE_BRANCH"; \
diff-cover \
--compare-branch="$DIFF_COMPARE_BRANCH" \
--fail-under=80 \
--format html:diff-coverage.html \
"$COVERAGE_FILE"'
[testenv:complexity-report]
labels = future-lint
description = Generate a HTML complexity report in the complexity directory
deps =
flake8-pyproject
flake8-html
change_dir = {toxinidir}
commands_pre =
commands =
-flake8 \
--select C90 \
--max-complexity 10 \
--format=html \
--htmldir={posargs:complexity} \
{posargs:{[common]lint_dirs}}
[testenv:ansible-lint]
labels = lint
description = Run ansible-lint
deps =
ansible-lint >= 25.1.2
jmespath
change_dir = {toxinidir}
commands_pre =
commands =
ansible-lint \
--skip-list=name[missing],yaml[line-length],args[module],run-once[task],ignore-errors,sanity[cannot-ignore],run-once[play] \
--exclude=.tox/ --exclude=tests/output/ \
{posargs:{[common]lint_dirs}}
[testenv:black]
labels = format
description = Apply "black" formatting
depends =
flynt, isort
deps =
black >=23.0, <24.0
change_dir = {toxinidir}
commands_pre =
commands =
black {posargs:{[common]format_dirs}}
[testenv:black-lint]
labels = lint
description = Lint against "black" formatting standards
deps =
{[testenv:black]deps}
change_dir = {toxinidir}
commands_pre =
commands =
black --check --diff {posargs:{[common]format_dirs}}
[testenv:isort]
labels = format
description = Sort imports
deps =
isort
change_dir = {toxinidir}
commands_pre =
commands =
isort {posargs:{[common]format_dirs}}
[testenv:isort-lint]
labels = lint
description = Lint for import sorting
deps =
{[testenv:isort]deps}
change_dir = {toxinidir}
commands_pre =
commands =
isort --check-only --diff {posargs:{[common]format_dirs}}
[testenv:flynt]
labels = format
description = Apply flint (f-string) formatting
deps =
flynt
change_dir = {toxinidir}
commands_pre =
commands =
flynt {posargs:{[common]format_dirs}}
[testenv:flynt-lint]
labels = lint
description = Run flint (f-string) linting
deps =
flynt
change_dir = {toxinidir}
commands_pre =
commands =
flynt --dry-run --fail-on-change {posargs:{[common]format_dirs}}
[testenv:flake8-lint]
labels = lint
description = Run FLAKE8 linting
deps =
flake8
flake8-pyproject
change_dir = {toxinidir}
commands_pre =
commands =
flake8 {posargs:{[common]format_dirs}}
[testenv:pylint-cyclomatic-complexity]
labels = complexity
description = Use pylint to evaluate McCabe cyclomatic complexity (fail if >15, warn if >10)
deps =
pylint
change_dir = {toxinidir}
commands =
# Warn if complexity > 10
-pylint \
--load-plugins=pylint.extensions.mccabe \
--disable=all \
--enable too-complex \
--max-complexity=10 \
{posargs:{[common]lint_dirs}}
# Fail if complexity > 15
pylint \
--load-plugins=pylint.extensions.mccabe \
--disable=all \
--enable too-complex \
--max-complexity=15 \
{posargs:{[common]lint_dirs}}
[testenv:flake8-cognitive-complexity]
labels = complexity
description = Check cognitive complexity using flake8 (fail if >15, warn if >10)
deps =
flake8
flake8-pyproject
flake8-cognitive-complexity
change_dir = {toxinidir}
commands_pre =
commands =
# Warn if complexity > 10
-flake8 \
--select=CCR001 \
--max-cognitive-complexity=10 \
{posargs:{[common]lint_dirs}}
# Fail if complexity > 15
flake8 \
--select=CCR001 \
--max-cognitive-complexity=15 \
{posargs:{[common]lint_dirs}}
[testenv:pylint-lint]
labels = lint
description = Run pylint tests that are disabled by the default Ansible sanity tests
deps =
pylint
change_dir = {toxinidir}
commands_pre =
commands =
pylint \
--disable R,C,W,E \
--enable pointless-statement \
--enable consider-using-dict-items \
--enable assignment-from-no-return \
--enable no-else-continue \
--enable no-else-break \
--enable simplifiable-if-statement \
--enable pointless-string-statement \
--enable redefined-outer-name \
--enable redefined-builtin \
--enable unused-import \
{posargs:{[common]lint_dirs}}
[testenv:ruff]
description = lint source code
labels = format-future
deps =
ruff
change_dir = {toxinidir}
commands_pre =
commands =
ruff check --fix {posargs:{[common]lint_dirs}}
ruff format {posargs:{[common]lint_dirs}}
[testenv:ruff-lint]
description = lint source code
labels = future-lint
deps =
ruff
change_dir = {toxinidir}
commands_pre =
commands =
ruff check --diff --unsafe-fixes {posargs:{[common]lint_dirs}}
ruff check {posargs:{[common]lint_dirs}}
[testenv:ansible-lint-future]
labels = future-lint
description = Run ansible-lint
deps =
ansible-lint
jmespath
git+https://github.com/ansible/ansible.git@devel
shellcheck-py
commands =
ansible-lint \
{posargs:{[common]lint_dirs}}
[testenv:ansible-sanity]
labels = future-lint
description = Run latest (devel) Ansible sanity tests
deps =
git+https://github.com/ansible/ansible.git@devel
shellcheck-py
commands =
ansible-test sanity
[testenv:mypy-lint]
allowlist_externals = rsync, ln, sh
labels = future-lint
description = Run mypi type tests
set_env =
ANSIBLE_HOME={[common]ansible_home}
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path}
MYPYPATH={[common]ansible_home}
deps =
mypy
# ansible-core
git+https://github.com/ansible/ansible.git@devel
botocore
boto3
placebo
typing_extensions
commands_pre =
rsync --delete --filter=':- .gitignore' --exclude=/.git -qraugpo {toxinidir}/ {[common]full_collection_path}/
{[common]community_aws_install}
ln -s {env_site_packages_dir}/ansible {[common]ansible_collections_path}/ansible
ln -s {[common]ansible_home}/collections/ansible_collections {[common]ansible_home}/ansible_collections
commands =
# TODO: passing directories doesn't work well, it's better to pass the package
# we might want to consider manipulating posargs/directories into the package names
mypy \
--check-untyped-defs \
--namespace-packages --explicit-package-bases \
--follow-imports silent \
-p ansible_collections.amazon.aws.plugins.plugin_utils \
-p ansible_collections.amazon.aws.plugins.module_utils