From b16cc4d2d1732b7c739c76a2e39f689f6b8cd474 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 3 Oct 2024 10:43:26 -0700 Subject: [PATCH] [stable-2.18] ansible-test - Update sanity tests and default Python (#83998) (#84047) * ansible-test - Update sanity test requirements * ansible-test - Default to Python 3.13 in base/default containers * ansible-test - Fix incorrect AnyStr type hints (cherry picked from commit 9406ed31090120afedce866a6b2c16277efae832) --- changelogs/fragments/ansible-test-update.yml | 3 +++ test/lib/ansible_test/_data/completion/docker.txt | 6 +++--- .../_data/requirements/sanity.pylint.txt | 8 ++++---- test/lib/ansible_test/_internal/encoding.py | 8 ++++---- .../sanity/pylint/config/ansible-test-target.cfg | 1 + .../controller/sanity/pylint/config/ansible-test.cfg | 1 + .../controller/sanity/pylint/config/code-smell.cfg | 1 + .../controller/sanity/pylint/config/collection.cfg | 1 + .../controller/sanity/pylint/config/default.cfg | 1 + .../ansible_test/_util/target/setup/requirements.py | 8 ++++---- test/sanity/code-smell/mypy.requirements.txt | 12 ++++++------ test/sanity/code-smell/package-data.requirements.txt | 2 +- test/sanity/code-smell/pymarkdown.requirements.txt | 2 +- 13 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 changelogs/fragments/ansible-test-update.yml diff --git a/changelogs/fragments/ansible-test-update.yml b/changelogs/fragments/ansible-test-update.yml new file mode 100644 index 00000000000..fdb6ed2f3d4 --- /dev/null +++ b/changelogs/fragments/ansible-test-update.yml @@ -0,0 +1,3 @@ +minor_changes: + - ansible-test - Update ``pylint`` sanity test to use version 3.3.1. + - ansible-test - Default to Python 3.13 in the ``base`` and ``default`` containers. diff --git a/test/lib/ansible_test/_data/completion/docker.txt b/test/lib/ansible_test/_data/completion/docker.txt index d9976935326..2d59ffd1d79 100644 --- a/test/lib/ansible_test/_data/completion/docker.txt +++ b/test/lib/ansible_test/_data/completion/docker.txt @@ -1,6 +1,6 @@ -base image=quay.io/ansible/base-test-container:7.5.0 python=3.12,3.8,3.9,3.10,3.11,3.13 -default image=quay.io/ansible/default-test-container:10.5.0 python=3.12,3.8,3.9,3.10,3.11,3.13 context=collection -default image=quay.io/ansible/ansible-core-test-container:10.5.0 python=3.12,3.8,3.9,3.10,3.11,3.13 context=ansible-core +base image=quay.io/ansible/base-test-container:7.5.0 python=3.13,3.8,3.9,3.10,3.11,3.12 +default image=quay.io/ansible/default-test-container:10.5.0 python=3.13,3.8,3.9,3.10,3.11,3.12 context=collection +default image=quay.io/ansible/ansible-core-test-container:10.5.0 python=3.13,3.8,3.9,3.10,3.11,3.12 context=ansible-core alpine320 image=quay.io/ansible/alpine320-test-container:8.1.0 python=3.12 cgroup=none audit=none fedora40 image=quay.io/ansible/fedora40-test-container:8.1.0 python=3.12 ubuntu2204 image=quay.io/ansible/ubuntu2204-test-container:8.1.0 python=3.10 diff --git a/test/lib/ansible_test/_data/requirements/sanity.pylint.txt b/test/lib/ansible_test/_data/requirements/sanity.pylint.txt index 60490bc7da4..a34c949550d 100644 --- a/test/lib/ansible_test/_data/requirements/sanity.pylint.txt +++ b/test/lib/ansible_test/_data/requirements/sanity.pylint.txt @@ -1,9 +1,9 @@ # edit "sanity.pylint.in" and generate with: hacking/update-sanity-requirements.py --test pylint -astroid==3.2.4 -dill==0.3.8 +astroid==3.3.4 +dill==0.3.9 isort==5.13.2 mccabe==0.7.0 -platformdirs==4.3.2 -pylint==3.2.7 +platformdirs==4.3.6 +pylint==3.3.1 PyYAML==6.0.2 tomlkit==0.13.2 diff --git a/test/lib/ansible_test/_internal/encoding.py b/test/lib/ansible_test/_internal/encoding.py index 11f0d75c26b..476c59025e6 100644 --- a/test/lib/ansible_test/_internal/encoding.py +++ b/test/lib/ansible_test/_internal/encoding.py @@ -6,17 +6,17 @@ import typing as t ENCODING = 'utf-8' -def to_optional_bytes(value: t.Optional[t.AnyStr], errors: str = 'strict') -> t.Optional[bytes]: +def to_optional_bytes(value: t.Optional[str | bytes], errors: str = 'strict') -> t.Optional[bytes]: """Return the given value as bytes encoded using UTF-8 if not already bytes, or None if the value is None.""" return None if value is None else to_bytes(value, errors) -def to_optional_text(value: t.Optional[t.AnyStr], errors: str = 'strict') -> t.Optional[str]: +def to_optional_text(value: t.Optional[str | bytes], errors: str = 'strict') -> t.Optional[str]: """Return the given value as text decoded using UTF-8 if not already text, or None if the value is None.""" return None if value is None else to_text(value, errors) -def to_bytes(value: t.AnyStr, errors: str = 'strict') -> bytes: +def to_bytes(value: str | bytes, errors: str = 'strict') -> bytes: """Return the given value as bytes encoded using UTF-8 if not already bytes.""" if isinstance(value, bytes): return value @@ -27,7 +27,7 @@ def to_bytes(value: t.AnyStr, errors: str = 'strict') -> bytes: raise Exception('value is not bytes or text: %s' % type(value)) -def to_text(value: t.AnyStr, errors: str = 'strict') -> str: +def to_text(value: str | bytes, errors: str = 'strict') -> str: """Return the given value as text decoded using UTF-8 if not already text.""" if isinstance(value, bytes): return value.decode(ENCODING, errors) diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg index 51d0bb01d38..0f42d759619 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg @@ -20,6 +20,7 @@ disable= too-many-nested-blocks, too-many-return-statements, too-many-statements, + too-many-positional-arguments, use-dict-literal, # ignoring as a common style issue useless-return, # complains about returning None when the return type is optional diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg index 801adbe145c..6067069dc5c 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg @@ -18,6 +18,7 @@ disable= too-many-nested-blocks, too-many-return-statements, too-many-statements, + too-many-positional-arguments, use-dict-literal, # ignoring as a common style issue unspecified-encoding, # always run with UTF-8 encoding enforced useless-return, # complains about returning None when the return type is optional diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg index adc0b95e947..39ed050eef5 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg @@ -17,6 +17,7 @@ disable= too-many-nested-blocks, too-many-return-statements, too-many-statements, + too-many-positional-arguments, use-dict-literal, # ignoring as a common style issue unspecified-encoding, # always run with UTF-8 encoding enforced useless-return, # complains about returning None when the return type is optional diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg index 778bf77fd85..60048abb88c 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg @@ -98,6 +98,7 @@ disable= too-many-public-methods, too-many-return-statements, too-many-statements, + too-many-positional-arguments, try-except-raise, unbalanced-tuple-unpacking, undefined-loop-variable, diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg index d41185214e2..c4b9a8f4dea 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg @@ -91,6 +91,7 @@ disable= too-many-public-methods, too-many-return-statements, too-many-statements, + too-many-positional-arguments, try-except-raise, unbalanced-tuple-unpacking, undefined-loop-variable, diff --git a/test/lib/ansible_test/_util/target/setup/requirements.py b/test/lib/ansible_test/_util/target/setup/requirements.py index da2555f4307..7cbc0a2f196 100644 --- a/test/lib/ansible_test/_util/target/setup/requirements.py +++ b/test/lib/ansible_test/_util/target/setup/requirements.py @@ -363,17 +363,17 @@ def open_binary_file(path, mode='rb'): # type: (str, str) -> t.IO[bytes] return io.open(to_bytes(path), mode) # pylint: disable=consider-using-with,unspecified-encoding -def to_optional_bytes(value, errors='strict'): # type: (t.Optional[t.AnyStr], str) -> t.Optional[bytes] +def to_optional_bytes(value, errors='strict'): # type: (t.Optional[str | bytes], str) -> t.Optional[bytes] """Return the given value as bytes encoded using UTF-8 if not already bytes, or None if the value is None.""" return None if value is None else to_bytes(value, errors) -def to_optional_text(value, errors='strict'): # type: (t.Optional[t.AnyStr], str) -> t.Optional[t.Text] +def to_optional_text(value, errors='strict'): # type: (t.Optional[str | bytes], str) -> t.Optional[t.Text] """Return the given value as text decoded using UTF-8 if not already text, or None if the value is None.""" return None if value is None else to_text(value, errors) -def to_bytes(value, errors='strict'): # type: (t.AnyStr, str) -> bytes +def to_bytes(value, errors='strict'): # type: (str | bytes, str) -> bytes """Return the given value as bytes encoded using UTF-8 if not already bytes.""" if isinstance(value, bytes): return value @@ -384,7 +384,7 @@ def to_bytes(value, errors='strict'): # type: (t.AnyStr, str) -> bytes raise Exception('value is not bytes or text: %s' % type(value)) -def to_text(value, errors='strict'): # type: (t.AnyStr, str) -> t.Text +def to_text(value, errors='strict'): # type: (str | bytes, str) -> t.Text """Return the given value as text decoded using UTF-8 if not already text.""" if isinstance(value, bytes): return value.decode(ENCODING, errors) diff --git a/test/sanity/code-smell/mypy.requirements.txt b/test/sanity/code-smell/mypy.requirements.txt index 74e6f18b593..c5a3ece72cd 100644 --- a/test/sanity/code-smell/mypy.requirements.txt +++ b/test/sanity/code-smell/mypy.requirements.txt @@ -7,12 +7,12 @@ mypy==1.11.2 mypy-extensions==1.0.0 packaging==24.1 pycparser==2.22 -tomli==2.0.1 +tomli==2.0.2 types-backports==0.1.3 -types-paramiko==3.4.0.20240423 -types-PyYAML==6.0.12.20240808 -types-requests==2.32.0.20240907 -types-setuptools==74.1.0.20240907 +types-paramiko==3.5.0.20240928 +types-PyYAML==6.0.12.20240917 +types-requests==2.32.0.20240914 +types-setuptools==75.1.0.20240917 types-toml==0.10.8.20240310 typing_extensions==4.12.2 -urllib3==2.2.2 +urllib3==2.2.3 diff --git a/test/sanity/code-smell/package-data.requirements.txt b/test/sanity/code-smell/package-data.requirements.txt index dd0a9a1146a..3a11919375a 100644 --- a/test/sanity/code-smell/package-data.requirements.txt +++ b/test/sanity/code-smell/package-data.requirements.txt @@ -1,4 +1,4 @@ # edit "package-data.requirements.in" and generate with: hacking/update-sanity-requirements.py --test package-data build==1.2.2 packaging==24.1 -pyproject_hooks==1.1.0 +pyproject_hooks==1.2.0 diff --git a/test/sanity/code-smell/pymarkdown.requirements.txt b/test/sanity/code-smell/pymarkdown.requirements.txt index 77bf274fe76..e5774e2fa53 100644 --- a/test/sanity/code-smell/pymarkdown.requirements.txt +++ b/test/sanity/code-smell/pymarkdown.requirements.txt @@ -3,7 +3,7 @@ application_properties==0.8.2 Columnar==1.4.1 pymarkdownlnt==0.9.23 PyYAML==6.0.2 -tomli==2.0.1 +tomli==2.0.2 toolz==0.12.1 typing_extensions==4.12.2 wcwidth==0.2.13