Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Switching to ruff formatting (#374)
Browse files Browse the repository at this point in the history
* adding ruff config

* adding ruff config

* line length

* reformatting for ruff

---------

Co-authored-by: srh-sloan <[email protected]>
  • Loading branch information
srh-sloan and srh-sloan authored Nov 20, 2024
1 parent 5afd0ff commit 6c83c23
Show file tree
Hide file tree
Showing 68 changed files with 441 additions and 347 deletions.
42 changes: 14 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python3
args:
- --experimental-string-processing
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [Flake8-pyproject]
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.14.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version. If bumping this, please also bump requirements-dev.in
rev: v0.6.7
hooks:
- id: reorder-python-imports
name: Reorder Python imports (src, tests)
args: ["--application-directories", "src"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: pyupgrade
args: ["--py39-plus"]
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
args: ['--disable-plugin', 'HexHighEntropyString']
exclude: .env.development
- id: detect-secrets
args: ['--disable-plugin', 'HexHighEntropyString']
exclude: .env.development
111 changes: 62 additions & 49 deletions api/routes/application/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,50 @@
from typing import Optional
from uuid import uuid4

from _helpers import get_blank_forms
from _helpers import order_applications
from flask import current_app, jsonify, request, send_file
from flask.views import MethodView
from fsd_utils import Decision, evaluate_response
from fsd_utils.config.notify_constants import NotifyConstants
from sqlalchemy.orm.exc import NoResultFound

from _helpers import get_blank_forms, order_applications
from config import Config
from config.key_report_mappings.mappings import ROUND_ID_TO_KEY_REPORT_MAPPING
from db.models.application.enums import Status
from db.queries import add_new_forms
from db.queries import create_application
from db.queries import export_json_to_csv
from db.queries import export_json_to_excel
from db.queries import get_application
from db.queries import get_feedback
from db.queries import get_fund_id
from db.queries import get_general_status_applications_report
from db.queries import get_key_report_field_headers
from db.queries import get_report_for_applications
from db.queries import search_applications
from db.queries import submit_application
from db.queries import update_form
from db.queries import upsert_feedback
from db.queries import (
add_new_forms,
create_application,
export_json_to_csv,
export_json_to_excel,
get_application,
get_feedback,
get_fund_id,
get_general_status_applications_report,
get_key_report_field_headers,
get_report_for_applications,
search_applications,
submit_application,
update_form,
upsert_feedback,
)
from db.queries.application import create_qa_base64file
from db.queries.feedback import retrieve_all_feedbacks_and_surveys
from db.queries.feedback import retrieve_end_of_application_survey_data
from db.queries.feedback import upsert_end_of_application_survey_data
from db.queries.reporting.queries import export_application_statuses_to_csv
from db.queries.reporting.queries import map_application_key_fields
from db.queries.research import retrieve_research_survey_data
from db.queries.research import upsert_research_survey_data
from db.queries.statuses import check_is_fund_round_open
from db.queries.statuses import update_statuses
from external_services import get_account
from external_services import get_fund
from external_services import get_round
from external_services import get_round_eoi_schema
from external_services.exceptions import NotificationError
from external_services.exceptions import SubmitError
from db.queries.feedback import (
retrieve_all_feedbacks_and_surveys,
retrieve_end_of_application_survey_data,
upsert_end_of_application_survey_data,
)
from db.queries.reporting.queries import (
export_application_statuses_to_csv,
map_application_key_fields,
)
from db.queries.research import (
retrieve_research_survey_data,
upsert_research_survey_data,
)
from db.queries.statuses import check_is_fund_round_open, update_statuses
from external_services import get_account, get_fund, get_round, get_round_eoi_schema
from external_services.exceptions import NotificationError, SubmitError
from external_services.models.notification import Notification
from flask import current_app
from flask import jsonify
from flask import request
from flask import send_file
from flask.views import MethodView
from fsd_utils import Decision
from fsd_utils import evaluate_response
from fsd_utils.config.notify_constants import NotifyConstants
from sqlalchemy.orm.exc import NoResultFound


class ApplicationsView(MethodView):
Expand Down Expand Up @@ -105,8 +104,8 @@ def get_key_application_data_report(self, application_id):

def get_applications_statuses_report(
self,
round_id: Optional[list] = [],
fund_id: Optional[list] = [],
round_id: Optional[list] = None,
fund_id: Optional[list] = None,
format: Optional[str] = "csv",
):
try:
Expand Down Expand Up @@ -232,7 +231,10 @@ def submit(self, application_id):
full_name.title() if full_name else None,
contents,
)
current_app.logger.info(f"Message added to the queue msg_id: [{message_id}]")
current_app.logger.info(
"Message added to the queue msg_id: [{message_id}]",
extra=dict(message_id=message_id),
)
return {
"id": application_id,
"reference": application_with_form_json["reference"],
Expand All @@ -241,19 +243,27 @@ def submit(self, application_id):
}, 201
except KeyError as e:
current_app.logger.exception(
f"Key error on processing application submissionfor application: '{application_id}'"
"Key error on processing application submissionfor application: '{application_id}'",
extra=dict(application_id=application_id),
)
return str(e), 500, {"x-error": "key error"}
except NotificationError as e:
current_app.logger.exception(
f"Notification error on sending SUBMIT notification for application {application_id}"
"Notification error on sending SUBMIT notification for application {application_id}",
extra=dict(application_id=application_id),
)
return str(e), 500, {"x-error": "notification error"}
except SubmitError as e:
current_app.logger.exception(f"Submit error on sending SUBMIT application {application_id}")
current_app.logger.exception(
"Submit error on sending SUBMIT application {application_id}",
extra=dict(application_id=application_id),
)
return str(e), 500, {"x-error": "Submit error"}
except Exception as e:
current_app.logger.exception(f"Error on sending SUBMIT notification for application {application_id}")
current_app.logger.exception(
"Error on sending SUBMIT notification for application {application_id}",
extra=dict(application_id=application_id),
)
return str(e), 500, {"x-error": "Error"}

def _send_submit_queue(self, application_id, application_with_form_json):
Expand All @@ -276,11 +286,14 @@ def _send_submit_queue(self, application_id, application_with_form_json):
message_deduplication_id=str(uuid4()), # ensures message uniqueness
extra_attributes=application_attributes,
)
current_app.logger.info(f"Message sent to SQS queue and message id is [{message_id}]")
current_app.logger.info(
"Message sent to SQS queue and message id is [{message_id}]",
extra=dict(message_id=message_id),
)
except Exception as e:
current_app.logger.error("An error occurred while sending message")
current_app.logger.error(e)
raise SubmitError(message="Sorry, cannot submit the message")
raise SubmitError(message="Sorry, cannot submit the message") from e

