Skip to content

Commit

Permalink
Replace deprecated disutils.version with packaging.version (#5868)
Browse files Browse the repository at this point in the history
Split from #5799

`distutils` will be removed in Python 3.12. For version parsing, other RAPIDS libraries use `packaging` so added as a dependency as well

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)
  - Ray Douglass (https://github.com/raydouglass)

URL: #5868
  • Loading branch information
mroeschke authored Apr 25, 2024
1 parent bcade6e commit 2842427
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
- numba>=0.57
- numpydoc
- nvcc_linux-64=11.8
- packaging
- pip
- pydata-sphinx-theme!=0.14.2
- pylibraft==24.6.*
Expand Down
1 change: 1 addition & 0 deletions conda/environments/all_cuda-122_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
- nltk
- numba>=0.57
- numpydoc
- packaging
- pip
- pydata-sphinx-theme!=0.14.2
- pylibraft==24.6.*
Expand Down
1 change: 1 addition & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ dependencies:
# we make it optional (i.e. an extra for pip
# installation/run_constrained for conda)?
- scipy>=1.8.0
- packaging
- rapids-dask-dependency==24.6.*
- *treelite
- output_types: conda
Expand Down
19 changes: 8 additions & 11 deletions python/cuml/internals/import_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,9 @@

import platform

from packaging.version import Version

from cuml.internals.safe_imports import gpu_only_import, UnavailableError
from distutils.version import LooseVersion


numba = gpu_only_import("numba")
Expand Down Expand Up @@ -123,14 +124,14 @@ def check_min_dask_version(version):
try:
import dask

return LooseVersion(dask.__version__) >= LooseVersion(version)
return Version(dask.__version__) >= Version(version)
except ImportError:
return False


def check_min_numba_version(version):
try:
return LooseVersion(str(numba.__version__)) >= LooseVersion(version)
return Version(str(numba.__version__)) >= Version(version)
except UnavailableError:
return False

Expand All @@ -139,7 +140,7 @@ def check_min_cupy_version(version):
if has_cupy():
import cupy

return LooseVersion(str(cupy.__version__)) >= LooseVersion(version)
return Version(str(cupy.__version__)) >= Version(version)
else:
return False

Expand Down Expand Up @@ -186,9 +187,7 @@ def has_shap(min_version="0.37"):
if min_version is None:
return True
else:
return LooseVersion(str(shap.__version__)) >= LooseVersion(
min_version
)
return Version(str(shap.__version__)) >= Version(min_version)
except ImportError:
return False

Expand All @@ -200,9 +199,7 @@ def has_daskglm(min_version=None):
if min_version is None:
return True
else:
return LooseVersion(str(dask_glm.__version__)) >= LooseVersion(
min_version
)
return Version(str(dask_glm.__version__)) >= Version(min_version)
except ImportError:
return False

Expand Down
6 changes: 3 additions & 3 deletions python/cuml/tests/test_linear_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,9 @@
# limitations under the License.
#
from contextlib import nullcontext
from distutils.version import LooseVersion
from functools import lru_cache

from packaging.version import Version
import pytest
import sklearn
from cuml.internals.array import elements_in_representable_range
Expand Down Expand Up @@ -488,7 +488,7 @@ def test_logistic_regression(
):
ncols, n_info = column_info
# Checking sklearn >= 0.21 for testing elasticnet
sk_check = LooseVersion(str(sklearn.__version__)) >= LooseVersion("0.21.0")
sk_check = Version(str(sklearn.__version__)) >= Version("0.21.0")
if not sk_check and penalty == "elasticnet":
pytest.skip(
"Need sklearn > 0.21 for testing logistic with" "elastic net."
Expand Down
1 change: 1 addition & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies = [
"dask-cudf==24.6.*",
"joblib>=0.11",
"numba>=0.57",
"packaging",
"pylibraft==24.6.*",
"raft-dask==24.6.*",
"rapids-dask-dependency==24.6.*",
Expand Down

0 comments on commit 2842427

Please sign in to comment.