Skip to content

Commit 7f9d02f

Browse files
ran-isenbergRan Isenberg
andauthored
feature: add ruff support instead of flake8, yapf and isort (#756)
Co-authored-by: Ran Isenberg <ran.isenberg@ranthebuilder.cloud>
1 parent 0d2a2c2 commit 7f9d02f

28 files changed

+322
-442
lines changed

.flake8

Lines changed: 0 additions & 5 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ repos:
2424
name: Tests should begin with test_
2525
args: ["--django"]
2626
exclude: "^(?!helpers/)"
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
# Ruff version.
29+
rev: v0.1.2
30+
hooks:
31+
# Run the Ruff linter.
32+
- id: ruff
33+
# Run the Ruff formatter.
34+
- id: ruff-format

.style

Lines changed: 0 additions & 7 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ dev:
1010
poetry install
1111
npm ci
1212

13-
format-fix:
14-
poetry run isort .
15-
poetry run yapf -vv --style=./.style -r --in-place .
16-
1713
format:
18-
poetry run isort .
19-
poetry run yapf -d -vv --style=./.style -r .
14+
poetry run ruff check .
15+
16+
format-fix:
17+
poetry run ruff format .
2018

2119
lint: format
22-
@echo "Running flake8"
23-
poetry run flake8 service/* cdk/* tests/*
2420
@echo "Running mypy"
2521
$(MAKE) mypy-lint
2622

Makefile_windows

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ dev:
88
npm ci
99

1010
format:
11-
poetry run isort .
12-
poetry run yapf -d -vv --style=.\.style -r .
11+
poetry run ruff check .
12+
13+
format-fix:
14+
poetry run ruff format .
1315

1416
lint: format
15-
@echo "Running flake8"
16-
poetry run flake8 service.\* cdk\* tests\* docs\examples\*
1717
@echo "Running mypy"
1818
$(MAKE) mypy-lint
1919

cdk/service/api_construct.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class ApiConstruct(Construct):
15-
1615
def __init__(self, scope: Construct, id_: str, appconfig_app_name: str) -> None:
1716
super().__init__(scope, id_)
1817
self.id_ = id_
@@ -21,8 +20,9 @@ def __init__(self, scope: Construct, id_: str, appconfig_app_name: str) -> None:
2120
self.common_layer = self._build_common_layer()
2221
self.rest_api = self._build_api_gw()
2322
api_resource: aws_apigateway.Resource = self.rest_api.root.add_resource('api').add_resource(constants.GW_RESOURCE)
24-
self.create_order_func = self._add_post_lambda_integration(api_resource, self.lambda_role, self.api_db.db, appconfig_app_name,
25-
self.api_db.idempotency_db)
23+
self.create_order_func = self._add_post_lambda_integration(
24+
api_resource, self.lambda_role, self.api_db.db, appconfig_app_name, self.api_db.idempotency_db
25+
)
2626
self.monitoring = CrudMonitoring(self, id_, self.rest_api, self.api_db.db, self.api_db.idempotency_db, [self.create_order_func])
2727

2828
def _build_api_gw(self) -> aws_apigateway.RestApi:
@@ -44,30 +44,33 @@ def _build_lambda_role(self, db: dynamodb.Table, idempotency_table: dynamodb.Tab
4444
constants.SERVICE_ROLE_ARN,
4545
assumed_by=iam.ServicePrincipal('lambda.amazonaws.com'),
4646
inline_policies={
47-
'dynamic_configuration':
48-
iam.PolicyDocument(statements=[
47+
'dynamic_configuration': iam.PolicyDocument(
48+
statements=[
4949
iam.PolicyStatement(
5050
actions=['appconfig:GetLatestConfiguration', 'appconfig:StartConfigurationSession'],
5151
resources=['*'],
5252
effect=iam.Effect.ALLOW,
5353
)
54-
]),
55-
'dynamodb_db':
56-
iam.PolicyDocument(statements=[
54+
]
55+
),
56+
'dynamodb_db': iam.PolicyDocument(
57+
statements=[
5758
iam.PolicyStatement(
5859
actions=['dynamodb:PutItem', 'dynamodb:GetItem'],
5960
resources=[db.table_arn],
6061
effect=iam.Effect.ALLOW,
6162
)
62-
]),
63-
'idempotency_table':
64-
iam.PolicyDocument(statements=[
63+
]
64+
),
65+
'idempotency_table': iam.PolicyDocument(
66+
statements=[
6567
iam.PolicyStatement(
6668
actions=['dynamodb:PutItem', 'dynamodb:GetItem', 'dynamodb:UpdateItem', 'dynamodb:DeleteItem'],
6769
resources=[idempotency_table.table_arn],
6870
effect=iam.Effect.ALLOW,
6971
)
70-
]),
72+
]
73+
),
7174
},
7275
managed_policies=[
7376
iam.ManagedPolicy.from_aws_managed_policy_name(managed_policy_name=(f'service-role/{constants.LAMBDA_BASIC_EXECUTION_ROLE}'))
@@ -83,8 +86,9 @@ def _build_common_layer(self) -> PythonLayerVersion:
8386
removal_policy=RemovalPolicy.DESTROY,
8487
)
8588

86-
def _add_post_lambda_integration(self, api_name: aws_apigateway.Resource, role: iam.Role, db: dynamodb.Table, appconfig_app_name: str,
87-
idempotency_table: dynamodb.Table) -> _lambda.Function:
89+
def _add_post_lambda_integration(
90+
self, api_name: aws_apigateway.Resource, role: iam.Role, db: dynamodb.Table, appconfig_app_name: str, idempotency_table: dynamodb.Table
91+
) -> _lambda.Function:
8892
lambda_function = _lambda.Function(
8993
self,
9094
constants.CREATE_LAMBDA,

cdk/service/api_db_construct.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class ApiDbConstruct(Construct):
9-
109
def __init__(self, scope: Construct, id_: str) -> None:
1110
super().__init__(scope, id_)
1211

@@ -25,8 +24,9 @@ def _build_idempotency_table(self, id_: str) -> dynamodb.Table:
2524
time_to_live_attribute='expiration',
2625
point_in_time_recovery=True,
2726
)
28-
CfnOutput(self, id=constants.IDEMPOTENCY_TABLE_NAME_OUTPUT,
29-
value=table.table_name).override_logical_id(constants.IDEMPOTENCY_TABLE_NAME_OUTPUT)
27+
CfnOutput(self, id=constants.IDEMPOTENCY_TABLE_NAME_OUTPUT, value=table.table_name).override_logical_id(
28+
constants.IDEMPOTENCY_TABLE_NAME_OUTPUT
29+
)
3030
return table
3131

3232
def _build_db(self, id_prefix: str) -> dynamodb.Table:

cdk/service/configuration/configuration_construct.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class ConfigurationStore(Construct):
11-
1211
def __init__(self, scope: Construct, id_: str, environment: str, service_name: str, configuration_name: str) -> None:
1312
"""
1413
This construct should be deployed in a different repo and have its own pipeline so updates can be decoupled from

cdk/service/configuration/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ def validate_features(cls, value):
1313
try:
1414
validator.validate()
1515
except Exception as exc:
16-
raise ValueError(str(exc))
16+
raise ValueError(str(exc)) from exc
1717
return value

cdk/service/monitoring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020

2121
class CrudMonitoring(Construct):
22-
2322
def __init__(
2423
self,
2524
scope: Construct,
@@ -40,7 +39,7 @@ def _build_topic(self) -> sns.Topic:
4039
self,
4140
'MonitoringKey',
4241
description='KMS Key for SNS Topic Encryption',
43-
enable_key_rotation=True # Enables automatic key rotation
42+
enable_key_rotation=True, # Enables automatic key rotation
4443
)
4544
topic = sns.Topic(self, f'{self.id_}alarms', display_name=f'{self.id_}alarms', master_key=key)
4645
# Grant CloudWatch permissions to publish to the SNS topic
@@ -50,7 +49,8 @@ def _build_topic(self) -> sns.Topic:
5049
effect=iam.Effect.ALLOW,
5150
principals=[iam.ServicePrincipal('cloudwatch.amazonaws.com')],
5251
resources=[topic.topic_arn],
53-
))
52+
)
53+
)
5454
CfnOutput(self, id=constants.MONITORING_TOPIC, value=topic.topic_name).override_logical_id(constants.MONITORING_TOPIC)
5555
return topic
5656

0 commit comments

Comments
 (0)