-
Notifications
You must be signed in to change notification settings - Fork 345
/
Copy pathtox.ini
279 lines (257 loc) · 7.56 KB
/
tox.ini
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
# 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.15}-py{39,310,311}-{with_constraints,without_constraints}
ansible{2.16,2.17}-py{310,311,312}-{with_constraints,without_constraints}
ansible{2.18}-py{311,312,313}-{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
ansible_desc =
ansible2.15: Ansible-core 2.15
ansible2.16: Ansible-core 2.16
ansible2.17: Ansible-core 2.17
ansible2.18: Ansible-core 2.18
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
deps =
pytest
mock
pytest-mock
pytest-cov
pytest-ansible
pytest-xdist
-rtest-requirements.txt
-rtests/unit/requirements.txt
ansible2.15: ansible-core>2.15,<2.16
ansible2.16: ansible-core>2.16,<2.17
ansible2.17: ansible-core>2.17,<2.18
ansible2.18: ansible-core>2.18,<2.19
with_constraints: -rtests/unit/constraints.txt
allowlist_externals = rsync
change_dir = {[common]full_collection_path}
commands_pre =
rsync --delete --exclude=.tox -qraugpo {toxinidir}/ {[common]full_collection_path}/
ansible-galaxy collection install git+https://github.com/ansible-collections/community.aws.git
commands =
pytest \
--cov-report html \
--cov plugins/callback \
--cov plugins/inventory \
--cov plugins/lookup \
--cov plugins/module_utils \
--cov plugins/modules \
--cov plugins/plugin_utils \
--cov plugins \
--ansible-host-pattern localhost \
{posargs:tests/unit/}
[testenv:clean]
description = Remove test results and caches
allowlist_externals = rm
deps = coverage
skip_install = true
change_dir = {toxinidir}
commands_pre =
commands =
coverage erase
rm -rf tests/output/ htmlcov/ .mypy_cache/ complexity/ .ruff_cache/
[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 >= 24.7.0
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] \
{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-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 = lint-future
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
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 --exclude=.tox -qraugpo {toxinidir}/ {[common]full_collection_path}/
ansible-galaxy collection install git+https://github.com/ansible-collections/community.aws.git
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