Skip to content

Commit 75d79a8

Browse files
committed
Add black for code formatting. Remove some linting exclusions. Fix errors.
1 parent 6e68b0d commit 75d79a8

272 files changed

Lines changed: 7001 additions & 3895 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/quality-checks.yml

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,26 @@ env:
1212
LAMBDA_PATH: ${{ github.workspace }}/lambdas
1313

1414
jobs:
15-
lint:
16-
name: Lint specification and Python projects
15+
lint-specification:
16+
name: Lint specification
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v5
21+
22+
- uses: actions/setup-node@v5
23+
with:
24+
node-version: '23.11.0'
25+
cache: 'npm'
26+
27+
- name: Install linting dependencies
28+
run: make install-node
29+
30+
- name: Lint
31+
run: make lint
32+
33+
lint-python:
34+
name: Lint Python projects
1735
runs-on: ubuntu-latest
1836

1937
steps:
@@ -22,23 +40,22 @@ jobs:
2240
- name: Install poetry
2341
run: pip install poetry==2.1.4
2442

25-
# Base linting requires 3.8 due to APIM package dependencies. See root README for details under linting.
26-
# Consider upgrading this and poetry deps if we move away from Azure DevOps to using the Proxygen tool.
2743
- uses: actions/setup-python@v6
2844
with:
29-
python-version: 3.8
45+
python-version: 3.11
3046
cache: 'poetry'
3147

32-
- uses: actions/setup-node@v5
33-
with:
34-
node-version: '23.11.0'
35-
cache: 'npm'
36-
3748
- name: Install linting dependencies
38-
run: make install-node && poetry install --no-root
49+
run: poetry install
50+
working-directory: quality-checks
3951

4052
- name: Lint
41-
run: make lint
53+
run: poetry run lint
54+
working-directory: quality-checks
55+
56+
- name: Check formatting
57+
run: poetry run format-check
58+
working-directory: quality-checks
4259

4360
testcoverage_and_sonarcloud:
4461
name: Test Coverage and SonarCloud

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ install: install-node install-python .git/hooks/pre-commit
2222
#Run the npm linting script (specified in package.json). Used to check the syntax and formatting of files.
2323
lint:
2424
npm run lint
25-
find . -name '*.py' -not -path '**/.venv/*' -not -path '**/.terraform/*'| xargs poetry run flake8
2625

2726
#Removes build/ + dist/ directories
2827
clean:

backend/src/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

backend/src/authorisation/authoriser.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Authoriser class"""
2+
23
import json
34

45
from authorisation.api_operation_code import ApiOperationCode
@@ -8,13 +9,17 @@
89

910
class Authoriser:
1011
"""Authoriser class. Used for authorising operations on FHIR vaccinations."""
12+
1113
def __init__(self):
1214
self._cache_client = redis_client
1315

1416
@staticmethod
15-
def _expand_permissions(permissions: list[str]) -> dict[str, list[ApiOperationCode]]:
17+
def _expand_permissions(
18+
permissions: list[str],
19+
) -> dict[str, list[ApiOperationCode]]:
1620
"""Parses and expands permissions data into a dictionary mapping vaccination types to a list of permitted
17-
API operations. The raw string from Redis will be in the form VAC.PERMS e.g. COVID19.CRUDS"""
21+
API operations. The raw string from Redis will be in the form VAC.PERMS e.g. COVID19.CRUDS
22+
"""
1823
expanded_permissions = {}
1924

2025
for permission in permissions:
@@ -39,7 +44,7 @@ def authorise(
3944
self,
4045
supplier_system: str,
4146
requested_operation: ApiOperationCode,
42-
vaccination_types: set[str]
47+
vaccination_types: set[str],
4348
) -> bool:
4449
"""Checks that the supplier system is permitted to carry out the requested operation on the given vaccination
4550
type(s)"""
@@ -58,7 +63,7 @@ def filter_permitted_vacc_types(
5863
self,
5964
supplier_system: str,
6065
requested_operation: ApiOperationCode,
61-
vaccination_types: set[str]
66+
vaccination_types: set[str],
6267
) -> set[str]:
6368
"""Returns the set of vaccine types that a given supplier can interact with for a given operation type.
6469
This is a more permissive form of authorisation e.g. used in search as it will filter out any requested vacc

backend/src/clients.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Initialise s3, kinesis, lambda and redis clients"""
22

