Skip to content

Commit 504bae7

Browse files
committed
Updates Flake8 and Mypy versions, fixes all errors. Replaces poetry instructions with uv
1 parent 7afc05a commit 504bae7

11 files changed

Lines changed: 18 additions & 19 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
- id: black
1212
language: python
1313
- repo: https://github.com/PyCQA/flake8
14-
rev: 5.0.4
14+
rev: 7.3.0
1515
hooks:
1616
- id: flake8
1717
language: python

dicomtrolley/caching.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ class QueryCache:
189189

190190
def __init__(self, cache: DICOMObjectCache):
191191
self.cache = cache
192-
self.queries: Dict[Query, Tuple[DICOMObjectReference, ...]] = {}
192+
self.queries: Dict[str, Tuple[DICOMObjectReference, ...]] = {}
193193

194194
def add_response(self, query: Query, response: Sequence[DICOMObject]):
195195
"""Cache response for this query"""
196196
self.cache.add_all(response)
197197
references = tuple(x.reference() for x in response)
198-
self.queries[query.json()] = references
198+
self.queries[query.model_dump_json()] = references
199199

200200
def get_response(self, query: Query) -> List[Study]:
201201
"""Obtain cached response for this query
@@ -206,7 +206,7 @@ def get_response(self, query: Query) -> List[Study]:
206206
If any of the results of query are not in cache or have expired
207207
"""
208208
try:
209-
references = self.queries[query.json()]
209+
references = self.queries[query.model_dump_json()]
210210
except KeyError as e:
211211
raise NodeNotFound(
212212
f"Query {query.to_short_string()} not found in cache"
@@ -221,7 +221,7 @@ def get_response(self, query: Query) -> List[Study]:
221221
return retrieved
222222
except NodeNotFound as e:
223223
# This query response is not (fully) cached anymore. Remove
224-
self.queries.pop(query.json())
224+
self.queries.pop(query.model_dump_json())
225225
raise NodeNotFound(
226226
f"One or more response to {query.to_short_string()} "
227227
f"was not in cache"

dicomtrolley/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ class Query(BaseModel):
613613
) # to which depth to return results
614614
max_study_date: Optional[datetime] = None
615615
min_study_date: Optional[datetime] = None
616-
include_fields: List[str] = Field([]) #
616+
include_fields: Optional[List[str]] = Field(default_factory=list)
617617

618618
class Config:
619619
extra = "forbid" # raise ValueError when passing an unknown keyword to init
@@ -749,5 +749,5 @@ def find_study_by_id(
749749
)
750750

751751

752-
Instance.update_forward_refs() # enables pydantic validation
753-
Series.update_forward_refs()
752+
Instance.model_rebuild() # enables pydantic validation
753+
Series.model_rebuild()

dicomtrolley/fields.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class StudyLevel:
140140
"InstitutionalDepartmentName",
141141
"NumberOfStudyRelatedSeries",
142142
"NumberOfStudyRelatedInstances",
143-
"InstanceAvailability",
144143
"SOPClassesInStudy",
145144
"CurrentPatientLocation",
146145
"SourceApplicationEntityTitle",

docs/contributing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Report bugs at [https://github.com/sjoerdk/dicomtrolley/issues]()
99
Fork this repo, create a feature branch
1010

1111
### Set up environment
12-
dicomtrolley uses [poetry](https://python-poetry.org/docs/) for dependency and package management
12+
dicomtrolley uses [uv](https://docs.astral.sh/uv) for dependency and package management
1313

14-
* Install poetry (see [poetry docs](https://python-poetry.org/docs/#installation))
14+
* Install uv (see [uv docs](https://docs.astral.sh/uv/getting-started/installation/))
1515

16-
* Create a virtual env. Go to the folder where cloned dicomtrolley and use
16+
* Create a virtual env. Go to the folder where you cloned dicomtrolley and use
1717
```
18-
poetry install
18+
uv sync
1919
```
2020

2121
* Install [pre-commit](https://pre-commit.com) hooks.

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ ignore =
6868
W503
6969
# N815 allow mixedCase. Matching case of MINT API url parameters is clearer then renaming
7070
N815
71+
exclude:
7172
# I want to keep very long lines in long xml templates.
7273
# NOTE: this exlude is also set in pre-commit-config.yaml as pre-commit seems to ignore this here
7374
dicomtrolley/xml_templates.py

tests/mock_responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def create_rad69_response(bytes_parts, soap_header=None):
393393
multi_part_soap_response = MultipartEncoder(
394394
fields=[("part1", soap_header)]
395395
+ [
396-
(f"part{idx+2}", ("filename", bytes_part, "application/dicom"))
396+
(f"part{idx + 2}", ("filename", bytes_part, "application/dicom"))
397397
for idx, bytes_part in enumerate(bytes_parts)
398398
],
399399
)

tests/test_dicom_qr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_find_study_with_basic_query():
160160
qr.parse_c_find_response = Mock()
161161

162162
qr.find_studies(query=Query(PatientID="test"))
163-
assert type(called[0]) == DICOMQuery
163+
assert isinstance(called[0], DICOMQuery)
164164
assert called[0].PatientID == "test"
165165

166166

tests/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from unittest.mock import Mock
33

44
import pytest
5-
6-
from dicomtrolley.storage import StorageDir
75
from examples.go_shopping import go_shopping
86
from examples.go_shopping_rad69 import go_shopping_rad69
97
from examples.search_for_studies_dicom_qr import search_for_studies_dicom_qr
108
from examples.search_for_studies_mint import search_for_studies_mint
119
from examples.use_wado_only import use_wado_only
10+
11+
from dicomtrolley.storage import StorageDir
1212
from tests.conftest import set_mock_response
1313
from tests.factories import create_c_find_image_response
1414
from tests.mock_responses import LOGIN_SUCCESS, MockUrls, RAD69_RESPONSE_ANY

tests/test_trolley.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from dicomtrolley.trolley import (
1010
Trolley,
1111
)
12-
1312
from tests.conftest import create_mint_study
1413
from tests.factories import (
1514
StudyReferenceFactory,

0 commit comments

Comments
 (0)