Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused/duplicate imports #217

Merged
merged 2 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/217-duplicate-imports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- various AWS plugins and module_utils - Cleanup unused imports (https://github.com/ansible-collections/amazon.aws/pull/217).
7 changes: 0 additions & 7 deletions plugins/lookup/aws_account_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
(or all attributes if one is not specified).
"""

import os

from ansible.errors import AnsibleError

try:
Expand All @@ -63,13 +61,8 @@
raise AnsibleError("The lookup aws_account_attribute requires boto3 and botocore.")

from ansible.module_utils._text import to_native
from ansible.module_utils.six import string_types
from ansible.plugins import AnsiblePlugin
from ansible.plugins.lookup import LookupBase

from ..module_utils.ec2 import boto3_conn
from ..module_utils.ec2 import get_aws_connection_info


def _boto3_conn(region, credentials):
boto_profile = credentials.pop('aws_profile', None)
Expand Down
1 change: 0 additions & 1 deletion plugins/lookup/aws_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
except ImportError:
raise AnsibleError("The lookup aws_secret requires boto3 and botocore.")

from ansible.plugins import AnsiblePlugin
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_native
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
Expand Down
2 changes: 0 additions & 2 deletions plugins/module_utils/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
"""
Common Amazon Certificate Manager facts shared between modules
"""
import traceback

try:
import botocore
from botocore.exceptions import BotoCoreError, ClientError
except ImportError:
pass
Expand Down
2 changes: 0 additions & 2 deletions plugins/module_utils/cloudfront_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
except ImportError:
pass

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from .ec2 import AWSRetry
from .ec2 import boto3_tag_list_to_ansible_dict

Expand Down
2 changes: 0 additions & 2 deletions plugins/module_utils/direct_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
except ImportError:
pass

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from .ec2 import AWSRetry


Expand Down
10 changes: 5 additions & 5 deletions plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
from ansible.module_utils.ansible_release import __version__
from ansible.module_utils.basic import env_fallback
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils.common.dict_transformations import _camel_to_snake
from ansible.module_utils.common.dict_transformations import _snake_to_camel
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict
from ansible.module_utils.six import binary_type
from ansible.module_utils.six import string_types
from ansible.module_utils.six import text_type
from ansible.module_utils.six import integer_types
# Used to live here, moved into ansible.module_utils.common.dict_transformations
from ansible.module_utils.common.dict_transformations import _camel_to_snake # pylint: disable=unused-import
from ansible.module_utils.common.dict_transformations import _snake_to_camel # pylint: disable=unused-import
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict # pylint: disable=unused-import
from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict # pylint: disable=unused-import

from .cloud import CloudRetry

Expand Down Expand Up @@ -581,7 +582,6 @@ def get_sg_id(sg, boto3):

if len(unmatched) > 0:
# If we have unmatched names that look like an ID, assume they are
import re
sec_group_id_list[:] = [sg for sg in unmatched if re.match('sg-[a-fA-F0-9]+$', sg)]
still_unmatched = [sg for sg in unmatched if not re.match('sg-[a-fA-F0-9]+$', sg)]
if len(still_unmatched) > 0:
Expand Down
2 changes: 0 additions & 2 deletions plugins/module_utils/elbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
except ImportError:
pass

from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict

from .ec2 import AWSRetry
from .ec2 import ansible_dict_to_boto3_tag_list
from .ec2 import boto3_tag_list_to_ansible_dict
Expand Down
1 change: 0 additions & 1 deletion plugins/module_utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ansible.module_utils.urls import open_url

from .ec2 import HAS_BOTO3
from .ec2 import boto3_conn
from .ec2 import get_aws_connection_info


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
__metaclass__ = type


try:
from botocore.exceptions import BotoCoreError, ClientError
except ImportError:
pass # Handled by AnsibleAWSModule

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/compat/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# One unittest needs to import builtins via __import__() so we need to have
# the string that represents it
try:
import __builtin__
import __builtin__ # pylint: disable=unused-import
except ImportError:
BUILTINS = 'builtins'
else:
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/module_utils/ec2/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
__metaclass__ = type

try:
import boto3
# We explicitly want to know if boto3/botocore are available, they're used
# by the code we're testing even if we don't directly use them.
import boto3 # pylint: disable=unused-import
import botocore
HAS_BOTO3 = True
except Exception:
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/modules/test_cloudformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import pytest

from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import placeboify, maybe_sleep
# Magic...
from ansible_collections.amazon.aws.tests.unit.utils.amazon_placebo_fixtures import maybe_sleep, placeboify # pylint: disable=unused-import

from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto_exception
from ansible_collections.amazon.aws.plugins.modules import cloudformation as cfn_module

Expand Down
1 change: 0 additions & 1 deletion tests/unit/plugins/lookup/test_aws_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import pytest
import datetime
import sys
from copy import copy

from ansible.errors import AnsibleError
Expand Down