Skip to content

Commit

Permalink
update ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
jtherrmann committed Dec 17, 2024
1 parent 56cbb05 commit 6c66d8f
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ dmypy.json

# Pyre type checker
.pyre/

# vim
*.swp
1 change: 1 addition & 0 deletions apps/api/src/hyp3_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask


app = Flask(__name__, template_folder='ui/swagger/', static_folder='ui/swagger/', static_url_path='/ui/')
CMR_URL = 'https://cmr.earthdata.nasa.gov/search/granules.json'

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/hyp3_api/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from hyp3_api import app


if __name__ == '__main__':
app.run(port=8080)
1 change: 1 addition & 0 deletions apps/api/src/hyp3_api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from hyp3_api import app, auth, handlers
from hyp3_api.openapi import get_spec_yaml


api_spec_file = Path(__file__).parent / 'api-spec' / 'openapi-spec.yml'
api_spec_dict = get_spec_yaml(api_spec_file)
api_spec = OpenAPI.from_dict(api_spec_dict)
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/hyp3_api/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from hyp3_api import CMR_URL
from hyp3_api.util import get_granules


DEM_COVERAGE = None


Expand Down
1 change: 1 addition & 0 deletions apps/get-files/src/get_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import boto3


S3_CLIENT = boto3.client('s3')


Expand Down
2 changes: 1 addition & 1 deletion apps/render_cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def render_templates(job_types: dict, compute_envs: dict, security_environment:
keep_trailing_newline=True,
)

for template_file in Path('.').glob('**/*.j2'):
for template_file in Path().glob('**/*.j2'):
template = env.get_template(str(template_file))

