Skip to content

Commit 190f918

Browse files
authored
Update SDK to support typeguard v3.0 and above, which has a breaking change in its API, and updated notebooks (#438)
* Change to support typeguard v3.0+ which has breaking API change on check_type() Along with the SDK change in th io_context.py, any pinged version of typarguard to ~=2 must be removed. Signed-off-by: M Q <[email protected]> * Add comments on the reason for depending on pydicom and highdicom Signed-off-by: M Q <[email protected]> * Add comments in the notebooks for the use of highdicom package Signed-off-by: M Q <[email protected]> * Reran notebooks, aferwards, restored import "--upgrade" With "import --upgrade monai-deploy-app-sdk", users do not need to explicitly uninstall prior version of the App SDK when running the notebook in virtual env. For testing the notebook in dev with the editable App SDK, do NOT use --upgrade in case the local dirty version is lower somehow. Signed-off-by: M Q <[email protected]> * Udpate pytest version to get the automated test in CI to succeed Signed-off-by: M Q <[email protected]> * Bump to Python3.8 as in 3.7 pytest still fails on GitHub Signed-off-by: M Q <[email protected]> * Fix flake8 complaint: B907, manually surrounded by quotes, consider using the `!r` conversion Signed-off-by: M Q <[email protected]> * Quiet the format checking complaint Signed-off-by: M Q <[email protected]> * To quiet flake8 complint Signed-off-by: M Q <[email protected]> * Yet another black nit-picking Signed-off-by: M Q <[email protected]> * Need to use the new way, pytest instead of py.test Signed-off-by: M Q <[email protected]> * Somehow the last commit did not get the change py.test -> pytest Signed-off-by: M Q <[email protected]> * Retested all notebooks as QA step Signed-off-by: M Q <[email protected]> * Yet another way to quiet flake8 complaint Signed-off-by: M Q <[email protected]> * The file content was wiped out (local disk space issue) Signed-off-by: M Q <[email protected]> * Used the known working way to quiet flake8 complaint, str.format() Signed-off-by: M Q <[email protected]> --------- Signed-off-by: M Q <[email protected]>
1 parent fe9bb2b commit 190f918

30 files changed

+4493
-4702
lines changed

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sphinx:
1818

1919
# Optionally set the version of Python and requirements required to build your docs
2020
python:
21-
version: 3.7
21+
version: "3.8"
2222
install:
2323
- requirements: docs/requirements.txt
2424
# system_packages: true

examples/apps/mednist_classifier_monaideploy/mednist_classifier_monaideploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def compute(self, op_input: InputContext, op_output: OutputContext, context: Exe
9595

9696

9797
@md.resource(cpu=1, gpu=1, memory="1Gi")
98-
@md.env(pip_packages=["pydicom >= 2.3.0", "highdicom>=0.18.2", "typeguard~=2.12.1"])
98+
@md.env(pip_packages=["pydicom >= 2.3.0", "highdicom>=0.18.2"]) # because of the use of DICOM writer operator
9999
class App(Application):
100100
"""Application class for the MedNIST classifier."""
101101

monai/deploy/core/application.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ def add_flow(
205205
if not io_map:
206206
if len(op_output_labels) > 1:
207207
raise IOMappingError(
208-
f"The source operator has more than one output port "
208+
"The source operator has more than one output port "
209209
f"({', '.join(op_output_labels)}) so mapping should be specified explicitly!"
210210
)
211211
if len(op_input_labels) > 1:
212212
raise IOMappingError(
213213
f"The destination operator has more than one output port ({', '.join(op_input_labels)}) "
214-
f"so mapping should be specified explicitly!"
214+
"so mapping should be specified explicitly!"
215215
)
216216
io_map = {"": {""}}
217217

@@ -227,7 +227,7 @@ def add_flow(
227227
if len(op_output_labels) == 1 and len(output_labels) != 1:
228228
raise IOMappingError(
229229
f"The source operator({source_op.name}) has only one port with label "
230-
f"'{next(iter(op_output_labels))}' but io_map specifies {len(output_labels)} "
230+
f"{next(iter(op_output_labels))!r} but io_map specifies {len(output_labels)} "
231231
f"labels({', '.join(output_labels)}) to the source operator's output port"
232232
)
233233

@@ -239,7 +239,7 @@ def add_flow(
239239
del io_maps[output_label]
240240
break
241241
raise IOMappingError(
242-
f"The source operator({source_op.name}) has no output port with label '{output_label}'. "
242+
f"The source operator({source_op.name}) has no output port with label {output_label!r}. "
243243
f"It should be one of ({', '.join(op_output_labels)})."
244244
)
245245

@@ -250,7 +250,7 @@ def add_flow(
250250
if len(op_input_labels) == 1 and len(input_labels) != 1:
251251
raise IOMappingError(
252252
f"The destination operator({destination_op.name}) has only one port with label "
253-
f"'{next(iter(op_input_labels))}' but io_map specifies {len(input_labels)} "
253+
f"{next(iter(op_input_labels))!r} but io_map specifies {len(input_labels)} "
254254
f"labels({', '.join(input_labels)}) to the destination operator's input port"
255255
)
256256

@@ -262,8 +262,8 @@ def add_flow(
262262
input_labels.add(next(iter(op_input_labels)))
263263
break
264264
raise IOMappingError(
265-
f"The destination operator({destination_op.name}) has no input port with label '{input_label}'. "
266-
f"It should be one of ({', '.join(op_input_labels)})."
265+
f"The destination operator({destination_op.name}) has no input port with label {input_label!r}."
266+
f" It should be one of ({', '.join(op_input_labels)})."
267267
)
268268

269269
self._graph.add_flow(source_op, destination_op, io_maps)

monai/deploy/core/domain/datapath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def get(self, name: Optional[str] = "") -> DataPath:
6767
return next(iter(self._paths.values()))
6868
else:
6969
raise IOMappingError(
70-
f"'{name}' is not a valid name. It should be one of ({', '.join(self._paths.keys())})."
70+
f"{name!r} is not a valid name. It should be one of ({', '.join(self._paths.keys())})."
7171
)
7272
else:
7373
datapath = self._paths.get(name)
7474
if not datapath:
75-
raise ItemNotExistsError(f"A DataPath instance for '{name}' does not exist.")
75+
raise ItemNotExistsError(f"A DataPath instance for {name!r} does not exist.")
7676
return datapath

monai/deploy/core/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, pip_packages: Optional[Union[str, List[str]]] = None):
3737
if requirements_path.exists():
3838
pip_packages = requirements_path.read_text().strip().splitlines() # make it a list
3939
else:
40-
raise FileNotFoundError(f"The '{requirements_path}' file does not exist!")
40+
raise FileNotFoundError(f"The {requirements_path!r} file does not exist!")
4141

4242
self._pip_packages = list(pip_packages or [])
4343

monai/deploy/core/io_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_default_label(self, label: str = "") -> str:
4949
label = next(iter(self._labels))
5050
else:
5151
raise IOMappingError(
52-
f"'{label}' is not a valid {self._io_kind} of the operator({self._op.name}). "
52+
f"{label!r} is not a valid {self._io_kind} of the operator({self._op.name}). "
5353
f"It should be one of ({', '.join(self._labels)})."
5454
)
5555
return label
@@ -82,7 +82,7 @@ def get(self, label: str = "") -> Any:
8282
key = self.get_group_path(f"{self._io_kind}/{label}")
8383
storage = self._storage
8484
if not storage.exists(key):
85-
raise ItemNotExistsError(f"'{key}' does not exist.")
85+
raise ItemNotExistsError(f"{key!r} does not exist.")
8686
return storage.get(key)
8787

8888
def set(self, value: Any, label: str = ""):
@@ -109,10 +109,10 @@ def set(self, value: Any, label: str = ""):
109109
# checking: https://www.python.org/dev/peps/pep-0585/#id15
110110
data_type = self._op_info.get_data_type(self._io_kind, label)
111111
try:
112-
check_type("value", value, data_type)
112+
check_type(value, data_type)
113113
except TypeError as err:
114114
raise IOMappingError(
115-
f"The data type of '{label}' in the {self._io_kind} of '{self._op}' is {data_type}, but the value"
115+
f"The data type of {label!r} in the {self._io_kind} of {self._op!r} is {data_type}, but the value"
116116
f" to set is the data type of {type(value)}."
117117
) from err
118118

monai/deploy/core/models/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def get(self, name: str = "") -> "Model":
164164
if item:
165165
return item
166166
else:
167-
raise ItemNotExistsError(f"A model with '{name}' does not exist.")
167+
raise ItemNotExistsError(f"A model with {name!r} does not exist.")
168168
else:
169169
item_count = len(self._items)
170170
if item_count == 1:

monai/deploy/core/models/named_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def accept(cls, path: str):
8383
# 3) Each model folder must contain only one model definition file or folder.
8484
if sum(1 for _ in model_folder.iterdir()) != 1:
8585
logger.warning(
86-
f"Model repository '{model_folder}' contains more than one model definition file or folder "
86+
f"Model repository {model_folder!r} contains more than one model definition file or folder "
8787
"so not treated as NamedModel."
8888
)
8989
return False, None

monai/deploy/core/resource.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ def set_resource_limits(
6464
self._cpu = cpu_limit
6565
else:
6666
raise ItemAlreadyExistsError(
67-
f"'cpu' wouldn't be set to {cpu_limit} because it is already set to {self._cpu} by the runtime environment."
67+
f"'cpu' wouldn't be set to {cpu_limit} because it is already set to {self._cpu} by the runtime"
68+
" environment."
6869
)
6970

7071
if gpu_limit is not None:
7172
if self._gpu is None:
7273
self._gpu = gpu_limit
7374
else:
7475
raise ItemAlreadyExistsError(
75-
f"'gpu' wouldn't be set to {gpu_limit} because it is already set to {self._gpu} by the runtime environment."
76+
f"'gpu' wouldn't be set to {gpu_limit} because it is already set to {self._gpu} by the runtime"
77+
" environment."
7678
)
7779

7880
if type(memory_limit) == str:

monai/deploy/operators/dicom_data_loader_operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ def test():
308308
print(f" 'StudyInstanceUID': {ds.StudyInstanceUID if ds.StudyInstanceUID else ''}")
309309
print(f" 'SeriesDescription': {ds.SeriesDescription if ds.SeriesDescription else ''}")
310310
print(
311-
f" 'IssuerOfPatientID': {ds.get('IssuerOfPatientID', '').repval if ds.get('IssuerOfPatientID', '') else '' }"
311+
" 'IssuerOfPatientID':"
312+
f" {ds.get('IssuerOfPatientID', '').repval if ds.get('IssuerOfPatientID', '') else '' }"
312313
)
313314
try:
314315
print(f" 'IssuerOfPatientID': {ds.IssuerOfPatientID if ds.IssuerOfPatientID else '' }")

0 commit comments

Comments
 (0)