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.
pull/76875/head
Matt Clay 3 years ago committed by GitHub
parent 3816815db0
commit d19b506ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.

@ -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.

@ -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

@ -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

@ -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.

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os
import sys

@ -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.')

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import ast
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import ast
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import sys

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os
import re

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -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

@ -2,8 +2,7 @@
# (c) 2018, Matt Martz <matt@sivel.net>
# 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

@ -2,8 +2,7 @@
# (c) 2018, Matt Martz <matt@sivel.net>
# 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

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
from validate_modules.main import main

@ -15,6 +15,5 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
__version__ = '0.0.1b'

@ -15,8 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import abc
import argparse

@ -15,8 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import runpy
import inspect

@ -3,8 +3,7 @@
# Copyright: (c) 2015, Matt Martz <matt@sivel.net>
# 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

@ -15,8 +15,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import ast
import datetime

@ -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

@ -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

@ -1,6 +1,5 @@
"""Show openssl version."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import json

@ -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

@ -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.

@ -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.

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -3,7 +3,8 @@
".py"
],
"prefixes": [
"test/lib/ansible_test/_internal/"
"test/sanity/",
"test/lib/ansible_test/"
],
"output": "path-message"
}

@ -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()

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os

@ -16,8 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import mmap
import os

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os
import re

@ -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

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import contextlib
import fnmatch

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import re
import sys

@ -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

@ -1,5 +1,4 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from __future__ import annotations
import os
import re

@ -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

Loading…
Cancel
Save