-
Notifications
You must be signed in to change notification settings - Fork 343
/
tox.ini
234 lines (217 loc) · 6.67 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
# 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}
linters
[common]
format_dirs = {toxinidir}/plugins {toxinidir}/tests
lint_dirs = {toxinidir}/plugins
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)
collection_path = collections/ansible_collections/amazon/aws
collection_name = amazon.aws
[mypy]
mypy_path = {envtmpdir}/mypy
full_tmp_path = {[mypy]mypy_path}/{[common]collection_path}
[ansible-sanity]
sanity_tmp_path = {envtmpdir}/ansible-sanity
full_tmp_path = {[ansible-sanity]sanity_tmp_path}/{[common]collection_path}
[future-lint]
lint_tmp_path = {envtmpdir}/ansible-lint
full_tmp_path = {[future-lint]lint_tmp_path}/{[common]collection_path}
[testenv]
description = Run the unit tests {[common]ansible_desc}/{base_python} {[common]const_desc}
labels = unit
deps =
pytest
pytest-cov
pytest-ansible
-rtest-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
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/}
[testenv:clean]
description = Remove test results and caches
allowlist_externals = rm
deps = coverage
skip_install = true
commands =
coverage erase
rm -rf tests/output/ htmlcov/ .mypy_cache/ complexity/
[testenv:complexity-report]
labels = lint
description = Generate a HTML complexity report in the complexity directory
deps =
flake8-pyproject
flake8-html
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
commands =
ansible-lint {posargs:{[common]lint_dirs}}
[testenv:black]
labels = format
description = Apply "black" formatting
depends =
flynt, isort
deps =
black >=23.0, <24.0
commands =
black {posargs:{[common]format_dirs}}
[testenv:black-lint]
labels = lint
description = Lint against "black" formatting standards
deps =
{[testenv:black]deps}
commands =
black -v --check --diff {posargs:{[common]format_dirs}}
[testenv:isort]
labels = format
description = Sort imports
deps =
isort
commands =
isort {posargs:{[common]format_dirs}}
[testenv:isort-lint]
labels = lint
description = Lint for import sorting
deps =
{[testenv:isort]deps}
commands =
isort --check-only --diff {posargs:{[common]format_dirs}}
[testenv:flynt]
labels = format
description = Apply flint (f-string) formatting
deps =
flynt
commands =
flynt {posargs:{[common]format_dirs}}
[testenv:flynt-lint]
labels = lint
description = Run flint (f-string) linting
deps =
flynt
commands =
flynt --dry-run --fail-on-change {posargs:{[common]format_dirs}}
[testenv:flake8-lint]
labels = lint
description = Run FLAKE8 linting
deps =
flake8
flake8-pyproject
commands =
flake8 {posargs:{[common]format_dirs}}
[testenv:pylint-lint]
labels = future-lint
description = Run pylint tests that are disabled by the default Ansible sanity tests
deps =
pylint
commands =
pylint \
--disable R,C,W,E \
--enable consider-using-dict-items,assignment-from-no-return,no-else-continue,no-else-break,simplifiable-if-statement,pointless-string-statement,redefined-outer-name,redefined-builtin \
{posargs:{[common]lint_dirs}}
[testenv:ansible-lint-future]
allowlist_externals = echo,cd,rm,mkdir,ln,ls
labels = future-lint
description = Run ansible-lint
# ansible-lint expects us to be installed into ansible_collections/amazon/aws
# by default we're checked out into amazon.aws
set_env =
ANSIBLE_HOME={[future-lint]lint_tmp_path}
commands_pre =
rm -rf {[future-lint]lint_tmp_path}
mkdir -p {[future-lint]full_tmp_path}
rm -d {[future-lint]full_tmp_path}
ln -s {toxinidir} {[future-lint]full_tmp_path}
ansible-galaxy collection install git+https://github.com/ansible-collections/community.aws.git
ansible-galaxy collection install -r tests/integration/requirements.yml
deps =
ansible-lint
jmespath
git+https://github.com/ansible/ansible.git@devel
shellcheck-py
commands =
cd {[future-lint]full_tmp_path}
ansible-lint --skip-list=name[missing],args[module],ignore-errors,yaml[line-length] {posargs:tests/integration/targets}
[testenv:ansible-sanity]
allowlist_externals = echo,cd,rm,mkdir,ln,ls
labels = future-lint
description = Run latest (devel) Ansible sanity tests
# ansible-sanity expects us to be installed into ansible_collections/amazon/aws
# by default we're checked out into amazon.aws
commands_pre =
rm -rf {[ansible-sanity]sanity_tmp_path}
mkdir -p {[ansible-sanity]full_tmp_path}
rm -d {[ansible-sanity]full_tmp_path}
ln -s {toxinidir} {[ansible-sanity]full_tmp_path}
deps =
git+https://github.com/ansible/ansible.git@devel
shellcheck-py
commands =
cd {[ansible-sanity]full_tmp_path}
ansible-test sanity
[testenv:mypy-lint]
allowlist_externals = echo,cd,rm,mkdir,ln
labels = future-lint
description = Run mypi type tests
set_env =
MYPYPATH={envtmpdir}/mypy
deps =
mypy
# ansible-core
git+https://github.com/ansible/ansible.git@devel
botocore
boto3
placebo
typing_extensions
commands_pre =
rm -rf {[mypy]mypy_path}
mkdir -p {[mypy]full_tmp_path}
rm -d {[mypy]full_tmp_path}
ln -s {toxinidir} {[mypy]full_tmp_path}
# Devel version of Ansible includes more typing hints, add it to MYPYPATH
ln -s {env_site_packages_dir}/ansible {[mypy]mypy_path}/ansible
commands =
cd {[mypy]full_tmp_path}
# 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
# {posargs:plugins/module_utils plugins/plugin_utils}