Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable deferred annotations everywhere and fix annotations and comments #206

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/src/pixl_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""PIXL command line interface"""
from __future__ import annotations

from pixl_cli.main import cli

Expand Down
3 changes: 2 additions & 1 deletion cli/src/pixl_cli/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Reading and writing files from PIXL CLI."""
from __future__ import annotations

import json
from datetime import datetime
from pathlib import Path
Expand Down
2 changes: 2 additions & 0 deletions cli/src/pixl_cli/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import logging

import coloredlogs
Expand Down
2 changes: 2 additions & 0 deletions cli/src/pixl_cli/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

from pathlib import Path


Expand Down
1 change: 1 addition & 0 deletions cli/src/pixl_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""PIXL command line interface functionality"""
from __future__ import annotations

import json
import os
Expand Down
3 changes: 2 additions & 1 deletion cli/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""CLI testing fixtures."""
from __future__ import annotations

import pathlib

import pytest
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/test_copy_omop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test copying of OMOP ES data for later export."""
from __future__ import annotations

import datetime

import pytest
Expand Down
6 changes: 5 additions & 1 deletion cli/tests/test_messages_from_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unit tests for reading cohorts from parquet files."""
from __future__ import annotations

import datetime
from pathlib import Path
from typing import TYPE_CHECKING

from core.patient_queue.message import Message
from pixl_cli._io import copy_parquet_return_logfile_fields, messages_from_parquet

if TYPE_CHECKING:
from pathlib import Path


def test_messages_from_parquet(resources: Path) -> None:
"""
Expand Down
1 change: 1 addition & 0 deletions cli/tests/test_queue_start_and_stop_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Patient queue tests"""
from __future__ import annotations

from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions hasher/src/hasher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
The Azure infrastructure (Key Vault, ServicePrincipal & permissions) must be persistent
and instructions are provided for creating these with the az CLI tool.
"""
from __future__ import annotations

import importlib.metadata

Expand Down
1 change: 1 addition & 0 deletions hasher/src/hasher/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Sets up endpoints for the hasher-api"""
from __future__ import annotations

from fastapi import APIRouter
from starlette.responses import Response
Expand Down
1 change: 1 addition & 0 deletions hasher/src/hasher/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- generate_salt: generate a random text string in hexadecimal to be used as a salt

"""
from __future__ import annotations

import logging
import os
Expand Down
1 change: 1 addition & 0 deletions hasher/src/hasher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Defines the FastAPI app for the hasher"""
from __future__ import annotations

import logging

Expand Down
1 change: 1 addition & 0 deletions hasher/src/hasher/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- "AZURE_KEY_VAULT_NAME"
- "AZURE_KEY_VAULT_SECRET_NAME"
"""
from __future__ import annotations

import pprint
import tempfile
Expand Down
1 change: 1 addition & 0 deletions hasher/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import os

Expand Down
2 changes: 2 additions & 0 deletions hasher/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import pytest
from fastapi.testclient import TestClient
from hasher.main import app
Expand Down
2 changes: 2 additions & 0 deletions hasher/tests/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import pytest
from hasher.hashing import generate_hash, generate_salt
from hypothesis import HealthCheck, example, given, settings
Expand Down
15 changes: 7 additions & 8 deletions orthanc/orthanc-anon/plugin/pixl.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""

Applies anonymisation scheme to datasets

This module:
-Modifies a DICOM instance received by Orthanc and applies anonymisation
-Upload the resource to a dicom-web server

# Copyright (c) 2022 University College London Hospitals NHS Foundation Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Applies anonymisation scheme to datasets

This module:
-Modifies a DICOM instance received by Orthanc and applies anonymisation
-Upload the resource to a dicom-web server
"""
from __future__ import annotations

import json
import logging
Expand Down
18 changes: 9 additions & 9 deletions orthanc/orthanc-raw/plugin/pixl.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
"""

Facilitates routing of stable studies from orthanc-raw to orthanc-anon

This module provides:
-OnChange: route stable studies and if auto-routing enabled
-ShouldAutoRoute: checks whether auto-routing is enabled
-OnHeartBeat: extends the REST API

# Copyright (c) 2022 University College London Hospitals NHS Foundation Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,6 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Facilitates routing of stable studies from orthanc-raw to orthanc-anon

This module provides:
-OnChange: route stable studies and if auto-routing enabled
-ShouldAutoRoute: checks whether auto-routing is enabled
-OnHeartBeat: extends the REST API
"""
from __future__ import annotations