output = template.render(
Expand Down
1 change: 1 addition & 0 deletions apps/scale-cluster/src/scale_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import boto3
import dateutil.relativedelta


BATCH = boto3.client('batch')
COST_EXPLORER = boto3.client('ce')

Expand Down
3 changes: 2 additions & 1 deletion apps/start-execution-manager/src/start_execution_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import os

import boto3
from lambda_logging import log_exceptions, logger

import dynamo
from lambda_logging import log_exceptions, logger


LAMBDA_CLIENT = boto3.client('lambda')

Expand Down
2 changes: 1 addition & 1 deletion apps/start-execution-worker/src/start_execution_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import Any

import boto3

from lambda_logging import log_exceptions, logger


STEP_FUNCTION = boto3.client('stepfunctions')

batch_params_file = Path(__file__).parent / 'batch_params_by_job_type.json'
Expand Down
1 change: 1 addition & 0 deletions apps/upload-log/src/upload_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import boto3
from botocore.config import Config


config = Config(retries={'max_attempts': 2, 'mode': 'standard'})
CLOUDWATCH = boto3.client('logs', config=config)
S3 = boto3.client('s3')
Expand Down
5 changes: 3 additions & 2 deletions lib/dynamo/dynamo/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from decimal import Decimal
from os import environ
from pathlib import Path
from typing import List, Optional
from typing import Optional
from uuid import uuid4

from boto3.dynamodb.conditions import Attr, Key
Expand All @@ -18,6 +18,7 @@
from dynamo.user import APPLICATION_APPROVED, APPLICATION_NOT_STARTED, APPLICATION_PENDING, APPLICATION_REJECTED
from dynamo.util import DYNAMODB_RESOURCE, convert_floats_to_decimals, current_utc_time, get_request_time_expression


costs_file = Path(__file__).parent / 'costs.json'
COSTS = convert_floats_to_decimals(json.loads(costs_file.read_text()))

Expand All @@ -29,7 +30,7 @@
DEFAULT_PARAMS_BY_JOB_TYPE = {}


def put_jobs(user_id: str, jobs: List[dict], dry_run=False) -> List[dict]:
def put_jobs(user_id: str, jobs: list[dict], dry_run=False) -> list[dict]:
table = DYNAMODB_RESOURCE.Table(environ['JOBS_TABLE_NAME'])
request_time = current_utc_time()

Expand Down
1 change: 1 addition & 0 deletions lib/dynamo/dynamo/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from dynamo.util import DYNAMODB_RESOURCE


APPLICATION_NOT_STARTED = 'NOT_STARTED'
APPLICATION_PENDING = 'PENDING'
APPLICATION_APPROVED = 'APPROVED'
Expand Down
1 change: 1 addition & 0 deletions lib/dynamo/dynamo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from boto3.dynamodb.conditions import Key
from dateutil.parser import parse


DYNAMODB_RESOURCE = boto3.resource('dynamodb')


Expand Down
1 change: 1 addition & 0 deletions lib/dynamo/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from setuptools import find_packages, setup


setup(
name='dynamo',
license='BSD',
Expand Down
1 change: 1 addition & 0 deletions lib/lambda_logging/lambda_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from functools import wraps


logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.INFO)
Expand Down
1 change: 1 addition & 0 deletions lib/lambda_logging/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from setuptools import find_packages, setup


setup(
name='lambda_logging',
license='BSD',
Expand Down
40 changes: 40 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[tool.ruff]
line-length = 120
src = [
"apps",
"apps/api/src",
"apps/check-processing-time/src",
"apps/get-files/src",
"apps/handle-batch-event/src",
"apps/set-batch-overrides/src",
"apps/scale-cluster/src",
"apps/start-execution-manager/src",
"apps/start-execution-worker/src",
"apps/disable-private-dns/src",
"apps/update-db/src",
"apps/upload-log/src",
"lib/dynamo",
"tests",
]

[tool.ruff.format]
indent-style = "space"
quote-style = "single"

[tool.ruff.lint]
extend-select = [
"I", # isort: https://docs.astral.sh/ruff/rules/#isort-i
"UP", # pyupgrade: https://docs.astral.sh/ruff/rules/#pyupgrade-up

# TODO: uncomment the following extensions and address their warnings:
#"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
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
case-sensitive = true
lines-after-imports = 2
4 changes: 0 additions & 4 deletions ruff.toml

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TableProperties:
def get_table_properties_from_template(resource_name):
yaml.SafeLoader.add_multi_constructor('!', lambda loader, suffix, node: None)
template_file = path.join(path.dirname(__file__), '../apps/main-cf.yml')
with open(template_file, 'r') as f:
with open(template_file) as f:
template = yaml.safe_load(f)
table_properties = template['Resources'][resource_name]['Properties']
return table_properties
Expand Down
1 change: 1 addition & 0 deletions tests/test_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from hyp3_api import CMR_URL, app, auth
from hyp3_api.util import get_granules


AUTH_COOKIE = 'asf-urs'
COSTS_URI = '/costs'
JOBS_URI = '/jobs'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api/test_api_spec.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from http import HTTPStatus

from hyp3_api import auth
from test_api.conftest import AUTH_COOKIE, JOBS_URI, USER_URI, login

from hyp3_api import auth

ENDPOINTS = {
JOBS_URI: {'GET', 'HEAD', 'OPTIONS', 'POST'},
Expand Down
3 changes: 1 addition & 2 deletions tests/test_api/test_get_user.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from http import HTTPStatus

from test_api.conftest import USER_URI, login, make_db_record

from dynamo.user import APPLICATION_APPROVED, APPLICATION_NOT_STARTED, APPLICATION_REJECTED
from dynamo.util import current_utc_time
from test_api.conftest import USER_URI, login, make_db_record


def test_get_new_user(client, tables, monkeypatch):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_api/test_patch_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from decimal import Decimal
from http import HTTPStatus

from test_api.conftest import DEFAULT_ACCESS_TOKEN, USER_URI, login

from dynamo.user import APPLICATION_APPROVED, APPLICATION_PENDING, APPLICATION_REJECTED
from test_api.conftest import DEFAULT_ACCESS_TOKEN, USER_URI, login


def test_patch_new_user(client, tables):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_api/test_submit_job.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from decimal import Decimal
from http import HTTPStatus

from test_api.conftest import login, make_job, setup_requests_mock, submit_batch

from dynamo.user import APPLICATION_PENDING
from dynamo.util import current_utc_time
from test_api.conftest import login, make_job, setup_requests_mock, submit_batch


def test_submit_one_job(client, approved_user):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import responses
from pytest import raises
from shapely.geometry import Polygon
from test_api.conftest import setup_requests_mock_with_given_polygons

from hyp3_api import CMR_URL, validation
from test_api.conftest import setup_requests_mock_with_given_polygons


def rectangle(north, south, east, west):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dynamo/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from decimal import Decimal

import pytest
from conftest import list_have_same_elements

import dynamo
from conftest import list_have_same_elements
from dynamo.exceptions import (
InsufficientCreditsError,
InvalidApplicationStatusError,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_lambda_logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest

import lambda_logging
import pytest


def test_log_exceptions():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_render_cf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import render_cf
import yaml

import render_cf


def test_parse_map_statement():
assert render_cf.parse_map_statement('for item in items') == ('item', 'items')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_set_batch_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from set_batch_overrides import (
AUTORIFT_LANDSAT_MEMORY,
AUTORIFT_S2_MEMORY,
INSAR_ISCE_BURST_MEMORY_128G,
INSAR_ISCE_BURST_MEMORY_8G,
INSAR_ISCE_BURST_MEMORY_16G,
INSAR_ISCE_BURST_MEMORY_32G,
INSAR_ISCE_BURST_MEMORY_64G,
INSAR_ISCE_BURST_MEMORY_8G,
INSAR_ISCE_BURST_MEMORY_128G,
RTC_GAMMA_10M_MEMORY,
WATER_MAP_10M_MEMORY,
lambda_handler,
Expand Down

0 comments on commit 6c66d8f

Please sign in to comment.