def post_feedback(self):
args = request.get_json()
Expand Down
10 changes: 7 additions & 3 deletions api/routes/queues/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import json
from uuid import uuid4

from config import Config
from db.queries import get_application
from flask import current_app
from flask.views import MethodView

from config import Config
from db.queries import get_application


class QueueView(MethodView):
def post_submitted_application_to_assessment(self, application_id=None):
Expand Down Expand Up @@ -36,7 +37,10 @@ def post_submitted_application_to_assessment(self, application_id=None):
message_deduplication_id=str(uuid4()), # ensures message uniqueness
extra_attributes=application_attributes,
)
current_app.logger.info(f"Message sent to SQS queue and message id is [{message_id}]")
current_app.logger.info(
"Message sent to SQS queue and message id is [{message_id}]",
extra=dict(message_id=message_id),
)
return f"Message queued, message_id is: {message_id}.", 201
except Exception as e:
current_app.logger.error("An error occurred while sending message")
Expand Down
10 changes: 5 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from os import getenv

import connexion
from api.routes.application.routes import ApplicationsView # noqa
from config import Config
from connexion import FlaskApp
from connexion.resolver import MethodResolver
from db.exceptions.application import ApplicationError
from flask import jsonify
from fsd_utils import init_sentry
from fsd_utils.healthchecks.checkers import DbChecker
from fsd_utils.healthchecks.checkers import FlaskRunningChecker
from fsd_utils.healthchecks.checkers import DbChecker, FlaskRunningChecker
from fsd_utils.healthchecks.healthcheck import Healthcheck
from fsd_utils.logging import logging
from fsd_utils.services.aws_extended_client import SQSExtendedClient

from api.routes.application.routes import ApplicationsView # noqa
from config import Config
from db.exceptions.application import ApplicationError
from openapi.utils import get_bundled_specs


Expand Down
6 changes: 3 additions & 3 deletions config/envs/default.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Flask configuration."""

import logging
import os
from distutils.util import strtobool
from os import environ
from pathlib import Path

from distutils.util import strtobool
from fsd_utils import CommonConfig
from fsd_utils import configclass
from fsd_utils import CommonConfig, configclass


@configclass
Expand Down
4 changes: 3 additions & 1 deletion config/envs/dev.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Flask configuration."""

import logging
from os import environ

from config.envs.default import DefaultConfig
from fsd_utils import configclass

from config.envs.default import DefaultConfig


