[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`
This commit is contained in:
Xuehai Pan
2023-04-04 00:04:24 +08:00
committed by GitHub
parent 4c33a0c4fc
commit 80d1319e1b
5 changed files with 19 additions and 4 deletions

View File

@@ -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

View File

@@ -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 (
is_torchdynamo_available, is_torchdynamo_available,
is_torchvision_available, is_torchvision_available,
is_vision_available, is_vision_available,
strtobool,
) )

View File

@@ -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 (
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

View File

@@ -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,

View File

@@ -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`.