From f76d9e7b0f8180be1e465f5b424101a190aa6a21 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Thu, 29 Feb 2024 14:16:33 -0900 Subject: [PATCH 1/5] ruff and cf-lint static analysis --- .github/workflows/static-anaysis.yml | 17 +++++++++++++++++ environment.yml | 6 ++++++ requirements-all.txt | 3 +++ ruff.toml | 22 ++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 .github/workflows/static-anaysis.yml create mode 100644 environment.yml create mode 100644 requirements-all.txt create mode 100644 ruff.toml diff --git a/.github/workflows/static-anaysis.yml b/.github/workflows/static-anaysis.yml new file mode 100644 index 00000000..dc4961dc --- /dev/null +++ b/.github/workflows/static-anaysis.yml @@ -0,0 +1,17 @@ +name: Static analysis + +on: push + +jobs: + call-ruff-workflow: + uses: ASFHyP3/actions/.github/workflows/reusable-ruff.yml@v0.11.0 + + cfn-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.12 + - run: make install + - run: make cfn-lint diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000..e65fdd9e --- /dev/null +++ b/environment.yml @@ -0,0 +1,6 @@ +name: its-live-monitoring +dependencies: + - python=3.12 + - pip + - pip: + - -r requirements-all.txt diff --git a/requirements-all.txt b/requirements-all.txt new file mode 100644 index 00000000..8cf9137e --- /dev/null +++ b/requirements-all.txt @@ -0,0 +1,3 @@ +cfn-lint +ruff +pytest diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..257c6dd5 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,22 @@ +line-length = 120 +src = ["landsat/src", "tests"] + +[format] +indent-style = "space" +quote-style = "single" + +[lint] +extend-select = [ + "I", # isort: https://docs.astral.sh/ruff/rules/#isort-i + "UP", # pyupgrade: https://docs.astral.sh/ruff/rules/#pyupgrade-up + "D", # pydocstyle: https://docs.astral.sh/ruff/rules/#pydocstyle-d + "ANN", # annotations: https://docs.astral.sh/ruff/rules/#flake8-annotations-ann + "PTH", # use-pathlib-pth: https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth +] + +[lint.pydocstyle] +convention = "google" + +[lint.isort] +case-sensitive = true +lines-after-imports = 2 From 84d4397b3fb82b16757d79be989486afcfa121c6 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Thu, 29 Feb 2024 14:17:12 -0900 Subject: [PATCH 2/5] setup dependabot --- .github/dependabot.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..383b1536 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + labels: + - "bumpless" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + labels: + - "bumpless" From 8779b80e8159ef1b858131ed036f51772c55796e Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Thu, 29 Feb 2024 14:17:50 -0900 Subject: [PATCH 3/5] setup makefile --- Makefile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..e2ca8116 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +export PYTHONPATH = ${PWD}/landsat/src + +install: + python -m pip install --upgrade pip && \ + python -m pip install -r requirements-all.txt + +install-lambda-deps: + python -m pip install --upgrade pip && \ + python -m pip install -r requirements-landsat.txt -t landsat/src/ + +test_file ?= 'tests/' +test: + pytest $(test_file) + +static: ruff-check cfn-lint + +ruff-check: + ruff check + +ruff-format: + ruff format + +ruff: ruff-check ruff-format + +cfn-lint: + cfn-lint --template `find . -name cloudformation.yml` --info --ignore-checks W3002 From c82c8a06b68874105d7998a606fef10776015ecb Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Thu, 29 Feb 2024 14:25:23 -0900 Subject: [PATCH 4/5] fix ruff's complaints --- landsat/src/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/landsat/src/main.py b/landsat/src/main.py index 737021fb..53aa5d35 100644 --- a/landsat/src/main.py +++ b/landsat/src/main.py @@ -1,11 +1,21 @@ +"""Lambda function to trigger low-latency Landsat processing from newly acquired scenes.""" import json -def process_scene(scene): +def process_scene(scene: str) -> None: + """Process a Landsat scene.""" print(scene) -def lambda_handler(event, context): +def lambda_handler(event: dict, context: object) -> None: + """Landsat processing lambda function. + + Accepts an event with SQS records for newly ingested Landsat scenes and processes each scene. + + Args: + event: The event dictionary that contains the parameters sent when this function is invoked. + context: The context in which is function is called. + """ for record in event['Records']: body = json.loads(record['body']) message = json.loads(body['Message']) From 142f5f86489054c1b58d94f9533588d891663786 Mon Sep 17 00:00:00 2001 From: Joseph H Kennedy Date: Thu, 29 Feb 2024 14:26:42 -0900 Subject: [PATCH 5/5] whitespace --- landsat/src/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/landsat/src/main.py b/landsat/src/main.py index 53aa5d35..ba48a38c 100644 --- a/landsat/src/main.py +++ b/landsat/src/main.py @@ -1,4 +1,5 @@ """Lambda function to trigger low-latency Landsat processing from newly acquired scenes.""" + import json