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

Test ruff #2070

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions changelogs/fragments/add_ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trivial:
- "Lint collection using ``ruff`` linter."

minor_changes:
- "Introduce ``ruff`` linter into CI."
2 changes: 1 addition & 1 deletion plugins/action/s3_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ActionModule(ActionBase):
TRANSFERS_FILES = True

def run(self, tmp=None, task_vars=None):
"""handler for s3_object operations
"""Handler for s3_object operations.

This adds the magic that means 'src' can point to both a 'remote' file
on the 'host' or in the 'files/' lookup path on the controller.
Expand Down
1 change: 0 additions & 1 deletion plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ def _add_hosts(
:param str hostvars_suffix: ends the hostvars variable name with this suffix
:param bool use_contrib_script_compatible_ec2_tag_keys: transform the host name with the legacy naming system
"""

for name, host_vars in self.iter_entry(
hosts,
hostnames,
Expand Down
1 change: 0 additions & 1 deletion plugins/lookup/secretsmanager_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def run(self, terms, variables, **kwargs):
:variables: ansible variables active at the time of the lookup
:returns: A list of parameter values or a list of dictionaries if bypath=True.
"""

super().run(terms, variables, **kwargs)

on_missing = self.get_option("on_missing")
Expand Down
1 change: 0 additions & 1 deletion plugins/lookup/ssm_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def run(self, terms, variables, **kwargs):
:kwarg variables: ansible variables active at the time of the lookup
:returns: A list of parameter values or a list of dictionaries if bypath=True.
"""

super().run(terms, variables, **kwargs)

on_missing = self.get_option("on_missing")
Expand Down
8 changes: 3 additions & 5 deletions plugins/module_utils/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# - acm_certificate
# - acm_certificate_info

"""
Common Amazon Certificate Manager facts shared between modules
"""
"""Common Amazon Certificate Manager facts shared between modules."""

try:
from botocore.exceptions import BotoCoreError
Expand Down Expand Up @@ -49,7 +47,7 @@ def runner(*args, **kwargs):


class ACMServiceManager:
"""Handles ACM Facts Services"""
"""Handles ACM Facts Services."""

def __init__(self, module):
self.module = module
Expand Down Expand Up @@ -206,7 +204,7 @@ def _filter_certificate(cert):
def get_domain_of_cert(self, arn, **kwargs):
"""
returns the domain name of a certificate (encoded in the public cert)
for a given ARN A cert with that ARN must already exist
for a given ARN A cert with that ARN must already exist.
"""
if arn is None:
self.module.fail_json(msg="Internal error with ACM domain fetching, no certificate ARN specified")
Expand Down
5 changes: 2 additions & 3 deletions plugins/module_utils/arn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def validate_aws_arn(

def parse_aws_arn(arn):
"""
Based on https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html
Based on https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html.

The following are the general formats for ARNs.
arn:partition:service:region:account-id:resource-id
Expand Down Expand Up @@ -70,8 +70,7 @@ def parse_aws_arn(arn):
# aren't specific to the EC2 service
def is_outpost_arn(arn):
"""
Validates that the ARN is for an AWS Outpost

Validates that the ARN is for an AWS Outpost.

API Specification Document:
https://docs.aws.amazon.com/outposts/latest/APIReference/API_Outpost.html
Expand Down
4 changes: 1 addition & 3 deletions plugins/module_utils/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
This module adds shared support for Batch modules.
"""
"""This module adds shared support for Batch modules."""

from ansible.module_utils.common.dict_transformations import snake_dict_to_camel_dict

Expand Down
13 changes: 5 additions & 8 deletions plugins/module_utils/botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None
ValueError,
botocore.exceptions.ProfileNotFound, botocore.exceptions.PartialCredentialsError,
botocore.exceptions.NoCredentialsError, botocore.exceptions.ConfigParseError,
botocore.exceptions.NoRegionError
botocore.exceptions.NoRegionError.
"""
try:
return _boto3_conn(conn_type=conn_type, resource=resource, region=region, endpoint=endpoint, **params)
Expand All @@ -113,7 +113,7 @@ def boto3_conn(module, conn_type=None, resource=None, region=None, endpoint=None
def _merge_botocore_config(config_a, config_b):
"""
Merges the extra configuration options from config_b into config_a.
Supports both botocore.config.Config objects and dicts
Supports both botocore.config.Config objects and dicts.
"""
if not config_b:
return config_a
Expand Down Expand Up @@ -316,7 +316,7 @@ def paginated_query_with_retries(client, paginator_name, retry_decorator=None, *


def gather_sdk_versions():
"""Gather AWS SDK (boto3 and botocore) dependency versions
"""Gather AWS SDK (boto3 and botocore) dependency versions.

Returns {'boto3_version': str, 'botocore_version': str}
Returns {} if either module is not installed
Expand Down Expand Up @@ -412,9 +412,7 @@ def normalize_boto3_result(result):


def enable_placebo(session):
"""
Helper to record or replay offline modules for testing purpose.
"""
"""Helper to record or replay offline modules for testing purpose."""
if "_ANSIBLE_PLACEBO_RECORD" in os.environ:
import placebo

Expand Down Expand Up @@ -454,9 +452,8 @@ def check_sdk_version_supported(botocore_version=None, boto3_version=None, warn=
AnsibleBotocoreError - If botocore/boto3 is missing
returns
False if boto3 or botocore is less than the minimum supported versions
True if boto3 and botocore are greater than or equal the the minimum supported versions
True if boto3 and botocore are greater than or equal the the minimum supported versions.
"""

botocore_version = botocore_version or MINIMUM_BOTOCORE_VERSION
boto3_version = boto3_version or MINIMUM_BOTO3_VERSION

Expand Down
4 changes: 1 addition & 3 deletions plugins/module_utils/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def _retry_func(


class CloudRetry:
"""
The base class to be used by other cloud providers to provide a backoff/retry decorator based on status codes.
"""
"""The base class to be used by other cloud providers to provide a backoff/retry decorator based on status codes."""

base_class = type(None)

Expand Down
6 changes: 2 additions & 4 deletions plugins/module_utils/cloudfront_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# - cloudfront_invalidation
# - cloudfront_origin_access_identity

"""
Common cloudfront facts shared between modules
"""
"""Common cloudfront facts shared between modules."""

from functools import partial

Expand Down Expand Up @@ -49,7 +47,7 @@ def _cloudfront_paginate_build_full_result(client, client_method, **kwargs):


class CloudFrontFactsServiceManager:
"""Handles CloudFront Facts Services"""
"""Handles CloudFront Facts Services."""

CLOUDFRONT_CLIENT_API_MAPPING = {
"get_distribution": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2017 Michael De La Rue | Ansible
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""This module adds shared support for generic Amazon AWS modules
"""This module adds shared support for generic Amazon AWS modules.

In order to use this module, include it as part of a custom
module as shown below.
Expand Down
4 changes: 1 addition & 3 deletions plugins/module_utils/direct_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
This module adds shared support for Direct Connect modules.
"""
"""This module adds shared support for Direct Connect modules."""

import traceback

Expand Down
7 changes: 2 additions & 5 deletions plugins/module_utils/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_ec2_security_group_ids_from_names(sec_group_list, ec2_connection, vpc_id
"""Return list of security group IDs from security group names. Note that security group names are not unique
across VPCs. If a name exists across multiple VPCs and no VPC ID is supplied, all matching IDs will be returned. This
will probably lead to a boto exception if you attempt to assign both IDs to a resource so ensure you wrap the call in
a try block
a try block.
"""

def get_sg_name(sg):
Expand Down Expand Up @@ -159,7 +159,6 @@ def add_ec2_tags(client, module, resource_id, tags_to_set, retry_codes=None):
:param tags_to_set: A dictionary of key/value pairs to set
:param retry_codes: additional boto3 error codes to trigger retries
"""

if not tags_to_set:
return False
if module.check_mode:
Expand Down Expand Up @@ -188,7 +187,6 @@ def remove_ec2_tags(client, module, resource_id, tags_to_unset, retry_codes=None
:param tags_to_unset: a list of tag keys to removes
:param retry_codes: additional boto3 error codes to trigger retries
"""

if not tags_to_unset:
return False
if module.check_mode:
Expand Down Expand Up @@ -251,7 +249,6 @@ def ensure_ec2_tags(client, module, resource_id, resource_type=None, tags=None,
:param retry_codes: additional boto3 error codes to trigger retries
:return: changed: returns True if the tags are changed
"""

if tags is None:
return False

Expand Down Expand Up @@ -292,7 +289,7 @@ def normalize_ec2_vpc_dhcp_config(option_config):
"netbios-name-servers": ["10.0.0.1", "10.0.1.1"],
"netbios-node-type": "1",
"ntp-servers": ["10.0.0.2", "10.0.1.2"]
},
},.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove the , here and lin 284 rather than adding a .

"""
config_data = {}

Expand Down
6 changes: 1 addition & 5 deletions plugins/module_utils/elb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def _get_elb(connection, module, elb_name):
:param elb_name: Name of load balancer to get
:return: boto3 ELB dict or None if not found
"""

try:
load_balancer_paginator = connection.get_paginator("describe_load_balancers")
return (load_balancer_paginator.paginate(Names=[elb_name]).build_full_result())["LoadBalancers"][0]
Expand All @@ -56,7 +55,6 @@ def get_elb_listener(connection, module, elb_arn, listener_port):
:param listener_port: Port of the listener to look for
:return: boto3 ELB listener dict or None if not found
"""

try:
listener_paginator = connection.get_paginator("describe_listeners")
listeners = (
Expand Down Expand Up @@ -84,7 +82,6 @@ def get_elb_listener_rules(connection, module, listener_arn):
:param listener_arn: ARN of the ELB listener
:return: boto3 ELB rules list
"""

try:
return AWSRetry.jittered_backoff()(connection.describe_rules)(ListenerArn=listener_arn)["Rules"]
except (BotoCoreError, ClientError) as e:
Expand All @@ -93,14 +90,13 @@ def get_elb_listener_rules(connection, module, listener_arn):

def convert_tg_name_to_arn(connection, module, tg_name):
"""
Get ARN of a target group using the target group's name
Get ARN of a target group using the target group's name.

:param connection: AWS boto3 elbv2 connection
:param module: Ansible module
:param tg_name: Name of the target group
:return: target group ARN string
"""

try:
response = AWSRetry.jittered_backoff()(connection.describe_target_groups)(Names=[tg_name])
except (BotoCoreError, ClientError) as e:
Expand Down
Loading
Loading