| 1 |
# 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 |
| 2 |
|
| 3 |
[tox] |
| 4 |
skipsdist = True |
| 5 |
skip_missing_interpreters = True |
| 6 |
envlist = |
| 7 |
ansible{2.17}-py{310,311,312}-{with_constraints,without_constraints} |
| 8 |
ansible{2.18,2.19}-py{311,312,313}-{with_constraints,without_constraints} |
| 9 |
ansible{2.17}-py{312,313,314}-{with_constraints,without_constraints} |
| 10 |
|
| 11 |
[common] |
| 12 |
collection_name = community.aws |
| 13 |
collection_path = community/aws |
| 14 |
|
| 15 |
format_dirs = {toxinidir}/plugins {toxinidir}/tests |
| 16 |
lint_dirs = {toxinidir}/plugins {toxinidir}/tests |
| 17 |
|
| 18 |
ansible_desc = |
| 19 |
ansible2.17: Ansible-core 2.17 |
| 20 |
ansible2.18: Ansible-core 2.18 |
| 21 |
ansible2.19: Ansible-core 2.19 |
| 22 |
ansible2.20: Ansible-core 2.20 |
| 23 |
const_desc = |
| 24 |
with_constraints: (With boto3/botocore constraints) |
| 25 |
|
| 26 |
ansible_home = {envtmpdir}/ansible_home |
| 27 |
ansible_collections_path = {[common]ansible_home}/collections |
| 28 |
full_collection_path = {[common]ansible_home}/collections/ansible_collections/{[common]collection_path} |
| 29 |
|
| 30 |
[testenv] |
| 31 |
description = Run the unit tests {[common]ansible_desc}/{base_python} {[common]const_desc} |
| 32 |
set_env = |
| 33 |
ANSIBLE_HOME={[common]ansible_home} |
| 34 |
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path} |
| 35 |
# ansible_pytest_collections is more aggressive than pytest_ansible when injecting collections into the import path |
| 36 |
# not needed if unit tests are under tests/unit/plugins rather than directly under tests/unit |
| 37 |
# ANSIBLE_CONTROLLER_MIN_PYTHON_VERSION=3.11 |
| 38 |
# PYTEST_PLUGINS=ansible_test._util.target.pytest.plugins.ansible_pytest_collections |
| 39 |
labels = unit |
| 40 |
deps = |
| 41 |
pytest |
| 42 |
mock |
| 43 |
pytest-mock |
| 44 |
pytest-cov |
| 45 |
pytest-ansible |
| 46 |
pytest-xdist |
| 47 |
-rtest-requirements.txt |
| 48 |
-rtests/unit/requirements.txt |
| 49 |
ansible2.17: ansible-core>2.17,<2.18 |
| 50 |
ansible2.18: ansible-core>2.18,<2.19 |
| 51 |
ansible2.19: ansible-core>2.19,<2.20 |
| 52 |
ansible2.20: ansible-core>2.20,<2.21 |
| 53 |
with_constraints: -rtests/unit/constraints.txt |
| 54 |
allowlist_externals = rsync |
| 55 |
change_dir = {[common]full_collection_path} |
| 56 |
commands_pre = |
| 57 |
rsync --delete --exclude=.tox -qraugpo {toxinidir}/ {[common]full_collection_path}/ |
| 58 |
ansible-galaxy collection install git+https://github.com/ansible-collections/amazon.aws.git |
| 59 |
commands = |
| 60 |
pytest \ |
| 61 |
--cov-report html \ |
| 62 |
--cov plugins/inventory \ |
| 63 |
--cov plugins/module_utils \ |
| 64 |
--cov plugins/modules \ |
| 65 |
--cov plugins \ |
| 66 |
--ansible-host-pattern localhost \ |
| 67 |
{posargs:tests/unit/} |
| 68 |
# We don't have these in community |
| 69 |
# --cov plugins/plugin_utils \ |
| 70 |
# --cov plugins/callback \ |
| 71 |
# --cov plugins/lookup \ |
| 72 |
|
| 73 |
[testenv:clean] |
| 74 |
description = Remove test results and caches |
| 75 |
allowlist_externals = rm |
| 76 |
deps = coverage |
| 77 |
skip_install = true |
| 78 |
change_dir = {toxinidir} |
| 79 |
commands_pre = |
| 80 |
commands = |
| 81 |
coverage erase |
| 82 |
rm -rf tests/output/ htmlcov/ .mypy_cache/ complexity/ .ruff_cache/ |
| 83 |
|
| 84 |
[testenv:complexity-report] |
| 85 |
labels = future-lint |
| 86 |
description = Generate a HTML complexity report in the complexity directory |
| 87 |
deps = |
| 88 |
flake8-pyproject |
| 89 |
flake8-html |
| 90 |
change_dir = {toxinidir} |
| 91 |
commands_pre = |
| 92 |
commands = |
| 93 |
-flake8 \ |
| 94 |
--select C90 \ |
| 95 |
--max-complexity 10 \ |
| 96 |
--format=html \ |
| 97 |
--htmldir={posargs:complexity} \ |
| 98 |
{posargs:{[common]lint_dirs}} |
| 99 |
|
| 100 |
[testenv:ansible-lint] |
| 101 |
labels = lint |
| 102 |
description = Run ansible-lint |
| 103 |
deps = |
| 104 |
ansible-lint >= 25.1.2 |
| 105 |
jmespath |
| 106 |
change_dir = {toxinidir} |
| 107 |
commands_pre = |
| 108 |
commands = |
| 109 |
ansible-lint \ |
| 110 |
--skip-list=name[missing],yaml[line-length],args[module],run-once[task],ignore-errors,sanity[cannot-ignore],run-once[play] \ |
| 111 |
{posargs:plugins} |
| 112 |
# {posargs:{[common]lint_dirs}} |
| 113 |
|
| 114 |
[testenv:black] |
| 115 |
labels = format |
| 116 |
description = Apply "black" formatting |
| 117 |
depends = |
| 118 |
flynt, isort |
| 119 |
deps = |
| 120 |
black >=23.0, <24.0 |
| 121 |
change_dir = {toxinidir} |
| 122 |
commands_pre = |
| 123 |
commands = |
| 124 |
black {posargs:{[common]format_dirs}} |
| 125 |
|
| 126 |
[testenv:black-lint] |
| 127 |
labels = lint |
| 128 |
description = Lint against "black" formatting standards |
| 129 |
deps = |
| 130 |
{[testenv:black]deps} |
| 131 |
change_dir = {toxinidir} |
| 132 |
commands_pre = |
| 133 |
commands = |
| 134 |
black --check --diff {posargs:{[common]format_dirs}} |
| 135 |
|
| 136 |
[testenv:isort] |
| 137 |
labels = format |
| 138 |
description = Sort imports |
| 139 |
deps = |
| 140 |
isort |
| 141 |
change_dir = {toxinidir} |
| 142 |
commands_pre = |
| 143 |
commands = |
| 144 |
isort {posargs:{[common]format_dirs}} |
| 145 |
|
| 146 |
[testenv:isort-lint] |
| 147 |
labels = lint |
| 148 |
description = Lint for import sorting |
| 149 |
deps = |
| 150 |
{[testenv:isort]deps} |
| 151 |
change_dir = {toxinidir} |
| 152 |
commands_pre = |
| 153 |
commands = |
| 154 |
isort --check-only --diff {posargs:{[common]format_dirs}} |
| 155 |
|
| 156 |
[testenv:flynt] |
| 157 |
labels = format |
| 158 |
description = Apply flint (f-string) formatting |
| 159 |
deps = |
| 160 |
flynt |
| 161 |
change_dir = {toxinidir} |
| 162 |
commands_pre = |
| 163 |
commands = |
| 164 |
flynt {posargs:{[common]format_dirs}} |
| 165 |
|
| 166 |
[testenv:flynt-lint] |
| 167 |
labels = lint |
| 168 |
description = Run flint (f-string) linting |
| 169 |
deps = |
| 170 |
flynt |
| 171 |
change_dir = {toxinidir} |
| 172 |
commands_pre = |
| 173 |
commands = |
| 174 |
flynt --dry-run --fail-on-change {posargs:{[common]format_dirs}} |
| 175 |
|
| 176 |
[testenv:flake8-lint] |
| 177 |
labels = lint |
| 178 |
description = Run FLAKE8 linting |
| 179 |
deps = |
| 180 |
flake8 |
| 181 |
flake8-pyproject |
| 182 |
change_dir = {toxinidir} |
| 183 |
commands_pre = |
| 184 |
commands = |
| 185 |
flake8 {posargs:{[common]format_dirs}} |
| 186 |
|
| 187 |
[testenv:pylint-lint] |
| 188 |
labels = future-lint |
| 189 |
description = Run pylint tests that are disabled by the default Ansible sanity tests |
| 190 |
deps = |
| 191 |
pylint |
| 192 |
change_dir = {toxinidir} |
| 193 |
commands_pre = |
| 194 |
commands = |
| 195 |
pylint \ |
| 196 |
--disable R,C,W,E \ |
| 197 |
--enable pointless-statement \ |
| 198 |
--enable consider-using-dict-items \ |
| 199 |
--enable assignment-from-no-return \ |
| 200 |
--enable no-else-continue \ |
| 201 |
--enable no-else-break \ |
| 202 |
--enable simplifiable-if-statement \ |
| 203 |
--enable pointless-string-statement \ |
| 204 |
--enable redefined-outer-name \ |
| 205 |
--enable redefined-builtin \ |
| 206 |
--enable unused-import \ |
| 207 |
{posargs:{[common]lint_dirs}} |
| 208 |
|
| 209 |
[testenv:ruff] |
| 210 |
description = lint source code |
| 211 |
labels = format-future |
| 212 |
deps = |
| 213 |
ruff |
| 214 |
change_dir = {toxinidir} |
| 215 |
commands_pre = |
| 216 |
commands = |
| 217 |
ruff check --fix {posargs:{[common]lint_dirs}} |
| 218 |
ruff format {posargs:{[common]lint_dirs}} |
| 219 |
|
| 220 |
[testenv:ruff-lint] |
| 221 |
description = lint source code |
| 222 |
labels = lint-future |
| 223 |
deps = |
| 224 |
ruff |
| 225 |
change_dir = {toxinidir} |
| 226 |
commands_pre = |
| 227 |
commands = |
| 228 |
ruff check --diff --unsafe-fixes {posargs:{[common]lint_dirs}} |
| 229 |
ruff check {posargs:{[common]lint_dirs}} |
| 230 |
|
| 231 |
[testenv:ansible-lint-future] |
| 232 |
labels = future-lint |
| 233 |
description = Run ansible-lint |
| 234 |
deps = |
| 235 |
ansible-lint |
| 236 |
jmespath |
| 237 |
git+https://github.com/ansible/ansible.git@devel |
| 238 |
shellcheck-py |
| 239 |
commands = |
| 240 |
ansible-lint \ |
| 241 |
{posargs:{[common]lint_dirs}} |
| 242 |
|
| 243 |
[testenv:ansible-sanity] |
| 244 |
labels = future-lint |
| 245 |
description = Run latest (devel) Ansible sanity tests |
| 246 |
deps = |
| 247 |
git+https://github.com/ansible/ansible.git@devel |
| 248 |
shellcheck-py |
| 249 |
commands = |
| 250 |
ansible-test sanity |
| 251 |
|
| 252 |
[testenv:mypy-lint] |
| 253 |
allowlist_externals = rsync,ln |
| 254 |
labels = future-lint |
| 255 |
description = Run mypi type tests |
| 256 |
set_env = |
| 257 |
ANSIBLE_HOME={[common]ansible_home} |
| 258 |
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path} |
| 259 |
MYPYPATH={[common]ansible_home} |
| 260 |
deps = |
| 261 |
mypy |
| 262 |
# ansible-core |
| 263 |
git+https://github.com/ansible/ansible.git@devel |
| 264 |
botocore |
| 265 |
boto3 |
| 266 |
placebo |
| 267 |
typing_extensions |
| 268 |
commands_pre = |
| 269 |
rsync --delete --exclude=.tox -qraugpo {toxinidir}/ {[common]full_collection_path}/ |
| 270 |
ansible-galaxy collection install git+https://github.com/ansible-collections/amazon.aws.git |
| 271 |
ln -s {env_site_packages_dir}/ansible {[common]ansible_collections_path}/ansible |
| 272 |
ln -s {[common]ansible_home}/collections/ansible_collections {[common]ansible_home}/ansible_collections |
| 273 |
commands = |
| 274 |
# TODO: passing directories doesn't work well, it's better to pass the package |
| 275 |
# we might want to consider manipulating posargs/directories into the package names |
| 276 |
mypy \ |
| 277 |
--check-untyped-defs \ |
| 278 |
--namespace-packages --explicit-package-bases \ |
| 279 |
--follow-imports silent \ |
| 280 |
-p ansible_collections.community.aws |
| 281 |
# {posargs:plugins/module_utils plugins/plugin_utils} |