Skip to content

Commit

Permalink
Merge pull request #4 from ASFHyP3/ruff
Browse files Browse the repository at this point in the history
Add static analysis for Ruff and cfn-lint, keep it up to date with dependabot
  • Loading branch information
jhkennedy authored Feb 29, 2024
2 parents 6dd7ed7 + 142f5f8 commit 266f54d
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 2 deletions.
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 17 additions & 0 deletions .github/workflows/static-anaysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Static analysis

on: push

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

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
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: its-live-monitoring
dependencies:
- python=3.12
- pip
- pip:
- -r requirements-all.txt
15 changes: 13 additions & 2 deletions landsat/src/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
"""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'])
Expand Down
3 changes: 3 additions & 0 deletions requirements-all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cfn-lint
ruff
pytest
22 changes: 22 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 266f54d

Please sign in to comment.