3-
from boto3 import client as boto3_client
4-
import os
53
import logging
4+
import os
5+
66
import redis
7+
from boto3 import client as boto3_client
78

89
REGION_NAME = os.getenv("AWS_REGION", "eu-west-2")
910

backend/src/controller/aws_apig_event_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utility module for interacting with the AWS API Gateway event provided to controllers"""
2+
23
from typing import Optional
34

45
from aws_lambda_typing.events import APIGatewayProxyEventV1
@@ -9,11 +10,7 @@
910

1011

1112
def get_path_parameter(event: APIGatewayProxyEventV1, param_name: str) -> str:
12-
return dict_utils.get_field(
13-
event["pathParameters"],
14-
param_name,
15-
default=""
16-
)
13+
return dict_utils.get_field(event["pathParameters"], param_name, default="")
1714

1815

1916
def get_supplier_system_header(event: APIGatewayProxyEventV1) -> str:

backend/src/controller/aws_apig_response_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
"""Utility module providing helper functions for dealing with response formats for AWS API Gateway"""
2+
23
import json
34
from typing import Optional
45

56

6-
def create_response(
7-
status_code: int,
8-
body: Optional[dict | str] = None,
9-
headers: Optional[dict] = None
10-
):
7+
def create_response(status_code: int, body: Optional[dict | str] = None, headers: Optional[dict] = None):
118
"""Creates response body as per Lambda -> API Gateway proxy integration"""
129
if body is not None:
1310
if isinstance(body, dict):
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""FHIR Controller constants"""
22

3-
43
SUPPLIER_SYSTEM_HEADER_NAME = "SupplierSystem"
54
E_TAG_HEADER_NAME = "E-Tag"

backend/src/controller/fhir_api_exception_handler.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
"""Module for the global FHIR API exception handler"""
2+
23
import functools
34
import uuid
45
from typing import Callable, Type
56

67
from clients import logger
78
from constants import GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE
89
from controller.aws_apig_response_utils import create_response
9-
from models.errors import UnauthorizedVaxError, UnauthorizedError, ResourceNotFoundError, create_operation_outcome, \
10-
Severity, Code
11-
10+
from models.errors import (
11+
UnauthorizedVaxError,
12+
UnauthorizedError,
13+
ResourceNotFoundError,
14+
create_operation_outcome,
15+
Severity,
16+
Code,
17+
)
1218

1319
_CUSTOM_EXCEPTION_TO_STATUS_MAP: dict[Type[Exception], int] = {
1420
UnauthorizedError: 403,
1521
UnauthorizedVaxError: 403,
16-
ResourceNotFoundError: 404
22+
ResourceNotFoundError: 404,
1723
}
1824

1925

@@ -39,4 +45,3 @@ def wrapper(*args, **kwargs):
3945
return create_response(500, server_error)
4046

4147
return wrapper
42-

backend/src/controller/fhir_batch_controller.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Function to send the request directly to lambda (or return appropriate diagnostics if this is not possible)"""
22

3-
from service.fhir_batch_service import ImmunizationBatchService
43
from repository.fhir_batch_repository import ImmunizationBatchRepository
4+
from service.fhir_batch_service import ImmunizationBatchService
55

66

77
def make_batch_controller():
@@ -33,5 +33,9 @@ def send_request_to_dynamo(self, message_body: dict, table: any, is_present: boo
3333
"DELETE": self.fhir_service.delete_immunization,
3434
}
3535
return function_map[operation_requested](
36-
immunization=fhir_json, supplier_system=supplier, vax_type=vax_type, table=table, is_present=is_present
36+
immunization=fhir_json,
37+
supplier_system=supplier,
38+
vax_type=vax_type,
39+
table=table,
40+
is_present=is_present,
3741
)

0 commit comments

Comments
 (0)