Skip to content

Commit

Permalink
Merge pull request #244 from elsaferrara/wip/bump_black_flake8_mypy
Browse files Browse the repository at this point in the history
Bump Flake8, Black, MyPy
  • Loading branch information
liaiss authored Mar 26, 2024
2 parents 646fc2b + fe9cfed commit e86e7e9
Show file tree
Hide file tree
Showing 23 changed files with 145 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Run Tox
run: tox
env:
TOXENV: security
TOXENV: check

pre-commit:
runs-on: ubuntu-latest
Expand Down
33 changes: 11 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
repos:
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- flake8-comprehensions
- flake8-docstrings
- flake8-rst-docstrings
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-builtins
- flake8-comprehensions
- flake8-docstrings
- flake8-rst-docstrings
- repo: https://github.com/ambv/black
rev: 23.1.0
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
hooks:
- id: mypy
files: '\.py$'
exclude: '^tests/.+$'
additional_dependencies:
- types-requests
- types-python-dateutil
- types-PyYAML
- types-setuptools
- id: black
71 changes: 0 additions & 71 deletions mypy.ini

This file was deleted.

14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ test = [
"moto[sts, dynamodb]"
]

check = [
"mypy==1.8.0",
"bandit",
"pip-audit",
"types-colorama",
"types-psutil",
"types-python-dateutil",
"types-PyYAML",
"types-requests",
"types-setuptools",
]

[tool.setuptools.dynamic]
version = {file = "VERSION"}

