diff --git a/changelogs/fragments/remove-unneeded-imports.yml b/changelogs/fragments/remove-unneeded-imports.yml new file mode 100644 index 000000000..fea3b35c0 --- /dev/null +++ b/changelogs/fragments/remove-unneeded-imports.yml @@ -0,0 +1,2 @@ +bugfixes: + - "various plugins and modules - remove unnecessary imports (https://github.com/ansible-collections/community.docker/pull/574)." diff --git a/plugins/action/docker_container_copy_into.py b/plugins/action/docker_container_copy_into.py index b6f255b75..372cbd0a3 100644 --- a/plugins/action/docker_container_copy_into.py +++ b/plugins/action/docker_container_copy_into.py @@ -8,7 +8,6 @@ import base64 from ansible import constants as C -from ansible.errors import AnsibleError from ansible.plugins.action import ActionBase from ansible.utils.vars import merge_hash diff --git a/plugins/connection/nsenter.py b/plugins/connection/nsenter.py index cf4da8242..fff36afbb 100644 --- a/plugins/connection/nsenter.py +++ b/plugins/connection/nsenter.py @@ -45,12 +45,11 @@ import os import pty -import shutil import subprocess import fcntl import ansible.constants as C -from ansible.errors import AnsibleError, AnsibleFileNotFound +from ansible.errors import AnsibleError from ansible.module_utils.compat import selectors from ansible.module_utils.six import binary_type, text_type from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text diff --git a/plugins/module_utils/_api/transport/ssladapter.py b/plugins/module_utils/_api/transport/ssladapter.py index a3182bcd4..e1b5ce020 100644 --- a/plugins/module_utils/_api/transport/ssladapter.py +++ b/plugins/module_utils/_api/transport/ssladapter.py @@ -14,7 +14,6 @@ https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/ https://github.com/kennethreitz/requests/pull/799 """ -import sys from ansible_collections.community.docker.plugins.module_utils.version import StrictVersion diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 35b4b4721..b96bc5531 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -12,13 +12,10 @@ import re import sys import traceback -from datetime import timedelta -from ansible.module_utils.basic import AnsibleModule, env_fallback, missing_required_lib -from ansible.module_utils.common.collections import is_sequence +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common._collections_compat import Mapping, Sequence from ansible.module_utils.six import string_types -from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE, BOOLEANS_FALSE from ansible_collections.community.docker.plugins.module_utils.version import LooseVersion @@ -56,14 +53,14 @@ # installed, as they utilize the same namespace are are incompatible try: # docker (Docker SDK for Python >= 2.0.0) - import docker.models # noqa: F401 + import docker.models # noqa: F401, pylint: disable=unused-import HAS_DOCKER_MODELS = True except ImportError: HAS_DOCKER_MODELS = False try: # docker-py (Docker SDK for Python < 2.0.0) - import docker.ssladapter # noqa: F401 + import docker.ssladapter # noqa: F401, pylint: disable=unused-import HAS_DOCKER_SSLADAPTER = True except ImportError: HAS_DOCKER_SSLADAPTER = False @@ -78,30 +75,30 @@ class RequestException(Exception): pass -from ansible_collections.community.docker.plugins.module_utils.util import ( +from ansible_collections.community.docker.plugins.module_utils.util import ( # noqa: F401, pylint: disable=unused-import DEFAULT_DOCKER_HOST, DEFAULT_TLS, DEFAULT_TLS_VERIFY, - DEFAULT_TLS_HOSTNAME, + DEFAULT_TLS_HOSTNAME, # TODO: remove DEFAULT_TIMEOUT_SECONDS, DOCKER_COMMON_ARGS, - DOCKER_COMMON_ARGS_VARS, + DOCKER_COMMON_ARGS_VARS, # TODO: remove DOCKER_MUTUALLY_EXCLUSIVE, DOCKER_REQUIRED_TOGETHER, - DEFAULT_DOCKER_REGISTRY, - BYTE_SUFFIXES, - is_image_name_id, - is_valid_tag, + DEFAULT_DOCKER_REGISTRY, # TODO: remove + BYTE_SUFFIXES, # TODO: remove + is_image_name_id, # TODO: remove + is_valid_tag, # TODO: remove sanitize_result, - DockerBaseClass, + DockerBaseClass, # TODO: remove update_tls_hostname, - compare_dict_allow_more_present, - compare_generic, - DifferenceTracker, - clean_dict_booleans_for_docker_api, - convert_duration_to_nanosecond, - parse_healthcheck, - omit_none_from_dict, + compare_dict_allow_more_present, # TODO: remove + compare_generic, # TODO: remove + DifferenceTracker, # TODO: remove + clean_dict_booleans_for_docker_api, # TODO: remove + convert_duration_to_nanosecond, # TODO: remove + parse_healthcheck, # TODO: remove + omit_none_from_dict, # TODO: remove ) diff --git a/plugins/module_utils/common_api.py b/plugins/module_utils/common_api.py index bafdaafe1..439be40af 100644 --- a/plugins/module_utils/common_api.py +++ b/plugins/module_utils/common_api.py @@ -11,10 +11,9 @@ import os import re -from ansible.module_utils.basic import AnsibleModule, env_fallback, missing_required_lib +from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common._collections_compat import Mapping, Sequence from ansible.module_utils.six import string_types -from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE, BOOLEANS_FALSE from ansible_collections.community.docker.plugins.module_utils.version import LooseVersion @@ -40,18 +39,18 @@ class RequestException(Exception): parse_repository_tag, ) -from ansible_collections.community.docker.plugins.module_utils.util import ( +from ansible_collections.community.docker.plugins.module_utils.util import ( # noqa: F401, pylint: disable=unused-import DEFAULT_DOCKER_HOST, DEFAULT_TLS, DEFAULT_TLS_VERIFY, - DEFAULT_TLS_HOSTNAME, + DEFAULT_TLS_HOSTNAME, # TODO: remove DEFAULT_TIMEOUT_SECONDS, DOCKER_COMMON_ARGS, DOCKER_MUTUALLY_EXCLUSIVE, DOCKER_REQUIRED_TOGETHER, - DEFAULT_DOCKER_REGISTRY, - is_image_name_id, - is_valid_tag, + DEFAULT_DOCKER_REGISTRY, # TODO: remove + is_image_name_id, # TODO: remove + is_valid_tag, # TODO: remove sanitize_result, update_tls_hostname, ) diff --git a/plugins/module_utils/module_container/docker_api.py b/plugins/module_utils/module_container/docker_api.py index d2cc553e0..1cb6d8bca 100644 --- a/plugins/module_utils/module_container/docker_api.py +++ b/plugins/module_utils/module_container/docker_api.py @@ -108,7 +108,6 @@ from ansible_collections.community.docker.plugins.module_utils._api.utils.utils import ( convert_port_bindings, normalize_links, - parse_repository_tag, ) diff --git a/plugins/module_utils/socket_handler.py b/plugins/module_utils/socket_handler.py index c582d6d88..f4a3ef794 100644 --- a/plugins/module_utils/socket_handler.py +++ b/plugins/module_utils/socket_handler.py @@ -10,7 +10,6 @@ import os.path import socket as pysocket -from ansible.module_utils.basic import missing_required_lib from ansible.module_utils.six import PY2 try: diff --git a/plugins/module_utils/util.py b/plugins/module_utils/util.py index 37917133f..9c6b738c6 100644 --- a/plugins/module_utils/util.py +++ b/plugins/module_utils/util.py @@ -6,17 +6,11 @@ __metaclass__ = type -import abc -import os -import platform import re -import sys -import traceback from datetime import timedelta from ansible.module_utils.basic import env_fallback from ansible.module_utils.common.collections import is_sequence -from ansible.module_utils.common._collections_compat import Sequence from ansible.module_utils.six.moves.urllib.parse import urlparse diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py index 746e6ba81..5184d70eb 100644 --- a/plugins/module_utils/version.py +++ b/plugins/module_utils/version.py @@ -15,10 +15,10 @@ from ansible.module_utils.six import raise_from try: - from ansible.module_utils.compat.version import LooseVersion, StrictVersion + from ansible.module_utils.compat.version import LooseVersion, StrictVersion # noqa: F401, pylint: disable=unused-import except ImportError: try: - from distutils.version import LooseVersion, StrictVersion + from distutils.version import LooseVersion, StrictVersion # noqa: F401, pylint: disable=unused-import except ImportError as exc: msg = 'To use this plugin or module with ansible-core 2.11, you need to use Python < 3.12 with distutils.version present' raise_from(ImportError(msg), exc) diff --git a/plugins/modules/docker_container_copy_into.py b/plugins/modules/docker_container_copy_into.py index 71b0ea590..f140bfe6a 100644 --- a/plugins/modules/docker_container_copy_into.py +++ b/plugins/modules/docker_container_copy_into.py @@ -146,7 +146,6 @@ import base64 import io import os -import random import stat import traceback diff --git a/plugins/modules/docker_container_exec.py b/plugins/modules/docker_container_exec.py index d91261262..95fde4f71 100644 --- a/plugins/modules/docker_container_exec.py +++ b/plugins/modules/docker_container_exec.py @@ -167,11 +167,6 @@ RequestException, ) -from ansible_collections.community.docker.plugins.module_utils.socket_helper import ( - shutdown_writing, - write_to_socket, -) - from ansible_collections.community.docker.plugins.module_utils.socket_handler import ( DockerSocketHandlerModule, ) diff --git a/plugins/modules/docker_volume.py b/plugins/modules/docker_volume.py index 9a8e50cd3..09b1d386b 100644 --- a/plugins/modules/docker_volume.py +++ b/plugins/modules/docker_volume.py @@ -118,7 +118,7 @@ import traceback from ansible.module_utils.common.text.converters import to_native -from ansible.module_utils.six import iteritems, text_type +from ansible.module_utils.six import iteritems from ansible_collections.community.docker.plugins.module_utils.common_api import ( AnsibleDockerClient, @@ -131,7 +131,6 @@ from ansible_collections.community.docker.plugins.module_utils._api.errors import ( APIError, DockerException, - NotFound, )