Skip to content

Commit 6be7b13

Browse files
K-RillaSaelrapre-commit-ci[bot]dedeepyasaiKumoLiu
authored
Replaced package "pkg_resources" with "packaging" (#7953)
Fixes #7559 . ### Description Replaced "pkg_resources" references with "packaging" in MONAI/monai/utils/module.py & setup.py Changes were made in functions "pytorch_after", "version_leq", "version_geq". ### Types of changes - Non-breaking change (fix or new feature that would not break existing functionality). --------- Signed-off-by: dedeepyasai <dedeepyasai.sai@gmail.com> Signed-off-by: saelra <rasaelee@gmail.com> Signed-off-by: Kelvin R <kelvinrbNsc@gmail.com> Signed-off-by: ken-ni <kennett.vera@gmail.com> Signed-off-by: Dureti <98233210+DuretiShemsi@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Co-authored-by: saelra <rasaelee@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: dedeepyasai <dedeepyasai.sai@gmail.com> Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Co-authored-by: Ratanachat Saelee <146144408+Saelra@users.noreply.github.com> Co-authored-by: ken-ni <kennett.vera@gmail.com> Co-authored-by: Dureti <98233210+DuretiShemsi@users.noreply.github.com>
1 parent 069519d commit 6be7b13

File tree

6 files changed

+11
-6
lines changed

6 files changed

+11
-6
lines changed

.github/workflows/pythonapp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
- name: Install dependencies
152152
run: |
153153
find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \;
154-
python -m pip install --user --upgrade pip setuptools wheel twine
154+
python -m pip install --user --upgrade pip setuptools wheel twine packaging
155155
# install the latest pytorch for testing
156156
# however, "pip install monai*.tar.gz" will build cpp/cuda with an isolated
157157
# fresh torch installation according to pyproject.toml

docs/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ onnxruntime; python_version <= '3.10'
4141
zarr
4242
huggingface_hub
4343
pyamg>=5.0.0
44+
packaging

monai/utils/module.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def version_leq(lhs: str, rhs: str) -> bool:
564564
"""
565565

566566
lhs, rhs = str(lhs), str(rhs)
567-
pkging, has_ver = optional_import("pkg_resources", name="packaging")
567+
pkging, has_ver = optional_import("packaging.Version")
568568
if has_ver:
569569
try:
570570
return cast(bool, pkging.version.Version(lhs) <= pkging.version.Version(rhs))
@@ -591,7 +591,8 @@ def version_geq(lhs: str, rhs: str) -> bool:
591591
592592
"""
593593
lhs, rhs = str(lhs), str(rhs)
594-
pkging, has_ver = optional_import("pkg_resources", name="packaging")
594+
pkging, has_ver = optional_import("packaging.Version")
595+
595596
if has_ver:
596597
try:
597598
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
629630
if current_ver_string is None:
630631
_env_var = os.environ.get("PYTORCH_VER", "")
631632
current_ver_string = _env_var if _env_var else torch.__version__
632-
ver, has_ver = optional_import("pkg_resources", name="parse_version")
633+
ver, has_ver = optional_import("packaging.version", name="parse")
633634
if has_ver:
634635
return ver(".".join((f"{major}", f"{minor}", f"{patch}"))) <= ver(f"{current_ver_string}") # type: ignore
635636
parts = f"{current_ver_string}".split("+", 1)[0].split(".", 3)

requirements-min.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ setuptools>=50.3.0,<66.0.0,!=60.6.0 ; python_version < "3.12"
44
setuptools>=70.2.0; python_version >= "3.12"
55
coverage>=5.5
66
parameterized
7+
packaging

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ pyyaml =
137137
pyyaml
138138
fire =
139139
fire
140+
packaging =
141+
packaging
140142
jsonschema =
141143
jsonschema
142144
pynrrd =

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sys
1818
import warnings
1919

20-
import pkg_resources
20+
from packaging import version
2121
from setuptools import find_packages, setup
2222

2323
import versioneer
@@ -40,7 +40,7 @@
4040

4141
BUILD_CUDA = FORCE_CUDA or (torch.cuda.is_available() and (CUDA_HOME is not None))
4242

43-
_pt_version = pkg_resources.parse_version(torch.__version__).release
43+
_pt_version = version.parse(torch.__version__).release
4444
if _pt_version is None or len(_pt_version) < 3:
4545
raise AssertionError("unknown torch version")
4646
TORCH_VERSION = int(_pt_version[0]) * 10000 + int(_pt_version[1]) * 100 + int(_pt_version[2])

0 commit comments

Comments
 (0)