import os

import orthanc
Expand Down
1 change: 1 addition & 0 deletions pixl_core/src/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
to interact with RabbitMQ and ensure suitable rate limiting of requests to the upstream
services.
"""
from __future__ import annotations
2 changes: 2 additions & 0 deletions pixl_core/src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
PIXL core models
This module defines the data models used by the PIXL core service
"""
from __future__ import annotations

from dataclasses import dataclass

from pydantic import BaseModel
Expand Down
8 changes: 6 additions & 2 deletions pixl_core/src/core/omop.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Processing of OMOP parquet files."""
import datetime
from __future__ import annotations

import logging
import pathlib
import shutil
from typing import TYPE_CHECKING

import slugify

if TYPE_CHECKING:
import datetime

root_from_install = pathlib.Path(__file__).parents[3]

logger = logging.getLogger(__file__)
Expand Down
1 change: 1 addition & 0 deletions pixl_core/src/core/patient_queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""RabbitMQ consumer for Pixl"""
from __future__ import annotations

from .subscriber import PixlConsumer

Expand Down
2 changes: 2 additions & 0 deletions pixl_core/src/core/patient_queue/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import logging
import os
from typing import Any
Expand Down
8 changes: 5 additions & 3 deletions pixl_core/src/core/patient_queue/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Classes to represent messages in the patient queue."""
from __future__ import annotations

import logging
from dataclasses import dataclass
from datetime import date, datetime
from typing import Any
from typing import TYPE_CHECKING, Any

from jsonpickle import decode, encode

if TYPE_CHECKING:
from datetime import date, datetime

logger = logging.getLogger(__name__)


Expand Down
7 changes: 5 additions & 2 deletions pixl_core/src/core/patient_queue/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Producer for RabbitMQ"""
from __future__ import annotations

import logging
from time import sleep

from core.patient_queue.message import Message
from typing import TYPE_CHECKING

from ._base import PixlBlockingInterface

if TYPE_CHECKING:
from core.patient_queue.message import Message

LOGGER = logging.getLogger(__name__)


Expand Down
14 changes: 10 additions & 4 deletions pixl_core/src/core/patient_queue/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Subscriber for RabbitMQ"""
from __future__ import annotations

import asyncio
import logging
from collections.abc import Awaitable, Callable
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING, Any

import aio_pika

from core.patient_queue.message import Message, deserialise
from core.token_buffer.tokens import TokenBucket

from ._base import PixlBlockingInterface, PixlQueueInterface

if TYPE_CHECKING:
from collections.abc import Awaitable, Callable

from typing_extensions import Self

from core.token_buffer.tokens import TokenBucket

logger = logging.getLogger(__name__)


Expand All @@ -44,7 +50,7 @@ def __init__(self, queue_name: str, token_bucket: TokenBucket) -> None:
def _url(self) -> str:
return f"amqp://{self._username}:{self._password}@{self._host}:{self._port}/"

async def __aenter__(self) -> "PixlConsumer":
async def __aenter__(self) -> Self:
"""Establishes connection to queue."""
self._connection = await aio_pika.connect_robust(self._url)
self._channel = await self._connection.channel()
Expand Down
1 change: 1 addition & 0 deletions pixl_core/src/core/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Router for the API endpoints"""
from __future__ import annotations

from fastapi import APIRouter, HTTPException, status

Expand Down
2 changes: 1 addition & 1 deletion pixl_core/src/core/token_buffer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Implements the TokenBucket class"""
from __future__ import annotations

from .tokens import TokenBucket

Expand Down
3 changes: 2 additions & 1 deletion pixl_core/src/core/token_buffer/tokens.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# noqa: D100

# Copyright (c) 2022 University College London Hospitals NHS Foundation Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import token_bucket as tb


Expand Down
2 changes: 2 additions & 0 deletions pixl_core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import os

os.environ["ENV"] = "test"
2 changes: 2 additions & 0 deletions pixl_core/tests/patient_queue/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import datetime

from core.patient_queue.message import Message, deserialise
Expand Down
Loading