From d19b506ce8c5ee43865b1cead2246fc07cc8902b Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 28 Jan 2022 13:48:34 -0800 Subject: [PATCH] ansible-test - Clean up future boilerplate. (#76874) * ansible-test - Clarify need for empty __init__.py * ansible-test - Update code-smell boilerplate. * Update code-smell boilerplate for core. * Update future boilerplate test for ansible-test. All ansible-test code (except for targets) and core-specific sanity tests now use the same boilerplate. The test also checks for unwanted `__future__` and `metaclass` boilerplate. * Relocate target tools to the correct directory. Several tools used on target Python versions were incorrectly placed in the controller directory. --- test/lib/ansible_test/__init__.py | 2 ++ test/lib/ansible_test/_internal/util.py | 1 + .../lib/ansible_test/_internal/util_common.py | 4 ++-- test/lib/ansible_test/_internal/venv.py | 4 ++-- test/lib/ansible_test/_util/__init__.py | 5 ++--- .../sanity/code-smell/action-plugin-docs.py | 3 +-- .../controller/sanity/code-smell/changelog.py | 3 +-- .../sanity/code-smell/changelog/sphinx.py | 3 +-- .../sanity/code-smell/empty-init.py | 3 +-- .../code-smell/future-import-boilerplate.py | 3 +-- .../sanity/code-smell/line-endings.py | 3 +-- .../code-smell/metaclass-boilerplate.py | 3 +-- .../controller/sanity/code-smell/no-assert.py | 3 +-- .../sanity/code-smell/no-basestring.py | 3 +-- .../sanity/code-smell/no-dict-iteritems.py | 3 +-- .../sanity/code-smell/no-dict-iterkeys.py | 3 +-- .../sanity/code-smell/no-dict-itervalues.py | 3 +-- .../sanity/code-smell/no-get-exception.py | 3 +-- .../sanity/code-smell/no-illegal-filenames.py | 3 +-- .../sanity/code-smell/no-main-display.py | 3 +-- .../sanity/code-smell/no-smart-quotes.py | 3 +-- .../sanity/code-smell/no-unicode-literals.py | 3 +-- .../sanity/code-smell/replace-urlopen.py | 3 +-- .../sanity/code-smell/runtime-metadata.py | 3 +-- .../controller/sanity/code-smell/shebang.py | 3 +-- .../controller/sanity/code-smell/symlinks.py | 3 +-- .../code-smell/use-argspec-type-path.py | 3 +-- .../sanity/code-smell/use-compat-six.py | 3 +-- .../integration-aliases/yaml_to_json.py | 3 +-- .../sanity/pylint/plugins/deprecated.py | 3 +-- .../sanity/pylint/plugins/string_format.py | 3 +-- .../sanity/pylint/plugins/unwanted.py | 4 +--- .../sanity/validate-modules/main.py | 3 +-- .../validate_modules/__init__.py | 3 +-- .../validate-modules/validate_modules/main.py | 3 +-- .../validate_modules/module_args.py | 3 +-- .../validate_modules/schema.py | 3 +-- .../validate_modules/utils.py | 3 +-- .../controller/sanity/yamllint/yamllinter.py | 3 +-- .../controller/tools/collection_detail.py | 3 +-- .../_util/controller/tools/sslcheck.py | 3 +-- .../_util/controller/tools/yaml_to_json.py | 3 +-- .../lib/ansible_test/_util/target/__init__.py | 5 ++--- .../_util/target/common/__init__.py | 5 ++--- .../tools/virtualenvcheck.py | 0 .../{controller => target}/tools/yamlcheck.py | 0 .../sanity/code-smell/ansible-requirements.py | 3 +-- .../ansible-test-future-boilerplate.json | 3 ++- .../ansible-test-future-boilerplate.py | 19 +++++++++++++++++-- test/sanity/code-smell/botmeta.py | 3 +-- .../code-smell/configure-remoting-ps1.py | 3 +-- test/sanity/code-smell/deprecated-config.py | 3 +-- test/sanity/code-smell/docs-build.py | 3 +-- test/sanity/code-smell/no-unwanted-files.py | 3 +-- test/sanity/code-smell/obsolete-files.py | 3 +-- test/sanity/code-smell/package-data.py | 3 +-- test/sanity/code-smell/release-names.py | 3 +-- .../required-and-default-attributes.py | 3 +-- test/sanity/code-smell/rstcheck.py | 3 +-- test/sanity/code-smell/test-constraints.py | 3 +-- test/sanity/code-smell/update-bundled.py | 3 +-- 61 files changed, 82 insertions(+), 117 deletions(-) rename test/lib/ansible_test/_util/{controller => target}/tools/virtualenvcheck.py (100%) rename test/lib/ansible_test/_util/{controller => target}/tools/yamlcheck.py (100%) diff --git a/test/lib/ansible_test/__init__.py b/test/lib/ansible_test/__init__.py index e69de29bb2d..527d413a98d 100644 --- a/test/lib/ansible_test/__init__.py +++ b/test/lib/ansible_test/__init__.py @@ -0,0 +1,2 @@ +# Empty __init__.py to allow importing of `ansible_test._util.target.common` under Python 2.x. +# This allows the ansible-test entry point to report supported Python versions before exiting. diff --git a/test/lib/ansible_test/_internal/util.py b/test/lib/ansible_test/_internal/util.py index 5fb33374854..58c77f3ede9 100644 --- a/test/lib/ansible_test/_internal/util.py +++ b/test/lib/ansible_test/_internal/util.py @@ -83,6 +83,7 @@ ANSIBLE_TEST_CONTROLLER_ROOT = os.path.join(ANSIBLE_TEST_UTIL_ROOT, 'controller' ANSIBLE_TEST_TARGET_ROOT = os.path.join(ANSIBLE_TEST_UTIL_ROOT, 'target') ANSIBLE_TEST_TOOLS_ROOT = os.path.join(ANSIBLE_TEST_CONTROLLER_ROOT, 'tools') +ANSIBLE_TEST_TARGET_TOOLS_ROOT = os.path.join(ANSIBLE_TEST_TARGET_ROOT, 'tools') # Modes are set to allow all users the same level of access. # This permits files to be used in tests that change users. diff --git a/test/lib/ansible_test/_internal/util_common.py b/test/lib/ansible_test/_internal/util_common.py index b4d42420b9e..0aa05450f58 100644 --- a/test/lib/ansible_test/_internal/util_common.py +++ b/test/lib/ansible_test/_internal/util_common.py @@ -31,7 +31,7 @@ from .util import ( raw_command, ANSIBLE_TEST_DATA_ROOT, ANSIBLE_TEST_TARGET_ROOT, - ANSIBLE_TEST_TOOLS_ROOT, + ANSIBLE_TEST_TARGET_TOOLS_ROOT, ApplicationError, SubprocessError, generate_name, @@ -425,7 +425,7 @@ def run_command( def yamlcheck(python): """Return True if PyYAML has libyaml support, False if it does not and None if it was not found.""" - result = json.loads(raw_command([python.path, os.path.join(ANSIBLE_TEST_TOOLS_ROOT, 'yamlcheck.py')], capture=True)[0]) + result = json.loads(raw_command([python.path, os.path.join(ANSIBLE_TEST_TARGET_TOOLS_ROOT, 'yamlcheck.py')], capture=True)[0]) if not result['yaml']: return None diff --git a/test/lib/ansible_test/_internal/venv.py b/test/lib/ansible_test/_internal/venv.py index fa76bc433d2..dadb3b97c51 100644 --- a/test/lib/ansible_test/_internal/venv.py +++ b/test/lib/ansible_test/_internal/venv.py @@ -14,7 +14,7 @@ from .util import ( find_python, SubprocessError, get_available_python_versions, - ANSIBLE_TEST_TOOLS_ROOT, + ANSIBLE_TEST_TARGET_TOOLS_ROOT, display, remove_tree, ApplicationError, @@ -150,7 +150,7 @@ def get_python_real_prefix(args, python_path): # type: (EnvironmentConfig, str) """ Return the real prefix of the specified interpreter or None if the interpreter is not a virtual environment created by 'virtualenv'. """ - cmd = [python_path, os.path.join(os.path.join(ANSIBLE_TEST_TOOLS_ROOT, 'virtualenvcheck.py'))] + cmd = [python_path, os.path.join(os.path.join(ANSIBLE_TEST_TARGET_TOOLS_ROOT, 'virtualenvcheck.py'))] check_result = json.loads(run_command(args, cmd, capture=True, always=True)[0]) real_prefix = check_result['real_prefix'] return real_prefix diff --git a/test/lib/ansible_test/_util/__init__.py b/test/lib/ansible_test/_util/__init__.py index d6fc0a8614c..527d413a98d 100644 --- a/test/lib/ansible_test/_util/__init__.py +++ b/test/lib/ansible_test/_util/__init__.py @@ -1,3 +1,2 @@ -"""Nearly empty __init__.py to allow importing under Python 2.x.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +# Empty __init__.py to allow importing of `ansible_test._util.target.common` under Python 2.x. +# This allows the ansible-test entry point to report supported Python versions before exiting. diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/action-plugin-docs.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/action-plugin-docs.py index e19b4d98a40..a319d1a12e4 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/action-plugin-docs.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/action-plugin-docs.py @@ -1,6 +1,5 @@ """Test to verify action plugins have an associated module to provide documentation.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog.py index 1875ab3aa44..fe2ba5e3727 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog/sphinx.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog/sphinx.py index 000c29e4e97..7eab0f573a1 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog/sphinx.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/changelog/sphinx.py @@ -1,5 +1,4 @@ """Block the sphinx module from being loaded.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations raise ImportError('The sphinx module has been prevented from loading to maintain consistent test results.') diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/empty-init.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/empty-init.py index 806c0e6ed1a..e0dd41cd5cd 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/empty-init.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/empty-init.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/future-import-boilerplate.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/future-import-boilerplate.py index cdad96551ed..dcb02e7adb9 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/future-import-boilerplate.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/future-import-boilerplate.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import ast import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/line-endings.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/line-endings.py index 660b0fce858..99417b6e720 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/line-endings.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/line-endings.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py index e3fba1f5ddb..21cb0017dff 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/metaclass-boilerplate.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import ast import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-assert.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-assert.py index d6d710aeffb..71883c9f611 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-assert.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-assert.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-basestring.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-basestring.py index 18a3f6d1d11..bb564564ef2 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-basestring.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-basestring.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iteritems.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iteritems.py index 7dfd5b26017..1b728de630c 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iteritems.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iteritems.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py index 8925e831d29..9fe6e9ff5c0 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-iterkeys.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-itervalues.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-itervalues.py index 18134154389..8a955636833 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-itervalues.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-dict-itervalues.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-get-exception.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-get-exception.py index 5a267ba0dfd..bf50a4d9742 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-get-exception.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-get-exception.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-illegal-filenames.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-illegal-filenames.py index 421bbd6229a..36793f3f0c6 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-illegal-filenames.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-illegal-filenames.py @@ -1,8 +1,7 @@ # a script to check for illegal filenames on various Operating Systems. The # main rules are derived from restrictions on Windows # https://msdn.microsoft.com/en-us/library/aa365247#naming_conventions -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import struct diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-main-display.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-main-display.py index e5abd64db80..020c95d6790 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-main-display.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-main-display.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-smart-quotes.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-smart-quotes.py index 8399a36e0bd..1ac51710ead 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-smart-quotes.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-smart-quotes.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-unicode-literals.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-unicode-literals.py index bb8c8f01d82..2a3413870ed 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/no-unicode-literals.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/no-unicode-literals.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/replace-urlopen.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/replace-urlopen.py index 87575f51895..8484047c1bd 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/replace-urlopen.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/replace-urlopen.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py index 929f371f7a2..74a2b936da1 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py @@ -1,6 +1,5 @@ """Schema validation of ansible-core's ansible_builtin_runtime.yml and collection's meta/runtime.yml""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import datetime import os diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py index bbbb713a85d..73b45ac27d6 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/shebang.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import re diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/symlinks.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/symlinks.py index 5603051ac51..4bd9d4bf466 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/symlinks.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/symlinks.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/use-argspec-type-path.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/use-argspec-type-path.py index 68f380b0a92..0e2fcfa661d 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/use-argspec-type-path.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/use-argspec-type-path.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/use-compat-six.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/use-compat-six.py index a8f0b879505..d0997484708 100644 --- a/test/lib/ansible_test/_util/controller/sanity/code-smell/use-compat-six.py +++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/use-compat-six.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/integration-aliases/yaml_to_json.py b/test/lib/ansible_test/_util/controller/sanity/integration-aliases/yaml_to_json.py index 74a45f009f7..af11dd8a8be 100644 --- a/test/lib/ansible_test/_util/controller/sanity/integration-aliases/yaml_to_json.py +++ b/test/lib/ansible_test/_util/controller/sanity/integration-aliases/yaml_to_json.py @@ -1,6 +1,5 @@ """Read YAML from stdin and write JSON to stdout.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json import sys diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py index 234ec217cda..851d8d75985 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/deprecated.py @@ -2,8 +2,7 @@ # (c) 2018, Matt Martz # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import datetime import re diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/string_format.py b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/string_format.py index 3b9a37e549c..934a9ae70ca 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/string_format.py +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/string_format.py @@ -2,8 +2,7 @@ # (c) 2018, Matt Martz # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # -*- coding: utf-8 -*- -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import astroid from pylint.interfaces import IAstroidChecker diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/unwanted.py b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/unwanted.py index 75a8b57fff8..6ef5dc2ac97 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/unwanted.py +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/plugins/unwanted.py @@ -1,7 +1,5 @@ """A plugin for pylint to identify imports and functions which should not be used.""" -from __future__ import (absolute_import, division, print_function) - -__metaclass__ = type +from __future__ import annotations import os import typing as t diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/main.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/main.py index e6749cdc61d..ee7e832b489 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/main.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/main.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations from validate_modules.main import main diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/__init__.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/__init__.py index d8ff2dc0d4f..c84ed8ac6b7 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/__init__.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/__init__.py @@ -15,6 +15,5 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations __version__ = '0.0.1b' diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py index 0f88ecadd2a..22416be990f 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/main.py @@ -15,8 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import abc import argparse diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/module_args.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/module_args.py index 326bcb7b1d7..ee938142ff8 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/module_args.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/module_args.py @@ -15,8 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import runpy import inspect diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/schema.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/schema.py index 555ac6607a4..b4d7893890c 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/schema.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/schema.py @@ -3,8 +3,7 @@ # Copyright: (c) 2015, Matt Martz # Copyright: (c) 2015, Rackspace US, Inc. # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re diff --git a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py index ac46f6669f6..5b20db8da9e 100644 --- a/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py +++ b/test/lib/ansible_test/_util/controller/sanity/validate-modules/validate_modules/utils.py @@ -15,8 +15,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import ast import datetime diff --git a/test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py b/test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py index 42822111be8..bf9bdd5c86a 100644 --- a/test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py +++ b/test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py @@ -1,6 +1,5 @@ """Wrapper around yamllint that supports YAML embedded in Ansible modules.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import ast import json diff --git a/test/lib/ansible_test/_util/controller/tools/collection_detail.py b/test/lib/ansible_test/_util/controller/tools/collection_detail.py index e7c883ca016..4ab6631ae21 100644 --- a/test/lib/ansible_test/_util/controller/tools/collection_detail.py +++ b/test/lib/ansible_test/_util/controller/tools/collection_detail.py @@ -1,6 +1,5 @@ """Retrieve collection detail.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json import os diff --git a/test/lib/ansible_test/_util/controller/tools/sslcheck.py b/test/lib/ansible_test/_util/controller/tools/sslcheck.py index 115c5ed25a8..c25fed6165e 100644 --- a/test/lib/ansible_test/_util/controller/tools/sslcheck.py +++ b/test/lib/ansible_test/_util/controller/tools/sslcheck.py @@ -1,6 +1,5 @@ """Show openssl version.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import json diff --git a/test/lib/ansible_test/_util/controller/tools/yaml_to_json.py b/test/lib/ansible_test/_util/controller/tools/yaml_to_json.py index 1164168e3eb..e2a15bf00ce 100644 --- a/test/lib/ansible_test/_util/controller/tools/yaml_to_json.py +++ b/test/lib/ansible_test/_util/controller/tools/yaml_to_json.py @@ -1,6 +1,5 @@ """Read YAML from stdin and write JSON to stdout.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import datetime import json diff --git a/test/lib/ansible_test/_util/target/__init__.py b/test/lib/ansible_test/_util/target/__init__.py index d6fc0a8614c..527d413a98d 100644 --- a/test/lib/ansible_test/_util/target/__init__.py +++ b/test/lib/ansible_test/_util/target/__init__.py @@ -1,3 +1,2 @@ -"""Nearly empty __init__.py to allow importing under Python 2.x.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +# Empty __init__.py to allow importing of `ansible_test._util.target.common` under Python 2.x. +# This allows the ansible-test entry point to report supported Python versions before exiting. diff --git a/test/lib/ansible_test/_util/target/common/__init__.py b/test/lib/ansible_test/_util/target/common/__init__.py index d6fc0a8614c..527d413a98d 100644 --- a/test/lib/ansible_test/_util/target/common/__init__.py +++ b/test/lib/ansible_test/_util/target/common/__init__.py @@ -1,3 +1,2 @@ -"""Nearly empty __init__.py to allow importing under Python 2.x.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +# Empty __init__.py to allow importing of `ansible_test._util.target.common` under Python 2.x. +# This allows the ansible-test entry point to report supported Python versions before exiting. diff --git a/test/lib/ansible_test/_util/controller/tools/virtualenvcheck.py b/test/lib/ansible_test/_util/target/tools/virtualenvcheck.py similarity index 100% rename from test/lib/ansible_test/_util/controller/tools/virtualenvcheck.py rename to test/lib/ansible_test/_util/target/tools/virtualenvcheck.py diff --git a/test/lib/ansible_test/_util/controller/tools/yamlcheck.py b/test/lib/ansible_test/_util/target/tools/yamlcheck.py similarity index 100% rename from test/lib/ansible_test/_util/controller/tools/yamlcheck.py rename to test/lib/ansible_test/_util/target/tools/yamlcheck.py diff --git a/test/sanity/code-smell/ansible-requirements.py b/test/sanity/code-smell/ansible-requirements.py index 48ecbaafdbd..4d1a652f2b1 100644 --- a/test/sanity/code-smell/ansible-requirements.py +++ b/test/sanity/code-smell/ansible-requirements.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/sanity/code-smell/ansible-test-future-boilerplate.json b/test/sanity/code-smell/ansible-test-future-boilerplate.json index e689ba5da12..ca4c067ab32 100644 --- a/test/sanity/code-smell/ansible-test-future-boilerplate.json +++ b/test/sanity/code-smell/ansible-test-future-boilerplate.json @@ -3,7 +3,8 @@ ".py" ], "prefixes": [ - "test/lib/ansible_test/_internal/" + "test/sanity/", + "test/lib/ansible_test/" ], "output": "path-message" } diff --git a/test/sanity/code-smell/ansible-test-future-boilerplate.py b/test/sanity/code-smell/ansible-test-future-boilerplate.py index 55092a73a3d..9a6222519b1 100644 --- a/test/sanity/code-smell/ansible-test-future-boilerplate.py +++ b/test/sanity/code-smell/ansible-test-future-boilerplate.py @@ -1,12 +1,19 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import ast import sys def main(): + # The following directories contain code which must work under Python 2.x. + py2_compat = ( + 'test/lib/ansible_test/_util/target/', + ) + for path in sys.argv[1:] or sys.stdin.read().splitlines(): + if any(path.startswith(prefix) for prefix in py2_compat): + continue + with open(path, 'rb') as path_fd: lines = path_fd.read().splitlines() @@ -15,11 +22,16 @@ def main(): # Files are allowed to be empty of everything including boilerplate missing = False + invalid_future = [] + for text in lines: if text == b'from __future__ import annotations': missing = False break + if text.startswith(b'from __future__ ') or text == b'__metaclass__ = type': + invalid_future.append(text.decode()) + if missing: with open(path) as file: contents = file.read() @@ -39,6 +51,9 @@ def main(): if missing: print('%s: missing: from __future__ import annotations' % path) + for text in invalid_future: + print('%s: invalid: %s' % (path, text)) + if __name__ == '__main__': main() diff --git a/test/sanity/code-smell/botmeta.py b/test/sanity/code-smell/botmeta.py index 0ab5bf97edd..985c8f9f0c2 100644 --- a/test/sanity/code-smell/botmeta.py +++ b/test/sanity/code-smell/botmeta.py @@ -1,6 +1,5 @@ """Make sure the data in BOTMETA.yml is valid""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import glob import os diff --git a/test/sanity/code-smell/configure-remoting-ps1.py b/test/sanity/code-smell/configure-remoting-ps1.py index bd2161067f5..fe678008c1e 100644 --- a/test/sanity/code-smell/configure-remoting-ps1.py +++ b/test/sanity/code-smell/configure-remoting-ps1.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os diff --git a/test/sanity/code-smell/deprecated-config.py b/test/sanity/code-smell/deprecated-config.py index 53cb2b93f24..3c5c6459296 100644 --- a/test/sanity/code-smell/deprecated-config.py +++ b/test/sanity/code-smell/deprecated-config.py @@ -16,8 +16,7 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import mmap import os diff --git a/test/sanity/code-smell/docs-build.py b/test/sanity/code-smell/docs-build.py index ff7d427a05d..9461620a9a3 100644 --- a/test/sanity/code-smell/docs-build.py +++ b/test/sanity/code-smell/docs-build.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import re diff --git a/test/sanity/code-smell/no-unwanted-files.py b/test/sanity/code-smell/no-unwanted-files.py index 1b55c23e6e2..82f7aff0a0e 100644 --- a/test/sanity/code-smell/no-unwanted-files.py +++ b/test/sanity/code-smell/no-unwanted-files.py @@ -1,6 +1,5 @@ """Prevent unwanted files from being added to the source tree.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import sys diff --git a/test/sanity/code-smell/obsolete-files.py b/test/sanity/code-smell/obsolete-files.py index 1fd980271cd..3c1a4a4c726 100644 --- a/test/sanity/code-smell/obsolete-files.py +++ b/test/sanity/code-smell/obsolete-files.py @@ -1,6 +1,5 @@ """Prevent files from being added to directories that are now obsolete.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import sys diff --git a/test/sanity/code-smell/package-data.py b/test/sanity/code-smell/package-data.py index 9c64ac6fd27..2390b2193a2 100644 --- a/test/sanity/code-smell/package-data.py +++ b/test/sanity/code-smell/package-data.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import contextlib import fnmatch diff --git a/test/sanity/code-smell/release-names.py b/test/sanity/code-smell/release-names.py index 4e145062027..81d90d81c3a 100644 --- a/test/sanity/code-smell/release-names.py +++ b/test/sanity/code-smell/release-names.py @@ -20,8 +20,7 @@ Test that the release name is present in the list of used up release names """ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations from yaml import safe_load diff --git a/test/sanity/code-smell/required-and-default-attributes.py b/test/sanity/code-smell/required-and-default-attributes.py index d71ddeeb297..900829dce74 100644 --- a/test/sanity/code-smell/required-and-default-attributes.py +++ b/test/sanity/code-smell/required-and-default-attributes.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import sys diff --git a/test/sanity/code-smell/rstcheck.py b/test/sanity/code-smell/rstcheck.py index 7f7028469f1..99917ca80ef 100644 --- a/test/sanity/code-smell/rstcheck.py +++ b/test/sanity/code-smell/rstcheck.py @@ -1,6 +1,5 @@ """Sanity test using rstcheck and sphinx.""" -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import re import subprocess diff --git a/test/sanity/code-smell/test-constraints.py b/test/sanity/code-smell/test-constraints.py index fd6f17d578e..18a7a29bbe4 100644 --- a/test/sanity/code-smell/test-constraints.py +++ b/test/sanity/code-smell/test-constraints.py @@ -1,5 +1,4 @@ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import os import re diff --git a/test/sanity/code-smell/update-bundled.py b/test/sanity/code-smell/update-bundled.py index 009f801bfd0..4bad77a6672 100644 --- a/test/sanity/code-smell/update-bundled.py +++ b/test/sanity/code-smell/update-bundled.py @@ -21,8 +21,7 @@ a newer upstream release. """ -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type +from __future__ import annotations import fnmatch import json