From ba980899318538aca97af31ff264899925237425 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:59:09 -0700 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#1665) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 23.12.1 → 24.3.0](https://github.com/psf/black/compare/23.12.1...24.3.0) - [github.com/psf/black: 23.12.1 → 24.3.0](https://github.com/psf/black/compare/23.12.1...24.3.0) - [github.com/PyCQA/flake8: 6.1.0 → 7.0.0](https://github.com/PyCQA/flake8/compare/6.1.0...7.0.0) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0) - [github.com/asottile/pyupgrade: v3.15.0 → v3.15.2](https://github.com/asottile/pyupgrade/compare/v3.15.0...v3.15.2) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update requirements.txt Signed-off-by: SACHIDANAND ALLE * Update setup.cfg Signed-off-by: SACHIDANAND ALLE --------- Signed-off-by: SACHIDANAND ALLE Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: SACHIDANAND ALLE --- .pre-commit-config.yaml | 10 ++++----- monailabel/endpoints/proxy.py | 10 ++++----- monailabel/interfaces/utils/transform.py | 10 ++++----- monailabel/scribbles/transforms.py | 6 ++--- monailabel/tasks/infer/bundle.py | 22 +++++++++++-------- monailabel/tasks/scoring/epistemic.py | 4 +--- monailabel/tasks/train/basic_train.py | 20 ++++++++++------- monailabel/tasks/train/bundle.py | 8 ++++--- .../MONAILabelReviewer/MONAILabelReviewer.py | 4 +++- requirements.txt | 2 +- setup.cfg | 2 +- tests/unit/scribbles/test_transforms_infer.py | 6 ++--- 12 files changed, 57 insertions(+), 47 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6139a27b7..ceb56fb06 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,33 +47,33 @@ repos: args: ["--line-length=120", "--profile=black", "--check"] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.3.0 hooks: - id: black args: ["--line-length=120"] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.3.0 hooks: - id: black name: black (check) args: ["--line-length=120", "--check"] - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 args: ["--count", "--statistics", "--config=setup.cfg"] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 + rev: v1.9.0 hooks: - id: mypy exclude: (^tests/|^plugins/) additional_dependencies: [types-PyYAML,types-filelock,types-requests,types-docutils,types-cachetools] - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.2 hooks: - id: pyupgrade args: [--py37-plus] diff --git a/monailabel/endpoints/proxy.py b/monailabel/endpoints/proxy.py index 7800f2fca..ffc749010 100644 --- a/monailabel/endpoints/proxy.py +++ b/monailabel/endpoints/proxy.py @@ -50,11 +50,11 @@ async def proxy_dicom(request: Request, op: str, path: str): prefix = ( settings.MONAI_LABEL_WADO_PREFIX if op == "wado" - else settings.MONAI_LABEL_QIDO_PREFIX - if op == "qido" - else settings.MONAI_LABEL_STOW_PREFIX - if op == "stow" - else "" + else ( + settings.MONAI_LABEL_QIDO_PREFIX + if op == "qido" + else settings.MONAI_LABEL_STOW_PREFIX if op == "stow" else "" + ) ) # some version of ohif requests metadata using qido so change it to wado diff --git a/monailabel/interfaces/utils/transform.py b/monailabel/interfaces/utils/transform.py index eaa9d6acb..98871c2eb 100644 --- a/monailabel/interfaces/utils/transform.py +++ b/monailabel/interfaces/utils/transform.py @@ -28,11 +28,11 @@ def dump_data(data, level=logging.DEBUG): level, "Data key: {} = {}".format( k, - v.shape - if hasattr(v, "shape") - else v - if type(v) in (int, float, bool, str, dict, tuple, list) - else type(v), + ( + v.shape + if hasattr(v, "shape") + else v if type(v) in (int, float, bool, str, dict, tuple, list) else type(v) + ), ), ) logger.log(level, "******************************************************************************") diff --git a/monailabel/scribbles/transforms.py b/monailabel/scribbles/transforms.py index e17d4186e..101033e07 100644 --- a/monailabel/scribbles/transforms.py +++ b/monailabel/scribbles/transforms.py @@ -146,9 +146,9 @@ def __call__(self, data): cz = int((selected_roi[4] + selected_roi[5]) / 2) # add scribbles at center of roi - scribbles[ - :, cx - offset : cx + offset, cy - offset : cy + offset, cz - offset : cz + offset - ] = self.scribbles_fg_label + scribbles[:, cx - offset : cx + offset, cy - offset : cy + offset, cz - offset : cz + offset] = ( + self.scribbles_fg_label + ) # return new scribbles d = self._save_data(d, self.scribbles, scribbles) diff --git a/monailabel/tasks/infer/bundle.py b/monailabel/tasks/infer/bundle.py index dce2619c3..120426bd5 100644 --- a/monailabel/tasks/infer/bundle.py +++ b/monailabel/tasks/infer/bundle.py @@ -278,15 +278,19 @@ def _get_type(self, name, type): ( InferType.DEEPEDIT if "deepedit" in name - else InferType.DEEPGROW - if "deepgrow" in name - else InferType.DETECTION - if "detection" in name - else InferType.SEGMENTATION - if "segmentation" in name - else InferType.CLASSIFICATION - if "classification" in name - else InferType.SEGMENTATION + else ( + InferType.DEEPGROW + if "deepgrow" in name + else ( + InferType.DETECTION + if "detection" in name + else ( + InferType.SEGMENTATION + if "segmentation" in name + else InferType.CLASSIFICATION if "classification" in name else InferType.SEGMENTATION + ) + ) + ) ) if not type else type diff --git a/monailabel/tasks/scoring/epistemic.py b/monailabel/tasks/scoring/epistemic.py index 7f057100e..8a9c46a1e 100644 --- a/monailabel/tasks/scoring/epistemic.py +++ b/monailabel/tasks/scoring/epistemic.py @@ -48,9 +48,7 @@ def infer_seg(self, data, model, roi_size, sw_batch_size): pre_transforms = ( None if not self.transforms - else self.transforms - if isinstance(self.transforms, Compose) - else Compose(self.transforms) + else self.transforms if isinstance(self.transforms, Compose) else Compose(self.transforms) ) # data = run_transforms(data, pre_transforms, log_prefix="EPISTEMIC-PRE") if pre_transforms else data if pre_transforms: diff --git a/monailabel/tasks/train/basic_train.py b/monailabel/tasks/train/basic_train.py index 8b8d748d5..9e5d0b1a9 100644 --- a/monailabel/tasks/train/basic_train.py +++ b/monailabel/tasks/train/basic_train.py @@ -235,11 +235,15 @@ def _dataset(self, context, datalist, is_train, replace_rate=0.25): dataset = ( CacheDataset(datalist, transforms) if context.dataset_type == "CacheDataset" - else SmartCacheDataset(datalist, transforms, replace_rate) - if context.dataset_type == "SmartCacheDataset" - else PersistentDataset(datalist, transforms, cache_dir=os.path.join(context.cache_dir, "pds")) - if context.dataset_type == "PersistentDataset" - else Dataset(datalist, transforms) + else ( + SmartCacheDataset(datalist, transforms, replace_rate) + if context.dataset_type == "SmartCacheDataset" + else ( + PersistentDataset(datalist, transforms, cache_dir=os.path.join(context.cache_dir, "pds")) + if context.dataset_type == "PersistentDataset" + else Dataset(datalist, transforms) + ) + ) ) return dataset, datalist @@ -681,9 +685,9 @@ def _create_trainer(self, context: Context): save_final=True, final_filename=self._final_filename, save_key_metric=True, - key_metric_filename=f"train_{self._key_metric_filename}" - if context.evaluator - else self._key_metric_filename, + key_metric_filename=( + f"train_{self._key_metric_filename}" if context.evaluator else self._key_metric_filename + ), n_saved=self._n_saved, ) ) diff --git a/monailabel/tasks/train/bundle.py b/monailabel/tasks/train/bundle.py index 004f8b641..44c90f393 100644 --- a/monailabel/tasks/train/bundle.py +++ b/monailabel/tasks/train/bundle.py @@ -140,9 +140,11 @@ def config(self): "val_split": 0.2, # VALIDATION SPLIT; -1 TO USE DEFAULT FROM BUNDLE "multi_gpu": True, # USE MULTI-GPU "gpus": "all", # COMMA SEPARATE DEVICE INDEX - "tracking": ["mlflow", "None"] - if self.enable_tracking and settings.MONAI_LABEL_TRACKING_ENABLED - else ["None", "mlflow"], + "tracking": ( + ["mlflow", "None"] + if self.enable_tracking and settings.MONAI_LABEL_TRACKING_ENABLED + else ["None", "mlflow"] + ), "tracking_uri": settings.MONAI_LABEL_TRACKING_URI, "tracking_experiment_name": "", "run_id": "", # bundle run id, if different from default diff --git a/plugins/slicer/MONAILabelReviewer/MONAILabelReviewer.py b/plugins/slicer/MONAILabelReviewer/MONAILabelReviewer.py index 455d80fe7..643598e7f 100644 --- a/plugins/slicer/MONAILabelReviewer/MONAILabelReviewer.py +++ b/plugins/slicer/MONAILabelReviewer/MONAILabelReviewer.py @@ -1463,7 +1463,9 @@ def updateAfterEditingSegmentation(self): elif setToOverwrite: if (imageVersionTag == self.LABEL.FINAL) or (imageVersionTag == self.LABEL.ORIGINAL): - warningMessage: str = "Initial Segmentation with label 'final' or 'original' \ncannot be overwritten.\n Please save current edit as new version." + warningMessage: str = ( + "Initial Segmentation with label 'final' or 'original' \ncannot be overwritten.\n Please save current edit as new version." + ) slicer.util.warningDisplay(warningMessage) logging.warn(warningMessage) return diff --git a/requirements.txt b/requirements.txt index ff71a1096..c9bb73e3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ fastapi==0.95.0 python-multipart==0.0.6 httpx==0.23.3 schedule==1.1.0 -dicomweb-client==0.59.1 +dicomweb-client[gcp]==0.59.1 timeloop==1.0.2 expiringdict==1.2.2 expiring_dict==1.1.0 diff --git a/setup.cfg b/setup.cfg index 39e59cd41..6221b8cdf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,7 @@ install_requires = requests-toolbelt==0.10.1 httpx==0.23.3 schedule==1.1.0 - dicomweb-client==0.59.1 + dicomweb-client[gcp]==0.59.1 timeloop==1.0.2 expiringdict==1.2.2 expiring_dict==1.1.0 diff --git a/tests/unit/scribbles/test_transforms_infer.py b/tests/unit/scribbles/test_transforms_infer.py index 01b53ffbf..d1e943bca 100644 --- a/tests/unit/scribbles/test_transforms_infer.py +++ b/tests/unit/scribbles/test_transforms_infer.py @@ -273,9 +273,9 @@ def add_scribbles_from_roi(scribbles, roi, scribbles_fg_label, scribbles_bg_labe cz = int((roi[4] + roi[5]) / 2) # add scribbles at center of roi - scribbles[ - :, cx - offset : cx + offset, cy - offset : cy + offset, cz - offset : cz + offset - ] = scribbles_fg_label + scribbles[:, cx - offset : cx + offset, cy - offset : cy + offset, cz - offset : cz + offset] = ( + scribbles_fg_label + ) return scribbles