From 77207ad46345343d0249f2cbc3133b63dcb99b40 Mon Sep 17 00:00:00 2001 From: saelra Date: Sat, 20 Jul 2024 11:31:55 -0700 Subject: [PATCH 01/31] remove pkg_resources and replace with packaging.version --- monai/utils/module.py | 27 +++++++++++++++++++-------- setup.py | 6 ++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 4d28f8d986..f53e20150e 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -27,9 +27,13 @@ from re import match from types import FunctionType, ModuleType from typing import Any, Iterable, cast - import torch +import importlib.metadata +from packaging import version +from packaging.version import Version, parse + + # bundle config system flags # set MONAI_EVAL_EXPR=1 to use 'eval', default value: run_eval=True run_eval = os.environ.get("MONAI_EVAL_EXPR", "1") != "0" @@ -564,11 +568,14 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("pkg_resources", name="packaging") + pkging, has_ver = optional_import("packaging", name="packaging") + # pkging, has_ver = optional_import("pkg_resources", name="packaging") if has_ver: try: - return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) - except pkging.version.InvalidVersion: + return cast(bool, version(lhs) <= version(rhs)) + # return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) + except version.InvalidVersion: + # except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) @@ -591,11 +598,14 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("pkg_resources", name="packaging") + pkging, has_ver = optional_import("packaging", name="packaging") + # pkging, has_ver = optional_import("pkg_resources", name="packaging") if has_ver: try: - return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) - except pkging.version.InvalidVersion: + return cast(bool, version(lhs) >= version(rhs)) + # return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) + except version.InvalidVersion: + # except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) @@ -629,7 +639,8 @@ def pytorch_after(major: int, minor: int, patch: int = 0, current_ver_string: st if current_ver_string is None: _env_var = os.environ.get("PYTORCH_VER", "") current_ver_string = _env_var if _env_var else torch.__version__ - ver, has_ver = optional_import("pkg_resources", name="parse_version") + ver, has_ver = optional_import("packaging.version", name="parse") + # ver, has_ver = optional_import("pkg_resources", name="parse_version") if has_ver: return ver(".".join((f"{major}", f"{minor}", f"{patch}"))) <= ver(f"{current_ver_string}") # type: ignore parts = f"{current_ver_string}".split("+", 1)[0].split(".", 3) diff --git a/setup.py b/setup.py index b90d9d0976..f35544994f 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,8 @@ import sys import warnings -import pkg_resources +# import pkg_resources +from packaging import version from setuptools import find_packages, setup import versioneer @@ -40,7 +41,8 @@ BUILD_CUDA = FORCE_CUDA or (torch.cuda.is_available() and (CUDA_HOME is not None)) - _pt_version = pkg_resources.parse_version(torch.__version__).release + # _pt_version = pkg_resources.parse_version(torch.__version__).release + _pt_version = version.parse(torch.__version__).release if _pt_version is None or len(_pt_version) < 3: raise AssertionError("unknown torch version") TORCH_VERSION = int(_pt_version[0]) * 10000 + int(_pt_version[1]) * 100 + int(_pt_version[2]) From 9656e4336aa715cb0dd16309e0017b58666e5c78 Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Thu, 25 Jul 2024 17:22:14 -0700 Subject: [PATCH 02/31] Removed comments from pkg_resources --- monai/utils/module.py | 3 --- setup.py | 2 -- 2 files changed, 5 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index f53e20150e..4785c4c7c5 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -569,7 +569,6 @@ def version_leq(lhs: str, rhs: str) -> bool: lhs, rhs = str(lhs), str(rhs) pkging, has_ver = optional_import("packaging", name="packaging") - # pkging, has_ver = optional_import("pkg_resources", name="packaging") if has_ver: try: return cast(bool, version(lhs) <= version(rhs)) @@ -599,7 +598,6 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) pkging, has_ver = optional_import("packaging", name="packaging") - # pkging, has_ver = optional_import("pkg_resources", name="packaging") if has_ver: try: return cast(bool, version(lhs) >= version(rhs)) @@ -640,7 +638,6 @@ def pytorch_after(major: int, minor: int, patch: int = 0, current_ver_string: st _env_var = os.environ.get("PYTORCH_VER", "") current_ver_string = _env_var if _env_var else torch.__version__ ver, has_ver = optional_import("packaging.version", name="parse") - # ver, has_ver = optional_import("pkg_resources", name="parse_version") if has_ver: return ver(".".join((f"{major}", f"{minor}", f"{patch}"))) <= ver(f"{current_ver_string}") # type: ignore parts = f"{current_ver_string}".split("+", 1)[0].split(".", 3) diff --git a/setup.py b/setup.py index f35544994f..576743c1f7 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ import sys import warnings -# import pkg_resources from packaging import version from setuptools import find_packages, setup @@ -41,7 +40,6 @@ BUILD_CUDA = FORCE_CUDA or (torch.cuda.is_available() and (CUDA_HOME is not None)) - # _pt_version = pkg_resources.parse_version(torch.__version__).release _pt_version = version.parse(torch.__version__).release if _pt_version is None or len(_pt_version) < 3: raise AssertionError("unknown torch version") From 598f70d0528e00209fd97348b6c59dac38d0c519 Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Thu, 25 Jul 2024 17:31:16 -0700 Subject: [PATCH 03/31] Removed a comment --- monai/utils/module.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 4785c4c7c5..fde018d6a2 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -572,9 +572,7 @@ def version_leq(lhs: str, rhs: str) -> bool: if has_ver: try: return cast(bool, version(lhs) <= version(rhs)) - # return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) except version.InvalidVersion: - # except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) @@ -601,9 +599,7 @@ def version_geq(lhs: str, rhs: str) -> bool: if has_ver: try: return cast(bool, version(lhs) >= version(rhs)) - # return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) except version.InvalidVersion: - # except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) From ab3ae7377a5d543054ef9a90ec04398e80417a53 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:37:08 +0000 Subject: [PATCH 04/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/utils/module.py | 1 - 1 file changed, 1 deletion(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index fde018d6a2..f5ea57be24 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -31,7 +31,6 @@ import importlib.metadata from packaging import version -from packaging.version import Version, parse # bundle config system flags From 967f4ad8fce795a213ce82cd3df66af090c85383 Mon Sep 17 00:00:00 2001 From: dedeepyasai Date: Thu, 25 Jul 2024 23:23:48 -0500 Subject: [PATCH 05/31] updated packaging in setup, utils Signed-off-by: dedeepyasai --- docs/requirements.txt | 1 + monai/utils/module.py | 9 ++++----- requirements-dev.txt | 1 + requirements-min.txt | 1 + setup.cfg | 2 ++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index fe415a07b5..ff94f7b6de 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -41,3 +41,4 @@ onnxruntime; python_version <= '3.10' zarr huggingface_hub pyamg>=5.0.0 +packaging diff --git a/monai/utils/module.py b/monai/utils/module.py index f5ea57be24..747d3a17b9 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -30,7 +30,6 @@ import torch import importlib.metadata -from packaging import version # bundle config system flags @@ -567,10 +566,10 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging", name="packaging") + pkging, has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, version(lhs) <= version(rhs)) + return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) except version.InvalidVersion: return True @@ -594,10 +593,10 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging", name="packaging") + pkging, has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, version(lhs) >= version(rhs)) + return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) except version.InvalidVersion: return True diff --git a/requirements-dev.txt b/requirements-dev.txt index ced783443e..1a687a6533 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,3 +59,4 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd +packaging diff --git a/requirements-min.txt b/requirements-min.txt index a091ef0568..21cf9d5e5c 100644 --- a/requirements-min.txt +++ b/requirements-min.txt @@ -4,3 +4,4 @@ setuptools>=50.3.0,<66.0.0,!=60.6.0 ; python_version < "3.12" setuptools>=70.2.0; python_version >= "3.12" coverage>=5.5 parameterized +packaging diff --git a/setup.cfg b/setup.cfg index 202e7b0e24..dfa94fcfa1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -137,6 +137,8 @@ pyyaml = pyyaml fire = fire +packaging = + packaging jsonschema = jsonschema pynrrd = From df38261e85107c610a61ced0532f46c514b9e77b Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Sat, 27 Jul 2024 10:37:51 -0700 Subject: [PATCH 06/31] Fixing imports --- monai/utils/module.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 747d3a17b9..59eaedd1eb 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -29,8 +29,8 @@ from typing import Any, Iterable, cast import torch -import importlib.metadata - +## import importlib.metadata +## from packaging import version # bundle config system flags # set MONAI_EVAL_EXPR=1 to use 'eval', default value: run_eval=True @@ -566,10 +566,10 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) + return cast(bool, version(lhs) <= version(rhs)) except version.InvalidVersion: return True @@ -593,10 +593,10 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) + return cast(bool, version(lhs) >= version(rhs)) except version.InvalidVersion: return True From e0c4d21e6388c59eafea188d3188c995a417c97b Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Sat, 27 Jul 2024 10:37:51 -0700 Subject: [PATCH 07/31] Fixing imports Signed-off-by Kelvin R --- monai/utils/module.py | 16 ++++++++-------- setup.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 747d3a17b9..a2b1a11921 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -29,8 +29,8 @@ from typing import Any, Iterable, cast import torch -import importlib.metadata - +## import importlib.metadata +## from packaging import version # bundle config system flags # set MONAI_EVAL_EXPR=1 to use 'eval', default value: run_eval=True @@ -74,10 +74,10 @@ def look_up_option( Raise a value error possibly with a guess of the closest match. Args: - opt_str: The option string or Enum to look up. + opt_str: The option string or Enum to look up. supported: The collection of supported options, it can be list, tuple, set, dict, or Enum. default: If it is given, this method will return `default` when `opt_str` is not found, - instead of raising a `ValueError`. Otherwise, it defaults to `"no_default"`, + instead of raising a `ValueError`. Otherwise, it defaults to `"no_default"`, so that the method may raise a `ValueError`. print_all_options: whether to print all available options when `opt_str` is not found. Defaults to True @@ -566,10 +566,10 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) + return cast(bool, version(lhs) <= version(rhs)) except version.InvalidVersion: return True @@ -593,10 +593,10 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) + return cast(bool, version(lhs) >= version(rhs)) except version.InvalidVersion: return True diff --git a/setup.py b/setup.py index 576743c1f7..67a5b00933 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ import versioneer -# TODO: debug mode -g -O0, compile test cases +# TODO: debug mode -g -O0, compile test cases RUN_BUILD = os.getenv("BUILD_MONAI", "0") == "1" FORCE_CUDA = os.getenv("FORCE_CUDA", "0") == "1" # flag ignored if BUILD_MONAI is False From 6acc718af655d0aca1c17dbe0027d6727e6c606d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 27 Jul 2024 17:54:33 +0000 Subject: [PATCH 08/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/utils/module.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index a2b1a11921..59eaedd1eb 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -74,10 +74,10 @@ def look_up_option( Raise a value error possibly with a guess of the closest match. Args: - opt_str: The option string or Enum to look up. + opt_str: The option string or Enum to look up. supported: The collection of supported options, it can be list, tuple, set, dict, or Enum. default: If it is given, this method will return `default` when `opt_str` is not found, - instead of raising a `ValueError`. Otherwise, it defaults to `"no_default"`, + instead of raising a `ValueError`. Otherwise, it defaults to `"no_default"`, so that the method may raise a `ValueError`. print_all_options: whether to print all available options when `opt_str` is not found. Defaults to True diff --git a/setup.py b/setup.py index 67a5b00933..576743c1f7 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ import versioneer -# TODO: debug mode -g -O0, compile test cases +# TODO: debug mode -g -O0, compile test cases RUN_BUILD = os.getenv("BUILD_MONAI", "0") == "1" FORCE_CUDA = os.getenv("FORCE_CUDA", "0") == "1" # flag ignored if BUILD_MONAI is False From 758fd66c04b9bdee7dd15c91bcdd0db9cd875a53 Mon Sep 17 00:00:00 2001 From: saelra Date: Sat, 27 Jul 2024 10:58:50 -0700 Subject: [PATCH 09/31] Fix DCO DCO Remediation Commit for saelra I, saelra , hereby add my Signed-off-by to this commit: 77207ad46345343d0249f2cbc3133b63dcb99b40 Signed-off-by: saelra --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 576743c1f7..01afcf0e0b 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import sys import warnings -from packaging import version +from packaging import version from setuptools import find_packages, setup import versioneer From 6ab46f7460650de238829a6df240a67c50766a52 Mon Sep 17 00:00:00 2001 From: saelra Date: Sat, 27 Jul 2024 10:59:35 -0700 Subject: [PATCH 10/31] Fix DCO I, saelra , hereby add my Signed-off-by to this commit: 77207ad46345343d0249f2cbc3133b63dcb99b40 Signed-off-by: saelra --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 01afcf0e0b..576743c1f7 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import sys import warnings -from packaging import version +from packaging import version from setuptools import find_packages, setup import versioneer From 2cc0e083d22458615aada90307e7113b65492997 Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Sat, 27 Jul 2024 11:14:19 -0700 Subject: [PATCH 11/31] DCO Remediation Commit for Kelvin R I, Kelvin R , hereby add my Signed-off-by to this commit: 9656e4336aa715cb0dd16309e0017b58666e5c78 I, Kelvin R , hereby add my Signed-off-by to this commit: 598f70d0528e00209fd97348b6c59dac38d0c519 I, Kelvin R , hereby add my Signed-off-by to this commit: df38261e85107c610a61ced0532f46c514b9e77b I, Kelvin R , hereby add my Signed-off-by to this commit: e0c4d21e6388c59eafea188d3188c995a417c97b Signed-off-by: Kelvin R --- monai/utils/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 59eaedd1eb..a343820471 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -60,7 +60,7 @@ "version_leq", "version_geq", "pytorch_after", -] +] def look_up_option( From 40084953cf1c8c89af3fc6b0c1b8054a974eaffd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 27 Jul 2024 18:14:44 +0000 Subject: [PATCH 12/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/utils/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index a343820471..59eaedd1eb 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -60,7 +60,7 @@ "version_leq", "version_geq", "pytorch_after", -] +] def look_up_option( From bb22a37c59670b3d2573446fcef4cd243607ea35 Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Sat, 27 Jul 2024 11:22:51 -0700 Subject: [PATCH 13/31] Fixing version Signed-off-by: Kelvin R --- monai/utils/module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index a343820471..839bc664bc 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -30,7 +30,7 @@ import torch ## import importlib.metadata -## from packaging import version +from packaging import version # bundle config system flags # set MONAI_EVAL_EXPR=1 to use 'eval', default value: run_eval=True From de41c6403f83d53bc85563a23912aff83e49d5f6 Mon Sep 17 00:00:00 2001 From: ken-ni Date: Thu, 1 Aug 2024 17:45:23 -0700 Subject: [PATCH 14/31] Addressed comments, reverted pkging references Signed-off-by: ken-ni --- monai/utils/module.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index ebc41d9d43..1da75370d3 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -29,9 +29,6 @@ from typing import Any, Iterable, cast import torch -## import importlib.metadata -from packaging import version - # bundle config system flags # set MONAI_EVAL_EXPR=1 to use 'eval', default value: run_eval=True run_eval = os.environ.get("MONAI_EVAL_EXPR", "1") != "0" @@ -566,11 +563,11 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - has_ver = optional_import("packaging") + pkging, has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, version(lhs) <= version(rhs)) - except version.InvalidVersion: + return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) + except pkging.version.Version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) @@ -593,11 +590,11 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - has_ver = optional_import("packaging") + pkging, has_ver = optional_import("packaging") if has_ver: try: - return cast(bool, version(lhs) >= version(rhs)) - except version.InvalidVersion: + return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) + except pkging.version.Version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) From fe1a4150fe8ed66bc18d4b4040d1c89b39aa0116 Mon Sep 17 00:00:00 2001 From: Dureti <98233210+DuretiShemsi@users.noreply.github.com> Date: Sat, 3 Aug 2024 10:39:31 -0700 Subject: [PATCH 15/31] updating exception packaging, remove packaging from requirement-dev.txt file Signed-off-by: DuretiShemsi --- monai/utils/module.py | 4 ++-- requirements-dev.txt | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 1da75370d3..204697ffa1 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -567,7 +567,7 @@ def version_leq(lhs: str, rhs: str) -> bool: if has_ver: try: return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) - except pkging.version.Version.InvalidVersion: + except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) @@ -594,7 +594,7 @@ def version_geq(lhs: str, rhs: str) -> bool: if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) - except pkging.version.Version.InvalidVersion: + except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) diff --git a/requirements-dev.txt b/requirements-dev.txt index 79572f099d..72ba210093 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,4 +59,3 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd -packaging From ed56b7e8b8163a36a92e25a4772071b9ef366d9d Mon Sep 17 00:00:00 2001 From: Dureti <98233210+DuretiShemsi@users.noreply.github.com> Date: Sat, 3 Aug 2024 10:39:31 -0700 Subject: [PATCH 16/31] DCO Remediation Commit for Dureti <98233210+DuretiShemsi@users.noreply.github.com> I, Dureti <98233210+DuretiShemsi@users.noreply.github.com>, hereby add my Signed-off-by to this commit: fe1a4150fe8ed66bc18d4b4040d1c89b39aa0116 Signed-off-by: Dureti <98233210+DuretiShemsi@users.noreply.github.com> --- monai/utils/module.py | 4 ++-- requirements-dev.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 1da75370d3..204697ffa1 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -567,7 +567,7 @@ def version_leq(lhs: str, rhs: str) -> bool: if has_ver: try: return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) - except pkging.version.Version.InvalidVersion: + except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) @@ -594,7 +594,7 @@ def version_geq(lhs: str, rhs: str) -> bool: if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) - except pkging.version.Version.InvalidVersion: + except pkging.version.InvalidVersion: return True lhs_, rhs_ = parse_version_strs(lhs, rhs) diff --git a/requirements-dev.txt b/requirements-dev.txt index 79572f099d..7c34561771 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,4 +59,4 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd -packaging + From e53b5a9679b6f5c4777e1b4fa75e43777bcf8599 Mon Sep 17 00:00:00 2001 From: Dureti <98233210+DuretiShemsi@users.noreply.github.com> Date: Sat, 3 Aug 2024 10:46:45 -0700 Subject: [PATCH 17/31] updating exception packaging, remove packaging from requirement-dev.txt Signed-off-by: Dureti <98233210+DuretiShemsi@users.noreply.github.com> --- requirements-dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7c34561771..72ba210093 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,4 +59,3 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd - From d93374f1cd3d268e153b9ba32665f7a42b450a92 Mon Sep 17 00:00:00 2001 From: Dureti <98233210+DuretiShemsi@users.noreply.github.com> Date: Sat, 3 Aug 2024 11:57:21 -0700 Subject: [PATCH 18/31] fix linting, changed import sub module packaging.version Signed-off-by: Dureti <98233210+DuretiShemsi@users.noreply.github.com> --- monai/utils/module.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 204697ffa1..bbd8bdd0bf 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -27,6 +27,7 @@ from re import match from types import FunctionType, ModuleType from typing import Any, Iterable, cast + import torch # bundle config system flags @@ -563,7 +564,7 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + pkging, has_ver = optional_import("packaging.Version") if has_ver: try: return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) @@ -590,7 +591,7 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + pkging, has_ver = optional_import("packaging.Version") if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) From 25e19a912dd44f84b2ed00308b12242190a9ee1c Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Tue, 6 Aug 2024 18:09:31 -0700 Subject: [PATCH 19/31] Added packaging to requirements-dev. Signed-off-by: Kelvin R --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 72ba210093..ab9b1a4c62 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,3 +59,4 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd +packaging \ No newline at end of file From 6132581efa79be33e7c1d7332ede19c6aa21e3b8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 01:09:58 +0000 Subject: [PATCH 20/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ab9b1a4c62..79572f099d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,4 +59,4 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd -packaging \ No newline at end of file +packaging From 4041ffe7c74fc47c21c5e597fe5e0e403b721c05 Mon Sep 17 00:00:00 2001 From: ken-ni Date: Thu, 8 Aug 2024 17:29:33 -0700 Subject: [PATCH 21/31] Remove packaging from requirements-dev Signed-off-by: ken-ni --- requirements-dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 79572f099d..72ba210093 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -59,4 +59,3 @@ nvidia-ml-py huggingface_hub pyamg>=5.0.0 git+https://github.com/Project-MONAI/GenerativeModels.git@7428fce193771e9564f29b91d29e523dd1b6b4cd -packaging From 8226d4c06f83b021493f2312f4ff081c549043b7 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:24:16 +0800 Subject: [PATCH 22/31] add packaging in pythonapp.yml Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- .github/workflows/pythonapp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 65f9a4dcf2..3c39166c1e 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -151,7 +151,7 @@ jobs: - name: Install dependencies run: | find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; - python -m pip install --user --upgrade pip setuptools wheel twine + python -m pip install --user --upgrade pip setuptools wheel twine packaging # install the latest pytorch for testing # however, "pip install monai*.tar.gz" will build cpp/cuda with an isolated # fresh torch installation according to pyproject.toml From f8689c88264d8d31f80455e9605a3f4218434abf Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:02:29 +0800 Subject: [PATCH 23/31] minor fix Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/utils/module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index bbd8bdd0bf..eb14823aba 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -564,7 +564,7 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging.Version") + pkging, has_ver = optional_import("packaging") if has_ver: try: return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) @@ -591,7 +591,7 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging.Version") + pkging, has_ver = optional_import("packaging") if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) From e3c34909578a46488a96168a39bbec6f80779767 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:05:20 +0800 Subject: [PATCH 24/31] Revert "minor fix" This reverts commit f8689c88264d8d31f80455e9605a3f4218434abf. --- monai/utils/module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index eb14823aba..bbd8bdd0bf 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -564,7 +564,7 @@ def version_leq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + pkging, has_ver = optional_import("packaging.Version") if has_ver: try: return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs)) @@ -591,7 +591,7 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) - pkging, has_ver = optional_import("packaging") + pkging, has_ver = optional_import("packaging.Version") if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) From d28e27af098c308df94e13cff20ee47a790eaee8 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:06:36 +0800 Subject: [PATCH 25/31] DCO Remediation Commit for YunLiu <55491388+KumoLiu@users.noreply.github.com> I, YunLiu <55491388+KumoLiu@users.noreply.github.com>, hereby add my Signed-off-by to this commit: e3c34909578a46488a96168a39bbec6f80779767 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/utils/module.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monai/utils/module.py b/monai/utils/module.py index bbd8bdd0bf..251232d62f 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -592,6 +592,7 @@ def version_geq(lhs: str, rhs: str) -> bool: """ lhs, rhs = str(lhs), str(rhs) pkging, has_ver = optional_import("packaging.Version") + if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) From 9645f5c78896226851154717bf90963213ddd8b0 Mon Sep 17 00:00:00 2001 From: Kelvin R Date: Tue, 20 Aug 2024 17:32:30 -0700 Subject: [PATCH 26/31] Added "normalized_shape" positional argument. Signed-off-by: Kelvin R --- monai/networks/layers/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monai/networks/layers/utils.py b/monai/networks/layers/utils.py index 8676f74638..70a9eece6b 100644 --- a/monai/networks/layers/utils.py +++ b/monai/networks/layers/utils.py @@ -49,6 +49,8 @@ def get_norm_layer(name: tuple | str, spatial_dims: int | None = 1, channels: in kw_args["num_features"] = channels if has_option(norm_type, "num_channels") and "num_channels" not in kw_args: kw_args["num_channels"] = channels + if has_option(norm_type, "normalized_shape") and "normalized_shape" not in kw_args: + kw_args["normalized_shape"] = channels return norm_type(**kw_args) From e83d123b731c316350ca59ea6a58fbdd4c562333 Mon Sep 17 00:00:00 2001 From: ken-ni Date: Thu, 29 Aug 2024 17:32:21 -0700 Subject: [PATCH 27/31] Add docstring to RandImageFilterd regarding resized image after transform Signed-off-by: ken-ni --- monai/transforms/utility/dictionary.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monai/transforms/utility/dictionary.py b/monai/transforms/utility/dictionary.py index 7e3a7b0454..9886de75bd 100644 --- a/monai/transforms/utility/dictionary.py +++ b/monai/transforms/utility/dictionary.py @@ -1714,6 +1714,10 @@ class RandImageFilterd(MapTransform, RandomizableTransform): Probability the transform is applied to the data allow_missing_keys: Don't raise exception if key is missing. + + Note: + - This method does not scale the image automatically. The user will need to manually scale + the image back to its proper size after RandImageFilterd transforms. """ backend = ImageFilter.backend From ba51fdb2a3ca40cd099a49a6d39ea17c5b56a79c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 00:46:13 +0000 Subject: [PATCH 28/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/transforms/utility/dictionary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/transforms/utility/dictionary.py b/monai/transforms/utility/dictionary.py index 9886de75bd..3fd85f277d 100644 --- a/monai/transforms/utility/dictionary.py +++ b/monai/transforms/utility/dictionary.py @@ -1715,8 +1715,8 @@ class RandImageFilterd(MapTransform, RandomizableTransform): allow_missing_keys: Don't raise exception if key is missing. - Note: - - This method does not scale the image automatically. The user will need to manually scale + Note: + - This method does not scale the image automatically. The user will need to manually scale the image back to its proper size after RandImageFilterd transforms. """ From 1a778d251ea827d0d214ac46c6427fa5cca230cc Mon Sep 17 00:00:00 2001 From: ken-ni Date: Thu, 29 Aug 2024 17:48:26 -0700 Subject: [PATCH 29/31] Remove "normalized_shape" positional argument. Signed-off-by: ken-ni --- monai/networks/layers/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/monai/networks/layers/utils.py b/monai/networks/layers/utils.py index 70a9eece6b..8676f74638 100644 --- a/monai/networks/layers/utils.py +++ b/monai/networks/layers/utils.py @@ -49,8 +49,6 @@ def get_norm_layer(name: tuple | str, spatial_dims: int | None = 1, channels: in kw_args["num_features"] = channels if has_option(norm_type, "num_channels") and "num_channels" not in kw_args: kw_args["num_channels"] = channels - if has_option(norm_type, "normalized_shape") and "normalized_shape" not in kw_args: - kw_args["normalized_shape"] = channels return norm_type(**kw_args) From e4bbeee095b808b50cac829afa61bf77cb1609f0 Mon Sep 17 00:00:00 2001 From: dedeepyasai Date: Fri, 30 Aug 2024 09:45:34 -0500 Subject: [PATCH 30/31] Update monai/transforms/utility/dictionary.py Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: dedeepyasai --- monai/transforms/utility/dictionary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/transforms/utility/dictionary.py b/monai/transforms/utility/dictionary.py index 3fd85f277d..249139f9fd 100644 --- a/monai/transforms/utility/dictionary.py +++ b/monai/transforms/utility/dictionary.py @@ -1716,8 +1716,8 @@ class RandImageFilterd(MapTransform, RandomizableTransform): Don't raise exception if key is missing. Note: - - This method does not scale the image automatically. The user will need to manually scale - the image back to its proper size after RandImageFilterd transforms. + - This transform does not scale output image values automatically to match the range of the input. + The output should be scaled by later transforms to match the input if this is desired. """ backend = ImageFilter.backend From cb4b64622892c72bc2f8c214282e682f0bec8db4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:45:57 +0000 Subject: [PATCH 31/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/transforms/utility/dictionary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/transforms/utility/dictionary.py b/monai/transforms/utility/dictionary.py index 249139f9fd..2475060f4e 100644 --- a/monai/transforms/utility/dictionary.py +++ b/monai/transforms/utility/dictionary.py @@ -1716,7 +1716,7 @@ class RandImageFilterd(MapTransform, RandomizableTransform): Don't raise exception if key is missing. Note: - - This transform does not scale output image values automatically to match the range of the input. + - This transform does not scale output image values automatically to match the range of the input. The output should be scaled by later transforms to match the input if this is desired. """