Expand All @@ -61,5 +73,7 @@ module = [
"botocore.*",
"boto3.*",
"requests.*",
"docker.*",
"troposphere.*",
]
ignore_missing_imports = true
60 changes: 30 additions & 30 deletions src/e3/aws/troposphere/apigateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ def __init__(
resource_list: list[Resource] | None = None,
integration_uri: str | Ref | Sub | None = None,
lambda_arn: str | GetAtt | Ref | None = None,
lambda_arn_permission: str
| GetAtt
| Ref
| dict[str, str | GetAtt | Ref]
| None = None,
lambda_arn_permission: (
str | GetAtt | Ref | dict[str, str | GetAtt | Ref] | None
) = None,
) -> None:
"""Initialize a REST API resource.
Expand Down Expand Up @@ -580,9 +578,11 @@ def declare_route(self, route: Route, integration: Ref | str) -> list[AWSObject]
)
),
Action="lambda:InvokeFunction",
FunctionName=config.lambda_arn_permission
if config.lambda_arn_permission is not None
else self.lambda_arn,
FunctionName=(
config.lambda_arn_permission
if config.lambda_arn_permission is not None
else self.lambda_arn
),
Principal="apigateway.amazonaws.com",
SourceArn=Sub(
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:"
Expand Down Expand Up @@ -911,11 +911,9 @@ def _declare_method(
resource_path: str,
resource_integration_uri: str | Ref | Sub | None = None,
resource_lambda_arn: str | GetAtt | Ref | None = None,
resource_lambda_arn_permission: str
| GetAtt
| Ref
| dict[str, str | GetAtt | Ref]
| None = None,
resource_lambda_arn_permission: (
str | GetAtt | Ref | dict[str, str | GetAtt | Ref] | None
) = None,
) -> list[AWSObject]:
"""Declare a method.
Expand Down Expand Up @@ -950,20 +948,22 @@ def _declare_method(
IntegrationHttpMethod="POST",
PassthroughBehavior="NEVER",
Type="AWS_PROXY",
Uri=integration_uri
if integration_uri is not None
else Sub(
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31"
"/functions/${lambdaArn}/invocations",
dict_values={"lambdaArn": lambda_arn},
Uri=(
integration_uri
if integration_uri is not None
else Sub(
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31"
"/functions/${lambdaArn}/invocations",
dict_values={"lambdaArn": lambda_arn},
)
),
)

method_params = {
"RestApiId": self.ref,
"AuthorizationType": "COGNITO_USER_POOLS"
if method.authorizer_name
else "NONE",
"AuthorizationType": (
"COGNITO_USER_POOLS" if method.authorizer_name else "NONE"
),
"HttpMethod": f"{method.method}",
"Integration": integration,
"ResourceId": Ref(name_to_id(f"{resource_id_prefix}Resource")),
Expand Down Expand Up @@ -1053,11 +1053,9 @@ def _declare_resources(
parent_path: str | None = None,
parent_integration_uri: str | Ref | Sub | None = None,
parent_lambda_arn: str | GetAtt | Ref | None = None,
parent_lambda_arn_permission: str
| GetAtt
| Ref
| dict[str, str | GetAtt | Ref]
| None = None,
parent_lambda_arn_permission: (
str | GetAtt | Ref | dict[str, str | GetAtt | Ref] | None
) = None,
) -> list[AWSObject]:
"""Create API resources and methods recursively.
Expand Down Expand Up @@ -1094,9 +1092,11 @@ def _declare_resources(
# Declare the resource
resource = apigateway.Resource(
f"{resource_id_prefix}Resource",
ParentId=GetAtt(self.logical_id, "RootResourceId")
if parent_id_prefix is None
else GetAtt(f"{parent_id_prefix}Resource", "ResourceId"),
ParentId=(
GetAtt(self.logical_id, "RootResourceId")
if parent_id_prefix is None
else GetAtt(f"{parent_id_prefix}Resource", "ResourceId")
),
RestApiId=self.ref,
PathPart=r.path,
)
Expand Down
20 changes: 12 additions & 8 deletions src/e3/aws/troposphere/awslambda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,9 @@ def __init__(
lambda_arn: str | GetAtt | Ref,
lambda_version: str,
alias_name: str | None = None,
provisioned_concurrency_config: awslambda.ProvisionedConcurrencyConfiguration
| None = None,
provisioned_concurrency_config: (
awslambda.ProvisionedConcurrencyConfiguration | None
) = None,
routing_config: awslambda.AliasRoutingConfiguration | None = None,
):
"""Initialize an AWS lambda alias.
Expand Down Expand Up @@ -567,8 +568,9 @@ def __init__(
name: str,
description: str,
lambda_arn: str | GetAtt | Ref,
provisioned_concurrency_config: awslambda.ProvisionedConcurrencyConfiguration
| None = None,
provisioned_concurrency_config: (
awslambda.ProvisionedConcurrencyConfiguration | None
) = None,
code_sha256: str | None = None,
):
"""Initialize an AWS lambda version.
Expand Down Expand Up @@ -626,8 +628,9 @@ def __init__(
lambda_name: str | None = None,
lambda_arn: str | GetAtt | Ref | None = None,
lambda_function: Function | None = None,
provisioned_concurrency_config: awslambda.ProvisionedConcurrencyConfiguration
| None = None,
provisioned_concurrency_config: (
awslambda.ProvisionedConcurrencyConfiguration | None
) = None,
code_sha256: str | None = None,
) -> None:
"""Create lambda versions from 1 to version included.
Expand Down Expand Up @@ -718,8 +721,9 @@ def __init__(
self,
version: str,
name: str | None = None,
provisioned_concurrency_config: awslambda.ProvisionedConcurrencyConfiguration
| None = None,
provisioned_concurrency_config: (
awslambda.ProvisionedConcurrencyConfiguration | None
) = None,
routing_config: awslambda.AliasRoutingConfiguration | None = None,
) -> None:
"""Configure a blue/green alias.
Expand Down
1 change: 1 addition & 0 deletions src/e3/aws/troposphere/awslambda/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def hello_world():
route_list=[Get("/")]))
"""

from __future__ import annotations
import os

Expand Down
8 changes: 5 additions & 3 deletions src/e3/aws/troposphere/cloudfront/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ def distribution(self) -> cloudfront.Distribution:
params["Logging"] = cloudfront.Logging(
Bucket=self.logging_bucket,
Prefix=self.logging_prefix if self.logging_prefix is not None else "",
IncludeCookies=self.logging_include_cookies
if self.logging_include_cookies is not None
else False,
IncludeCookies=(
self.logging_include_cookies
if self.logging_include_cookies is not None
else False
),
)

return cloudfront.Distribution(
Expand Down
1 change: 1 addition & 0 deletions src/e3/aws/troposphere/config/config_rule.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide AWS Config configuration rules."""

from __future__ import annotations
from dataclasses import dataclass, field
from typing import TYPE_CHECKING
Expand Down
44 changes: 26 additions & 18 deletions src/e3/aws/troposphere/dynamodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,16 @@ def resources(self, stack: Stack) -> list[AWSObject]:
],
Projection=dynamodb.Projection(**projection_param),
ProvisionedThroughput=dynamodb.ProvisionedThroughput(
ReadCapacityUnits=gsi.read_capacity_units
if gsi.read_capacity_units is not None
else 10,
WriteCapacityUnits=gsi.write_capacity_units
if self.write_capacity_units is not None
else 10,
ReadCapacityUnits=(
gsi.read_capacity_units
if gsi.read_capacity_units is not None
else 10
),
WriteCapacityUnits=(
gsi.write_capacity_units
if self.write_capacity_units is not None
else 10
),
),
)
)
Expand All @@ -198,20 +202,22 @@ def resources(self, stack: Stack) -> list[AWSObject]:
params["Tags"] = Tags(**self.tags)

if self.point_in_time_recovery_enabled:
params[
"PointInTimeRecoverySpecification"
] = PointInTimeRecoverySpecification(PointInTimeRecoveryEnabled=True)
params["PointInTimeRecoverySpecification"] = (
PointInTimeRecoverySpecification(PointInTimeRecoveryEnabled=True)
)

if self.billing_mode is not None:
params["BillingMode"] = self.billing_mode

params["ProvisionedThroughput"] = dynamodb.ProvisionedThroughput(
ReadCapacityUnits=self.read_capacity_units
if self.read_capacity_units is not None
else 10,
WriteCapacityUnits=self.write_capacity_units
if self.write_capacity_units is not None
else 10,
ReadCapacityUnits=(
self.read_capacity_units if self.read_capacity_units is not None else 10
),
WriteCapacityUnits=(
self.write_capacity_units
if self.write_capacity_units is not None
else 10
),
)

if self.time_to_live_enabled is not None:
Expand All @@ -225,9 +231,11 @@ def resources(self, stack: Stack) -> list[AWSObject]:

if self.stream_enabled:
params["StreamSpecification"] = dynamodb.StreamSpecification(
StreamViewType=self.stream_view_type
if self.stream_view_type is not None
else "NEW_IMAGE"
StreamViewType=(
self.stream_view_type
if self.stream_view_type is not None
else "NEW_IMAGE"
)
)

return [dynamodb.Table(name_to_id(self.name), **params)]
Loading

0 comments on commit e86e7e9

Please sign in to comment.