Unverified Commit 80d1319e authored by Xuehai Pan's avatar Xuehai Pan Committed by GitHub
Browse files

[setup] drop deprecated `distutils` usage (#22531)

* [setup] drop deprecated `distutils` usage

* drop deprecated `distutils.util.strtobool` usage

* fix import order

* reformat docstring by `doc-builder`
parent 4c33a0c4
...@@ -76,10 +76,9 @@ To create the package for pypi. ...@@ -76,10 +76,9 @@ To create the package for pypi.
import os import os
import re import re
import shutil import shutil
from distutils.core import Command
from pathlib import Path from pathlib import Path
from setuptools import find_packages, setup from setuptools import find_packages, setup, Command
# Remove stale transformers.egg-info directory to avoid https://github.com/pypa/pip/issues/5466 # Remove stale transformers.egg-info directory to avoid https://github.com/pypa/pip/issues/5466
......
...@@ -28,7 +28,6 @@ import tempfile ...@@ -28,7 +28,6 @@ import tempfile
import time import time
import unittest import unittest
from collections.abc import Mapping from collections.abc import Mapping
from distutils.util import strtobool
from io import StringIO from io import StringIO
from pathlib import Path from pathlib import Path
from typing import Iterator, List, Optional, Union from typing import Iterator, List, Optional, Union
...@@ -93,6 +92,7 @@ from .utils import ( ...@@ -93,6 +92,7 @@ from .utils import (
is_torchdynamo_available, is_torchdynamo_available,
is_torchvision_available, is_torchvision_available,
is_vision_available, is_vision_available,
strtobool,
) )
......
...@@ -29,7 +29,6 @@ import sys ...@@ -29,7 +29,6 @@ import sys
import time import time
import warnings import warnings
from collections.abc import Mapping from collections.abc import Mapping
from distutils.util import strtobool
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
...@@ -152,6 +151,7 @@ from .utils import ( ...@@ -152,6 +151,7 @@ from .utils import (
is_torch_neuroncore_available, is_torch_neuroncore_available,
is_torch_tpu_available, is_torch_tpu_available,
logging, logging,
strtobool,
) )
from .utils.generic import ContextManagers from .utils.generic import ContextManagers
......
...@@ -47,6 +47,7 @@ from .generic import ( ...@@ -47,6 +47,7 @@ from .generic import (
is_torch_tensor, is_torch_tensor,
reshape, reshape,
squeeze, squeeze,
strtobool,
tensor_size, tensor_size,
to_numpy, to_numpy,
to_py_obj, to_py_obj,
......
...@@ -56,6 +56,21 @@ class cached_property(property): ...@@ -56,6 +56,21 @@ class cached_property(property):
return cached return cached
# vendored from distutils.util
def strtobool(val):
"""Convert a string representation of truth to true (1) or false (0).
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'.
Raises ValueError if 'val' is anything else.
"""
val = val.lower()
if val in {"y", "yes", "t", "true", "on", "1"}:
return 1
if val in {"n", "no", "f", "false", "off", "0"}:
return 0
raise ValueError(f"invalid truth value {val!r}")
def is_tensor(x): def is_tensor(x):
""" """
Tests if `x` is a `torch.Tensor`, `tf.Tensor`, `jaxlib.xla_extension.DeviceArray` or `np.ndarray`. Tests if `x` is a `torch.Tensor`, `tf.Tensor`, `jaxlib.xla_extension.DeviceArray` or `np.ndarray`.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment