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