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 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 4d28f8d986..251232d62f 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("pkg_resources", name="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,8 @@ 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.Version") + if has_ver: try: return cast(bool, pkging.version.Version(lhs) >= pkging.version.Version(rhs)) @@ -629,7 +630,7 @@ 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") 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/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 = diff --git a/setup.py b/setup.py index b90d9d0976..576743c1f7 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import sys import warnings -import pkg_resources +from packaging import version from setuptools import find_packages, setup import versioneer @@ -40,7 +40,7 @@ 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") TORCH_VERSION = int(_pt_version[0]) * 10000 + int(_pt_version[1]) * 100 + int(_pt_version[2])