Skip to content

Commit e7bf945

Browse files
committed
Merge branch 'mr/trespeuch/ruff' into 'master'
Fix additional ruff check violations See merge request it/e3-aws!142
2 parents 2e7aae7 + ebb9a9d commit e7bf945

21 files changed

Lines changed: 50 additions & 52 deletions

examples/deploy_simple_stack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
import sys
2323
from functools import cached_property
24-
from typing_extensions import override
2524

2625
from troposphere import GetAtt, Ref, Tags, ec2, iam
26+
from typing_extensions import override
2727

2828
from e3.aws.troposphere import CFNProjectMain, Construct, Stack, name_to_id
2929
from e3.aws.troposphere.ec2 import VPCv2

src/e3/aws/cfn/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import yaml
2323
from typing_extensions import override
2424

25+
from e3.aws import iterate
2526
from e3.env import Env
2627

2728
from typing import TYPE_CHECKING, cast
@@ -41,7 +42,7 @@
4142
ValidateTemplateOutputTypeDef,
4243
)
4344

44-
from typing import Any, ParamSpec, TypeVar
45+
from typing import Any, ParamSpec, Self, TypeVar
4546

4647
P = ParamSpec("P")
4748
T = TypeVar("T")
@@ -517,7 +518,7 @@ def __init__(
517518
self.uuid = str(uuid.uuid1(clock_seq=int(1000 * time.time())))
518519
self.latest_read_event: StackEvent | None = None
519520

520-
def add(self, element: Stack | Resource) -> Stack:
521+
def add(self, element: Stack | Resource) -> Self:
521522
"""Add a resource or merge a stack.
522523
523524
:param element: if a resource add the resource to the stack. If a stack
@@ -533,7 +534,7 @@ def add(self, element: Stack | Resource) -> Stack:
533534
self.resources[element.name] = element
534535
return self
535536

536-
def __iadd__(self, element: Stack | Resource) -> Stack:
537+
def __iadd__(self, element: Stack | Resource) -> Self:
537538
"""Add a resource or merge a stack.
538539
539540
:param element: if a resource add the resource to the stack. If a stack
@@ -664,9 +665,7 @@ def exists(self) -> bool:
664665
"""
665666
try:
666667
self.state()
667-
except Exception:
668-
# Documentation does not specify the right exception that is raised
669-
# by botocore.
668+
except Exception: # noqa: BLE001
670669
return False
671670
return True
672671

@@ -792,8 +791,6 @@ def events(
792791
:param mark_as_read: if True, all events read won't be returned on next
793792
calls to events method.
794793
"""
795-
from e3.aws import iterate
796-
797794
latest_read_event = self.latest_read_event
798795
if mark_as_read:
799796
self.latest_read_event = None

src/e3/aws/cfn/iam.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def append(self, statement: Statement) -> PolicyDocument:
204204
self.statements.append(statement)
205205
return self
206206

207-
def extend(self, statements: list[Statement]) -> PolicyDocument:
207+
def extend(self, statements: list[Statement]) -> Self:
208208
"""Append a list of statements.
209209
210210
:param statements: IAM Statements
@@ -213,7 +213,7 @@ def extend(self, statements: list[Statement]) -> PolicyDocument:
213213
self.statements.extend(statements)
214214
return self
215215

216-
def __iadd__(self, statements: list[Statement]) -> PolicyDocument: # type: ignore[misc]
216+
def __iadd__(self, statements: list[Statement]) -> Self: # type: ignore[misc]
217217
"""See extend."""
218218
return self.extend(statements)
219219

src/e3/aws/ec2/ami.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ def find(
233233
continue
234234

235235
consider_ami = True
236-
for tag in tag_filters:
237-
if not re.match(tag_filters[tag], ami.tags.get(tag, "")):
236+
for tag, pattern in tag_filters.items():
237+
if not re.match(pattern, ami.tags.get(tag, "")):
238238
consider_ami = False
239239
continue
240240

src/e3/aws/troposphere/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,8 @@ def _upload_file(
168168
:param check_exists: check if an S3 object exists before uploading it
169169
:param dry_run: don't upload the file if set
170170
"""
171-
logger.info(
172-
"Upload {} to {}:{}".format(
173-
os.path.relpath(file, root_dir).replace("\\", "/"), s3_bucket, s3_key
174-
)
175-
)
171+
rel_path = os.path.relpath(file, root_dir).replace("\\", "/")
172+
logger.info(f"Upload {rel_path} to {s3_bucket}:{s3_key}")
176173

177174
if client is None:
178175
return

src/e3/aws/troposphere/awslambda/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
from e3.aws.troposphere import Stack
4646

47-
from typing import Any
47+
from typing import Any, Self
4848

4949
logger = logging.getLogger("e3.aws.troposphere.awslambda")
5050

@@ -154,7 +154,7 @@ def __init__(
154154
self._archive_tmpd: TemporaryDirectory | None = None
155155
self._archive_dir: str | None = None
156156

157-
def __enter__(self) -> PyFunctionAsset:
157+
def __enter__(self) -> Self:
158158
"""Create a temporary archive directory."""
159159
if self._archive_dir is None:
160160
self._archive_tmpd = TemporaryDirectory()
@@ -826,10 +826,10 @@ def _show_archive_files(self, archive_path: str | Path) -> list[str]:
826826
:param archive_path: path to the archive
827827
:return: the list of files in the archive
828828
"""
829-
with zipfile.ZipFile(archive_path) as zip:
829+
with zipfile.ZipFile(archive_path) as archive:
830830
return [
831831
f"{line}\n"
832-
for line in sorted(zip.namelist())
832+
for line in sorted(archive.namelist())
833833
if not line.endswith(".pyc")
834834
]
835835

@@ -1306,11 +1306,11 @@ def create_alias(
13061306
:param default_name: default alias name if none is specified
13071307
"""
13081308
name = config.name if config.name is not None else default_name
1309-
id = name_to_id(f"{self.lambda_name}-{name}-alias")
1309+
alias_id = name_to_id(f"{self.lambda_name}-{name}-alias")
13101310
return Alias(
1311-
name=id,
1311+
name=alias_id,
13121312
description=f"{name} alias for {self.lambda_name} lambda",
1313-
alias_name=config.name if config.name is not None else id,
1313+
alias_name=config.name if config.name is not None else alias_id,
13141314
lambda_arn=self.lambda_arn,
13151315
lambda_version=config.version,
13161316
provisioned_concurrency_config=config.provisioned_concurrency_config,

src/e3/aws/troposphere/awslambda/docker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
import logging
66
from datetime import datetime, timezone
7-
from pathlib import Path
87

98
from e3.aws.troposphere.awslambda import Architecture, Function, UnknownPlatform
109
from e3.aws.util.ecr import build_and_push_image
1110

1211
from typing import TYPE_CHECKING
1312

1413
if TYPE_CHECKING:
14+
from pathlib import Path
15+
1516
from python_on_whales import DockerClient
1617
from troposphere import AWSObject, GetAtt, awslambda
1718

src/e3/aws/troposphere/awslambda/flask_apigateway_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ def create_flask_wsgi_environ(self, event: dict, context: dict) -> dict:
241241
environ["CONTENT_LENGTH"] = str(len(body))
242242

243243
# Export headers into the WSGI environment
244-
for header in headers:
244+
for header, value in headers.items():
245245
wsgi_name = "HTTP_" + header.upper().replace("-", "_")
246-
environ[wsgi_name] = headers[header]
246+
environ[wsgi_name] = value
247247

248248
# Set HTTP_COOKIE if necessary
249249
if cookies:

src/e3/aws/troposphere/cloudfront/data/lambda_invalidate_head.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import os
66
import time
77

8-
from typing import TYPE_CHECKING
9-
108
import boto3
119

10+
from typing import TYPE_CHECKING
11+
1212
if TYPE_CHECKING:
1313
from typing import Any
1414

src/e3/aws/troposphere/iam/policy_document.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
if TYPE_CHECKING:
1010
from e3.aws.troposphere.iam.policy_statement import PolicyStatement
1111

12+
from typing import Self
13+
1214

1315
@dataclass
1416
class PolicyDocument:
@@ -29,7 +31,7 @@ def __add__(self, other: PolicyDocument) -> PolicyDocument:
2931
"""
3032
return PolicyDocument(statements=self.statements + other.statements)
3133

32-
def __iadd__(self, other: PolicyDocument) -> PolicyDocument:
34+
def __iadd__(self, other: PolicyDocument) -> Self:
3335
"""Merge another policy document into this one.
3436
3537
:param other: the policy document to merge

0 commit comments

Comments
 (0)