From 2b4beba3de862f4aca75734867bfd5afadd0cde9 Mon Sep 17 00:00:00 2001 From: Manuel Luypaert Date: Tue, 9 Apr 2024 09:44:11 +0100 Subject: [PATCH] Added pipeline aws_infra python typing check --- pipeline/aws_infra/Makefile | 3 +++ pipeline/aws_infra/cdk_app.py | 10 +++++----- pipeline/aws_infra/cdk_classes/__init__.py | 0 pipeline/aws_infra/cdk_classes/cdk_infra_stack.py | 4 +++- pipeline/aws_infra/cdk_classes/pipeline_stack.py | 2 +- pipeline/aws_infra/mypy.ini | 10 ++++++++++ pipeline/aws_infra/tests/requirements.txt | 1 + pipeline/aws_infra/tests/test_cdk_infra_stack.py | 13 +++++++------ 8 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 pipeline/aws_infra/cdk_classes/__init__.py create mode 100644 pipeline/aws_infra/mypy.ini diff --git a/pipeline/aws_infra/Makefile b/pipeline/aws_infra/Makefile index 67ade1f5..cbb917d6 100644 --- a/pipeline/aws_infra/Makefile +++ b/pipeline/aws_infra/Makefile @@ -21,3 +21,6 @@ run-unit-tests: python-dependencies python-test-dependencies run-unit-tests-dev: check-venv-active python-dependencies python-test-dependencies python -m pytest + +run-python-type-check: python-dependencies python-test-dependencies + mypy --install-types --non-interactive --warn-unused-config . diff --git a/pipeline/aws_infra/cdk_app.py b/pipeline/aws_infra/cdk_app.py index cead0240..4327106b 100644 --- a/pipeline/aws_infra/cdk_app.py +++ b/pipeline/aws_infra/cdk_app.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 -import os - -import aws_cdk as cdk +from aws_cdk import ( + App, Environment +) from cdk_classes.cdk_infra_stack import CdkInfraStack -app = cdk.App() +app = App() CdkInfraStack(app, "PaviPipelineCdkStack", - env=cdk.Environment(account='100225593120', region='us-east-1')) + env=Environment(account='100225593120', region='us-east-1')) app.synth() diff --git a/pipeline/aws_infra/cdk_classes/__init__.py b/pipeline/aws_infra/cdk_classes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pipeline/aws_infra/cdk_classes/cdk_infra_stack.py b/pipeline/aws_infra/cdk_classes/cdk_infra_stack.py index 23ff3317..8c66e1af 100644 --- a/pipeline/aws_infra/cdk_classes/cdk_infra_stack.py +++ b/pipeline/aws_infra/cdk_classes/cdk_infra_stack.py @@ -4,11 +4,13 @@ from constructs import Construct +from typing import Any + from cdk_classes.pipeline_stack import PaviEcrRepository class CdkInfraStack(Stack): - def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: + def __init__(self, scope: Construct, construct_id: str, **kwargs: Any) -> None: super().__init__(scope, construct_id, **kwargs) PaviEcrRepository(self, id="PAVI-pipeline-seq-retrieval-repo", component_name='seq_retrieval') diff --git a/pipeline/aws_infra/cdk_classes/pipeline_stack.py b/pipeline/aws_infra/cdk_classes/pipeline_stack.py index 19a07114..a540d813 100644 --- a/pipeline/aws_infra/cdk_classes/pipeline_stack.py +++ b/pipeline/aws_infra/cdk_classes/pipeline_stack.py @@ -18,4 +18,4 @@ def __init__(self, scope: Stack, id: str, component_name: str) -> None: self.repository = repo def get_repo_arn(self) -> str: - return self.repository.repository_arn + return str(self.repository.repository_arn) diff --git a/pipeline/aws_infra/mypy.ini b/pipeline/aws_infra/mypy.ini new file mode 100644 index 00000000..1bf8770f --- /dev/null +++ b/pipeline/aws_infra/mypy.ini @@ -0,0 +1,10 @@ +[mypy] +disallow_any_generics = True +disallow_untyped_defs = True +disallow_incomplete_defs = True +check_untyped_defs = True +warn_unused_ignores = False +warn_return_any = True +strict_equality = True +enable_error_code = explicit-override,truthy-bool,truthy-iterable,possibly-undefined +follow_imports = skip diff --git a/pipeline/aws_infra/tests/requirements.txt b/pipeline/aws_infra/tests/requirements.txt index 269f9b06..74bd7546 100644 --- a/pipeline/aws_infra/tests/requirements.txt +++ b/pipeline/aws_infra/tests/requirements.txt @@ -1 +1,2 @@ +mypy==1.9.* pytest==8.0.* diff --git a/pipeline/aws_infra/tests/test_cdk_infra_stack.py b/pipeline/aws_infra/tests/test_cdk_infra_stack.py index 54a29a8c..d0489929 100644 --- a/pipeline/aws_infra/tests/test_cdk_infra_stack.py +++ b/pipeline/aws_infra/tests/test_cdk_infra_stack.py @@ -4,12 +4,13 @@ before getting applied to the live AWS resources. """ -import aws_cdk +from aws_cdk import App +from aws_cdk.aws_config import ResourceType import aws_cdk.assertions as assertions from cdk_classes.cdk_infra_stack import CdkInfraStack -app = aws_cdk.App() +app = App() stack = CdkInfraStack(app, "pytest-stack") template = assertions.Template.from_stack(stack) @@ -21,15 +22,15 @@ # * Move All images from the old ECR repository to the new one # (or delete the images if no longer relevant) # * Delete the old ECR repository -def test_pipeline_seq_retrieval_ecr_repo(): - template.has_resource(type=aws_cdk.aws_config.ResourceType.ECR_REPOSITORY.compliance_resource_type, props={ +def test_pipeline_seq_retrieval_ecr_repo() -> None: + template.has_resource(type=ResourceType.ECR_REPOSITORY.compliance_resource_type, props={ "Properties": { "RepositoryName": "agr_pavi/seq_retrieval" } }) -def test_pipeline_alignment_ecr_repo(): - template.has_resource(type=aws_cdk.aws_config.ResourceType.ECR_REPOSITORY.compliance_resource_type, props={ +def test_pipeline_alignment_ecr_repo() -> None: + template.has_resource(type=ResourceType.ECR_REPOSITORY.compliance_resource_type, props={ "Properties": { "RepositoryName": "agr_pavi/alignment" }