Skip to content

Commit a48f9bf

Browse files
refactor(general): add support for ruff format (#6512)
* Enable Ruff format * Enable Ruff format
1 parent e9cb5e5 commit a48f9bf

File tree

60 files changed

+63
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+63
-169
lines changed

.github/workflows/quality_check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ jobs:
6363
run: make dev-quality-code
6464
- name: Checking third-party library licenses
6565
run: make check-licenses
66+
- name: Checking and enforcing format
67+
run: make format-check
6668
- name: Formatting and Linting
6769
run: make lint
6870
- name: Static type checking

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ repos:
1212
- id: check-toml
1313
- repo: local
1414
hooks:
15-
- id: black
16-
name: formatting::black
17-
entry: poetry run black
15+
- id: ruff
16+
name: formatting::ruff
17+
entry: poetry run ruff format
1818
language: system
1919
types: [python]
2020
- id: ruff
21-
name: linting-format::ruff
21+
name: linting::ruff
2222
entry: poetry run ruff check
2323
language: system
2424
types: [python]

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ dev-gitpod:
2525
check-licenses:
2626
poetry run licensecheck -u poetry:dev
2727

28+
format-check:
29+
poetry run ruff format aws_lambda_powertools tests examples --check
30+
2831
format:
29-
poetry run black aws_lambda_powertools tests examples
32+
poetry run ruff format aws_lambda_powertools tests examples
3033

3134
lint: format
3235
poetry run ruff check aws_lambda_powertools tests examples

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,6 @@ def _validate_response_validation_error_http_code(
16041604
response_validation_error_http_code: HTTPStatus | int | None,
16051605
enable_validation: bool,
16061606
) -> HTTPStatus:
1607-
16081607
if response_validation_error_http_code and not enable_validation:
16091608
msg = "'response_validation_error_http_code' cannot be set when enable_validation is False."
16101609
raise ValueError(msg)
@@ -1613,7 +1612,6 @@ def _validate_response_validation_error_http_code(
16131612
not isinstance(response_validation_error_http_code, HTTPStatus)
16141613
and response_validation_error_http_code is not None
16151614
):
1616-
16171615
try:
16181616
response_validation_error_http_code = HTTPStatus(response_validation_error_http_code)
16191617
except ValueError:

aws_lambda_powertools/event_handler/openapi/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class OpenAPIExtensions(BaseModel):
3636
@model_validator(mode="before")
3737
def serialize_openapi_extension_v2(self):
3838
if isinstance(self, dict) and self.get("openapi_extensions"):
39-
4039
openapi_extension_value = self.get("openapi_extensions")
4140

4241
for extension_key in openapi_extension_value:

aws_lambda_powertools/logging/logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,15 +1205,15 @@ def flush_buffer(self) -> None:
12051205
buffer = self._buffer_cache.get(tracer_id)
12061206
if not buffer:
12071207
return
1208-
1208+
12091209
if not self._buffer_config:
12101210
return
1211-
1211+
12121212
# Check ALC level against buffer level
12131213
lambda_log_level = self._get_aws_lambda_log_level()
12141214
if lambda_log_level:
12151215
# Check if buffer level is less verbose than ALC
1216-
if (logging.getLevelName(lambda_log_level) > logging.getLevelName(self._buffer_config.buffer_at_verbosity)):
1216+
if logging.getLevelName(lambda_log_level) > logging.getLevelName(self._buffer_config.buffer_at_verbosity):
12171217
warnings.warn(
12181218
"Advanced Logging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. "
12191219
"Some logs might be missing",

aws_lambda_powertools/utilities/batch/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ def _clean(self):
296296

297297
if self._entire_batch_failed() and self.raise_on_entire_batch_failure:
298298
raise BatchProcessingError(
299-
msg=f"All records failed processing. {len(self.exceptions)} individual errors logged "
300-
f"separately below.",
299+
msg=f"All records failed processing. {len(self.exceptions)} individual errors logged separately below.",
301300
child_exceptions=self.exceptions,
302301
)
303302

aws_lambda_powertools/utilities/data_classes/code_pipeline_job_event.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ def put_artifact(self, artifact_name: str, body: Any, content_type: str) -> None
314314
# So we are using if/else instead.
315315

316316
if self.data.encryption_key:
317-
318317
encryption_key_id = self.data.encryption_key.get_id
319318
encryption_key_type = self.data.encryption_key.get_type
320319
if encryption_key_type == "KMS":

aws_lambda_powertools/utilities/data_classes/transfer_family_event.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def source_ip(self) -> str:
3939

4040

4141
class TransferFamilyAuthorizerResponse:
42-
4342
def _build_authentication_response(
4443
self,
4544
role_arn: str,
@@ -51,7 +50,6 @@ def _build_authentication_response(
5150
user_uid: int | None = None,
5251
public_keys: str | None = None,
5352
) -> dict[str, Any]:
54-
5553
response: dict[str, Any] = {}
5654

5755
if home_directory_type == "PATH":

aws_lambda_powertools/utilities/data_masking/provider/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def erase(
8282
masking_rules: dict | None = None,
8383
**kwargs,
8484
) -> Any:
85-
8685
result: Any = DATA_MASKING_STRING
8786

8887
if not any([dynamic_mask, custom_mask, regex_pattern, mask_format, masking_rules]):

0 commit comments

Comments
 (0)