Skip to content

Commit

Permalink
Bulk migration to Python 3.6 f-strings (ansible-collections#1810)
Browse files Browse the repository at this point in the history
Bulk migration to Python 3.6 f-strings

SUMMARY
We've dropped support for Python <3.6, bulk migrate to fstrings and perform some general string cleanup
A combination of

black --preview
flynt
some manual cleanup

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/
tests/
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@de33821
  • Loading branch information
tremble authored and github-actions[bot] committed Oct 27, 2023
1 parent 5510cff commit a3baee8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions plugins/modules/acm_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def ensure_tags(client, module, resource_arn, existing_tags, tags, purge_tags):
botocore.exceptions.ClientError,
botocore.exceptions.BotoCoreError,
) as e:
module.fail_json_aws(e, "Couldn't add tags to certificate {0}".format(resource_arn))
module.fail_json_aws(e, f"Couldn't add tags to certificate {resource_arn}")
if tags_to_remove and not module.check_mode:
# remove_tags_from_certificate wants a list of key, value pairs, not a list of keys.
tags_list = [{"Key": key, "Value": existing_tags.get(key)} for key in tags_to_remove]
Expand All @@ -289,7 +289,7 @@ def ensure_tags(client, module, resource_arn, existing_tags, tags, purge_tags):
botocore.exceptions.ClientError,
botocore.exceptions.BotoCoreError,
) as e:
module.fail_json_aws(e, "Couldn't remove tags from certificate {0}".format(resource_arn))
module.fail_json_aws(e, f"Couldn't remove tags from certificate {resource_arn}")
new_tags = deepcopy(existing_tags)
for key, value in tags_to_add.items():
new_tags[key] = value
Expand Down Expand Up @@ -441,7 +441,7 @@ def ensure_certificates_present(client, module, acm, certificates, desired_tags,
cert_arn = None
changed = False
if len(certificates) > 1:
msg = "More than one certificate with Name=%s exists in ACM in this region" % module.params["name_tag"]
msg = f"More than one certificate with Name={module.params['name_tag']} exists in ACM in this region"
module.fail_json(msg=msg, certificates=certificates)
elif len(certificates) == 1:
# Update existing certificate that was previously imported to ACM.
Expand Down Expand Up @@ -496,7 +496,7 @@ def main():
absent_args = ["certificate_arn", "domain_name", "name_tag"]
if sum([(module.params[a] is not None) for a in absent_args]) < 1:
for a in absent_args:
module.debug("%s is %s" % (a, module.params[a]))
module.debug(f"{a} is {module.params[a]}")
module.fail_json(
msg="If 'state' is specified as 'present' then at least one of 'name_tag', 'certificate_arn' or 'domain_name' must be specified"
)
Expand All @@ -505,7 +505,7 @@ def main():
absent_args = ["certificate_arn", "domain_name", "name_tag"]
if sum([(module.params[a] is not None) for a in absent_args]) != 1:
for a in absent_args:
module.debug("%s is %s" % (a, module.params[a]))
module.debug(f"{a} is {module.params[a]}")
module.fail_json(
msg="If 'state' is specified as 'absent' then exactly one of 'name_tag', 'certificate_arn' or 'domain_name' must be specified"
)
Expand Down Expand Up @@ -543,7 +543,7 @@ def main():
only_tags=filter_tags,
)

module.debug("Found %d corresponding certificates in ACM" % len(certificates))
module.debug(f"Found {len(certificates)} corresponding certificates in ACM")
if module.params["state"] == "present":
ensure_certificates_present(client, module, acm, certificates, desired_tags, filter_tags)

Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/acm_certificate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def main():
)

if module.params["certificate_arn"] and len(certificates) != 1:
module.fail_json(msg="No certificate exists in this region with ARN %s" % module.params["certificate_arn"])
module.fail_json(msg=f"No certificate exists in this region with ARN {module.params['certificate_arn']}")

module.exit_json(certificates=certificates)

Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ec2_ami_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def copy_image(module, ec2):

try:
if module.params.get("tag_equality"):
filters = [{"Name": "tag:%s" % k, "Values": [v]} for (k, v) in module.params.get("tags").items()]
filters = [{"Name": f"tag:{k}", "Values": [v]} for (k, v) in module.params.get("tags").items()]
filters.append(dict(Name="state", Values=["available", "pending"]))
images = ec2.describe_images(Filters=filters)
if len(images["Images"]) > 0:
Expand All @@ -197,7 +197,7 @@ def copy_image(module, ec2):
except (ClientError, BotoCoreError) as e:
module.fail_json_aws(e, msg="Could not copy AMI")
except Exception as e:
module.fail_json(msg="Unhandled exception. (%s)" % to_native(e))
module.fail_json(msg=f"Unhandled exception. ({to_native(e)})")


def main():
Expand Down

0 comments on commit a3baee8

Please sign in to comment.