Skip to content

Commit

Permalink
Remove unneccessary imports (#575)
Browse files Browse the repository at this point in the history
* Remove unneccessary imports.

* Add noqas.
  • Loading branch information
felixfontein authored Feb 9, 2023
1 parent eb186f0 commit 54a3dc1
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 50 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/remove-unneeded-imports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "various plugins and modules - remove unnecessary imports (https://github.com/ansible-collections/community.docker/pull/574)."
1 change: 0 additions & 1 deletion plugins/action/docker_container_copy_into.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions plugins/connection/nsenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/_api/transport/ssladapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 18 additions & 21 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
)


Expand Down
13 changes: 6 additions & 7 deletions plugins/module_utils/common_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/module_container/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
from ansible_collections.community.docker.plugins.module_utils._api.utils.utils import (
convert_port_bindings,
normalize_links,
parse_repository_tag,
)


Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/socket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions plugins/module_utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions plugins/module_utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion plugins/modules/docker_container_copy_into.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
import base64
import io
import os
import random
import stat
import traceback

Expand Down
5 changes: 0 additions & 5 deletions plugins/modules/docker_container_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
3 changes: 1 addition & 2 deletions plugins/modules/docker_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -131,7 +131,6 @@
from ansible_collections.community.docker.plugins.module_utils._api.errors import (
APIError,
DockerException,
NotFound,
)


Expand Down

0 comments on commit 54a3dc1

Please sign in to comment.