@configclass
class DevConfig(DefaultConfig):
Expand Down
4 changes: 3 additions & 1 deletion config/envs/development.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Flask configuration."""

import logging

from config.envs.default import DefaultConfig
from fsd_utils import configclass

from config.envs.default import DefaultConfig


@configclass
class DevelopmentConfig(DefaultConfig):
Expand Down
4 changes: 3 additions & 1 deletion config/envs/production.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Flask configuration."""

from os import environ

from config.envs.default import DefaultConfig
from fsd_utils import configclass

from config.envs.default import DefaultConfig


@configclass
class ProductionConfig(DefaultConfig):
Expand Down
4 changes: 3 additions & 1 deletion config/envs/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Flask configuration."""

from os import environ

from config.envs.default import DefaultConfig
from fsd_utils import configclass

from config.envs.default import DefaultConfig


@configclass
class TestConfig(DefaultConfig):
Expand Down
1 change: 1 addition & 0 deletions config/envs/unit_testing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# flake8 : noqa
"""Flask Unit Testing Environment Configuration."""

from os import environ

from config.envs.default import DefaultConfig
Expand Down
4 changes: 1 addition & 3 deletions config/key_report_mappings/cof25_eoi_key_report_mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from config.key_report_mappings.model import extract_postcode
from config.key_report_mappings.model import FormMappingItem
from config.key_report_mappings.model import KeyReportMapping
from config.key_report_mappings.model import FormMappingItem, KeyReportMapping, extract_postcode

COF25_EOI_KEY_REPORT_MAPPING = KeyReportMapping(
round_id="9104d809-0fb0-4144-b514-55e81cc2b6fa",
Expand Down
4 changes: 1 addition & 3 deletions config/key_report_mappings/cof_eoi_key_report_mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from config.key_report_mappings.model import extract_postcode
from config.key_report_mappings.model import FormMappingItem
from config.key_report_mappings.model import KeyReportMapping
from config.key_report_mappings.model import FormMappingItem, KeyReportMapping, extract_postcode

COF_EOI_KEY_REPORT_MAPPING = KeyReportMapping(
round_id="6a47c649-7bac-4583-baed-9c4e7a35c8b3",
Expand Down
10 changes: 6 additions & 4 deletions config/key_report_mappings/cof_key_report_mapping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from config.key_report_mappings.model import ApplicationColumnMappingItem
from config.key_report_mappings.model import extract_postcode
from config.key_report_mappings.model import FormMappingItem
from config.key_report_mappings.model import KeyReportMapping
from config.key_report_mappings.model import (
ApplicationColumnMappingItem,
FormMappingItem,
KeyReportMapping,
extract_postcode,
)

COF_KEY_REPORT_MAPPING = KeyReportMapping(
round_id=["4efc3263-aefe-4071-b5f4-0910abec12d2", "33726b63-efce-4749-b149-20351346c76e"],
Expand Down
4 changes: 1 addition & 3 deletions config/key_report_mappings/cof_r2_key_report_mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from config.key_report_mappings.model import extract_postcode
from config.key_report_mappings.model import FormMappingItem
from config.key_report_mappings.model import KeyReportMapping
from config.key_report_mappings.model import FormMappingItem, KeyReportMapping, extract_postcode

COF_R2_KEY_REPORT_MAPPING = KeyReportMapping(
round_id="c603d114-5364-4474-a0c4-c41cbf4d3bbd",
Expand Down
10 changes: 6 additions & 4 deletions config/key_report_mappings/cof_r3w2_key_report_mapping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from config.key_report_mappings.model import ApplicationColumnMappingItem
from config.key_report_mappings.model import extract_postcode
from config.key_report_mappings.model import FormMappingItem
from config.key_report_mappings.model import KeyReportMapping
from config.key_report_mappings.model import (
ApplicationColumnMappingItem,
FormMappingItem,
KeyReportMapping,
extract_postcode,
)

COF_R3W2_KEY_REPORT_MAPPING = KeyReportMapping(
round_id="6af19a5e-9cae-4f00-9194-cf10d2d7c8a7",
Expand Down
3 changes: 1 addition & 2 deletions config/key_report_mappings/cyp_r1_key_report_mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from config.key_report_mappings.model import FormMappingItem
from config.key_report_mappings.model import KeyReportMapping
from config.key_report_mappings.model import FormMappingItem, KeyReportMapping

CYP_R1_KEY_REPORT_MAPPING = KeyReportMapping(
round_id="888aae3d-7e2c-4523-b9c1-95952b3d1644",
Expand Down
Loading

0 comments on commit 6c83c23

Please sign in to comment.