Skip to content

Commit

Permalink
Synchronise tox configuration between amazon.aws and community.aws (#…
Browse files Browse the repository at this point in the history
…2486)

SUMMARY
tox configs needed a little cleanup to ensure that things were consistently in the import path when running pylint.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
pyproject.toml
tests/unit/conftest.py
tox.ini
ADDITIONAL INFORMATION
See also: ansible-collections/community.aws#2219

Reviewed-by: Alina Buzachis
  • Loading branch information
tremble authored Jan 28, 2025
1 parent 528843e commit 62ea880
Show file tree
Hide file tree
Showing 88 changed files with 94 additions and 72 deletions.
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

11 changes: 0 additions & 11 deletions check_mypy.sh

This file was deleted.

13 changes: 12 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ disable_error_code = ["import-untyped"]
line-length = 120

[tool.ruff.lint]
# "F401" - unused-imports - We use these imports to maintaining historic Interfaces
# "F401" - unused-imports - We use these imports to maintain historic Interfaces
# "E402" - import not at top of file - General Ansible style puts the documentation at the top.
unfixable = ["F401"]
ignore = ["F401", "E402"]

[tool.pytest]
xfail_strict = true

[tool.coverage.report]
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",
# Don't complain if tests don't hit defensive assertion code:
"raise NotImplementedError",
]
12 changes: 6 additions & 6 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# pylint: disable=unused-import

import pytest

from .utils.amazon_placebo_fixtures import fixture_maybe_sleep
from .utils.amazon_placebo_fixtures import fixture_placeboify
# While it may seem appropriate to import our custom fixtures here, the pytest_ansible pytest plugin
# isn't as agressive as the ansible_test._util.target.pytest.plugins.ansible_pytest_collections plugin
# when it comes to rewriting the import paths and as such we can't import fixtures via their
# absolute import path or across collections.
11 changes: 11 additions & 0 deletions tests/unit/plugins/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-

# This file is part of Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

# pylint: disable=unused-import

import pytest

from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_maybe_sleep
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import fixture_placeboify
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/unit/plugins/modules/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
108 changes: 61 additions & 47 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,55 @@ 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]
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)
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}

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 \
Expand All @@ -62,16 +74,20 @@ 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/
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 \
Expand All @@ -86,6 +102,8 @@ 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] \
Expand All @@ -98,6 +116,8 @@ depends =
flynt, isort
deps =
black >=23.0, <24.0
change_dir = {toxinidir}
commands_pre =
commands =
black {posargs:{[common]format_dirs}}

Expand All @@ -106,14 +126,18 @@ labels = lint
description = Lint against "black" formatting standards
deps =
{[testenv:black]deps}
change_dir = {toxinidir}
commands_pre =
commands =
black -v --check --diff {posargs:{[common]format_dirs}}
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}}

Expand All @@ -122,6 +146,8 @@ 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}}

Expand All @@ -130,6 +156,8 @@ labels = format
description = Apply flint (f-string) formatting
deps =
flynt
change_dir = {toxinidir}
commands_pre =
commands =
flynt {posargs:{[common]format_dirs}}

Expand All @@ -138,6 +166,8 @@ 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}}

Expand All @@ -147,6 +177,8 @@ description = Run FLAKE8 linting
deps =
flake8
flake8-pyproject
change_dir = {toxinidir}
commands_pre =
commands =
flake8 {posargs:{[common]format_dirs}}

Expand All @@ -155,6 +187,8 @@ 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 \
Expand All @@ -175,6 +209,8 @@ 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}}
Expand All @@ -184,59 +220,41 @@ 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]
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 \
{posargs:plugins/ tests/}
{posargs:{[common]lint_dirs}}

[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
allowlist_externals = rsync,ln
labels = future-lint
description = Run mypi type tests
set_env =
MYPYPATH={envtmpdir}/mypy
ANSIBLE_HOME={[common]ansible_home}
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path}
MYPYPATH={[common]ansible_home}
deps =
mypy
# ansible-core
Expand All @@ -246,14 +264,11 @@ deps =
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
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 =
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 \
Expand All @@ -262,4 +277,3 @@ commands =
--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}

0 comments on commit 62ea880

Please sign in to comment.