Skip to content

Commit

Permalink
add mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
jtherrmann committed Jan 13, 2025
1 parent cb8680e commit 8b65a40
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ jobs:
call-ruff-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected]

call-mypy-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected]

cfn-lint:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions
runs-on: ubuntu-latest

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
3 changes: 0 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ dependencies:
- python=3.12
- pip
- pip:
- pytest
- boto3
- pytest-mock
- -r requirements-all.txt
2 changes: 1 addition & 1 deletion ingest/src/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions invoke/src/invoke.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion metadata-construction/src/metadata_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
4 changes: 2 additions & 2 deletions metadata-to-cmr/src/daemon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import os
from logging import getLogger
from os import getenv

import boto3
from botocore.client import Config
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions notify/src/notify.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
-r requirements-invoke.txt
-r requirements-notify.txt
-r requirements-verify.txt
boto3
pytest
pytest-mock
ruff
mypy
4 changes: 2 additions & 2 deletions tests/test_metadata_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 8b65a40

Please sign in to comment.