From 8b65a409286e9dc81e12c2d1c7bd0d7214e808e5 Mon Sep 17 00:00:00 2001 From: Jake Herrmann Date: Mon, 13 Jan 2025 10:53:33 -0900 Subject: [PATCH] add mypy --- .github/workflows/static_analysis.yml | 3 +++ CHANGELOG.md | 2 ++ environment.yml | 3 --- ingest/src/ingest.py | 2 +- invoke/src/invoke.py | 4 ++-- metadata-construction/src/metadata_construction.py | 2 +- metadata-to-cmr/src/daemon.py | 4 ++-- notify/src/notify.py | 4 ++-- pyproject.toml | 8 ++++++++ requirements-all.txt | 5 +++++ tests/test_metadata_construction.py | 4 ++-- 11 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 37bef528..2de1ada5 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -7,6 +7,9 @@ jobs: call-ruff-workflow: uses: ASFHyP3/actions/.github/workflows/reusable-ruff.yml@v0.13.2 + call-mypy-workflow: + uses: ASFHyP3/actions/.github/workflows/reusable-mypy.yml@v0.14.0 + cfn-lint: runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index 3460dccb..e7a05d98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/) and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [2.0.2] +### Added +- Added `mypy` to static analysis workflow. ### Changed - Replaced `flake8` with `ruff`. diff --git a/environment.yml b/environment.yml index 81b7cd7d..45882ee6 100644 --- a/environment.yml +++ b/environment.yml @@ -5,7 +5,4 @@ dependencies: - python=3.12 - pip - pip: - - pytest - - boto3 - - pytest-mock - -r requirements-all.txt diff --git a/ingest/src/ingest.py b/ingest/src/ingest.py index f0aa17ab..5bb19d0a 100755 --- a/ingest/src/ingest.py +++ b/ingest/src/ingest.py @@ -10,7 +10,7 @@ log = getLogger() log.setLevel('INFO') s3 = boto3.resource('s3') -config = json.loads(os.getenv('CONFIG')) +config = json.loads(os.environ['CONFIG']) def copy_s3_object(copy_source, dest_bucket, dest_key, transfer_config): diff --git a/invoke/src/invoke.py b/invoke/src/invoke.py index 37f9fb20..bfb72b8a 100644 --- a/invoke/src/invoke.py +++ b/invoke/src/invoke.py @@ -1,13 +1,13 @@ import json +import os from logging import getLogger -from os import getenv import boto3 log = getLogger() log.setLevel('INFO') -CONFIG = json.loads(getenv('CONFIG')) +CONFIG = json.loads(os.environ['CONFIG']) sqs = boto3.resource('sqs') sfn = boto3.client('stepfunctions') diff --git a/metadata-construction/src/metadata_construction.py b/metadata-construction/src/metadata_construction.py index a8ec0e5c..61ea6f54 100644 --- a/metadata-construction/src/metadata_construction.py +++ b/metadata-construction/src/metadata_construction.py @@ -8,7 +8,7 @@ log = getLogger() log.setLevel('INFO') -CONFIG = json.loads(os.getenv('CONFIG')) +CONFIG = json.loads(os.environ['CONFIG']) s3 = boto3.resource('s3') diff --git a/metadata-to-cmr/src/daemon.py b/metadata-to-cmr/src/daemon.py index c335cdaf..8db9db3f 100644 --- a/metadata-to-cmr/src/daemon.py +++ b/metadata-to-cmr/src/daemon.py @@ -1,6 +1,6 @@ import json +import os from logging import getLogger -from os import getenv import boto3 from botocore.client import Config @@ -11,7 +11,7 @@ log = getLogger() log.setLevel('INFO') -CONFIG = json.loads(getenv('CONFIG')) +CONFIG = json.loads(os.environ['CONFIG']) def get_sfn_client(connect_timeout): diff --git a/notify/src/notify.py b/notify/src/notify.py index 4202f115..bf9ff095 100644 --- a/notify/src/notify.py +++ b/notify/src/notify.py @@ -1,14 +1,14 @@ import json +import os from datetime import datetime from logging import getLogger -from os import getenv import boto3 log = getLogger() log.setLevel('INFO') -CONFIG = json.loads(getenv('CONFIG')) +CONFIG = json.loads(os.environ['CONFIG']) def create_response(event, error_config): diff --git a/pyproject.toml b/pyproject.toml index 9717bc2e..f2b7a092 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,3 +28,11 @@ convention = "google" [tool.ruff.lint.isort] case-sensitive = true lines-after-imports = 2 + +[tool.mypy] +python_version = "3.12" +warn_redundant_casts = true +warn_unused_ignores = true +warn_unreachable = true +strict_equality = true +check_untyped_defs = true diff --git a/requirements-all.txt b/requirements-all.txt index a132abc7..de1c38eb 100644 --- a/requirements-all.txt +++ b/requirements-all.txt @@ -5,3 +5,8 @@ -r requirements-invoke.txt -r requirements-notify.txt -r requirements-verify.txt +boto3 +pytest +pytest-mock +ruff +mypy diff --git a/tests/test_metadata_construction.py b/tests/test_metadata_construction.py index 487b4ffb..ad78ecdf 100644 --- a/tests/test_metadata_construction.py +++ b/tests/test_metadata_construction.py @@ -68,7 +68,7 @@ def test_create_granule_metadata_in_s3_g1(test_data_dir, mocker): assert metadata_construction.create_granule_metadata_in_s3(inputs, config) == metadata_s3_object - assert metadata_construction.upload_content_to_s3.mock_calls == [ + assert metadata_construction.upload_content_to_s3.mock_calls == [ # type: ignore[attr-defined] unittest.mock.call( metadata_s3_object, json.dumps(json.loads((test_data_dir / 'granule1' / 'granule.umm.json').read_text()), sort_keys=True), @@ -93,7 +93,7 @@ def test_create_granule_metadata_in_s3_g2(test_data_dir, mocker): assert metadata_construction.create_granule_metadata_in_s3(inputs, config) == metadata_s3_object - assert metadata_construction.upload_content_to_s3.mock_calls == [ + assert metadata_construction.upload_content_to_s3.mock_calls == [ # type: ignore[attr-defined] unittest.mock.call( metadata_s3_object, json.dumps(json.loads((test_data_dir / 'granule2' / 'granule.umm.json').read_text()), sort_keys=True),