Skip to content

Commit

Permalink
chore: update deps and move to ruff (#29)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Ran Isenberg <[email protected]>
  • Loading branch information
ran-isenberg and Ran Isenberg authored Nov 11, 2023
1 parent 57883a1 commit 21409ab
Show file tree
Hide file tree
Showing 17 changed files with 770 additions and 784 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/serverless-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ jobs:
- name: pre commit
run: |
make pre-commit
- name: Lint with flake8 and mypy
- name: Lint with mypy
run: |
make lint
- name: file format
run: |
yapf -d -vv --style=./.style --exclude=.venv --exclude=.build --exclude=cdk.out --exclude=.git -r .
make format
- name: Complexity scan
run: |
make complex
Expand Down
8 changes: 0 additions & 8 deletions .isort.cfg

This file was deleted.

10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.5.0
hooks:
- id: trailing-whitespace
name: Ensure that code don't have trailing whitespace
Expand All @@ -24,3 +24,11 @@ repos:
name: Tests should begin with test_
args: ["--django"]
exclude: "^(?!helpers/)"
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.5
hooks:
# Run the Ruff linter.
- id: ruff
# Run the Ruff formatter.
- id: ruff-format
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ dev:
pre-commit install
poetry shell

format:
poetry run ruff check . --fix

format-fix:
poetry run ruff format .


lint:
@echo "Running flake8"
flake8 service/* cdk/* tests/* --exclude patterns='build,cdk.json,cdk.context.json,.yaml'
@echo "Running mypy"
make mypy-lint

Expand All @@ -20,8 +25,6 @@ complex:
@echo "Running xenon"
xenon --max-absolute B --max-modules A --max-average A -e 'tests/*,.venv/*,cdk.out/*' .

sort:
isort ${PWD}

pre-commit:
pre-commit run -a --show-diff-on-failure
Expand All @@ -47,10 +50,8 @@ integration:
e2e:
pytest tests/e2e --cov-config=.coveragerc --cov=service --cov-report xml

pr: deps yapf sort pre-commit complex lint unit deploy integration e2e
pr: deps pre-commit complex lint unit deploy integration e2e

yapf:
yapf -i -vv --style=./.style --exclude=.venv --exclude=.build --exclude=cdk.out --exclude=.git -r .

pipeline-tests:
pytest tests/unit tests/integration --cov-config=.coveragerc --cov=service --cov-report xml
Expand All @@ -67,3 +68,8 @@ docs:

lint-docs:
docker run -v ${PWD}:/markdown 06kellyjac/markdownlint-cli --fix "docs"


update-deps:
poetry update
pre-commit autoupdate
48 changes: 28 additions & 20 deletions cdk/my_service/consumer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from aws_cdk import Duration, RemovalPolicy
from aws_cdk import Duration, RemovalPolicy, aws_s3_notifications
from aws_cdk import aws_iam as iam
from aws_cdk import aws_lambda as _lambda
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_s3_notifications
from aws_cdk.aws_lambda_python_alpha import PythonLayerVersion
from aws_cdk.aws_logs import RetentionDays
from constructs import Construct
Expand All @@ -12,7 +11,6 @@


class TextConsumer(Construct):

def __init__(self, scope: Construct, id_: str, bucket: s3.Bucket) -> None:
super().__init__(scope, id_)
self.id_ = id_
Expand All @@ -34,23 +32,33 @@ def _create_target_lambda(self, bucket: s3.Bucket) -> _lambda.Function:
f'{self.id_}consumer',
assumed_by=iam.ServicePrincipal('lambda.amazonaws.com'),
inline_policies={
'ses':
iam.PolicyDocument(statements=[iam.PolicyStatement(
actions=['ses:SendRawEmail'],
resources=['*'],
effect=iam.Effect.ALLOW,
)]),
's3':
iam.PolicyDocument(statements=[
iam.PolicyStatement(actions=['s3:GetObject', 's3:DeleteObject', 's3:ListBucket', 's3:PutObject'],
resources=[bucket.bucket_arn, f'{bucket.bucket_arn}/*'], effect=iam.Effect.ALLOW),
]),
'polly':
iam.PolicyDocument(
statements=[
iam.PolicyStatement(actions=['polly:StartSpeechSynthesisTask', 'polly:SynthesizeSpeech', 'polly:GetSpeechSynthesisTask'],
resources=['*'], effect=iam.Effect.ALLOW),
],),
'ses': iam.PolicyDocument(
statements=[
iam.PolicyStatement(
actions=['ses:SendRawEmail'],
resources=['*'],
effect=iam.Effect.ALLOW,
)
]
),
's3': iam.PolicyDocument(
statements=[
iam.PolicyStatement(
actions=['s3:GetObject', 's3:DeleteObject', 's3:ListBucket', 's3:PutObject'],
resources=[bucket.bucket_arn, f'{bucket.bucket_arn}/*'],
effect=iam.Effect.ALLOW,
),
]
),
'polly': iam.PolicyDocument(
statements=[
iam.PolicyStatement(
actions=['polly:StartSpeechSynthesisTask', 'polly:SynthesizeSpeech', 'polly:GetSpeechSynthesisTask'],
resources=['*'],
effect=iam.Effect.ALLOW,
),
],
),
},
managed_policies=[iam.ManagedPolicy.from_aws_managed_policy_name(managed_policy_name=('service-role/AWSLambdaBasicExecutionRole'))],
)
Expand Down
1 change: 0 additions & 1 deletion cdk/my_service/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class DB(Construct):

def __init__(self, scope: Construct, id_: str) -> None:
super().__init__(scope, id_)
self.id_ = id_
Expand Down
1 change: 0 additions & 1 deletion cdk/my_service/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class InputProducer(Construct):

def __init__(self, scope: Construct, id_: str, bucket: s3.Bucket) -> None:
super().__init__(scope, id_)
self.id_ = id_
Expand Down
1 change: 0 additions & 1 deletion cdk/my_service/service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def get_stack_name() -> str:


class ServiceStack(Stack):

def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
self.id_ = id
Expand Down
Loading

0 comments on commit 21409ab

Please sign in to comment.