[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:
3
setup.py
3
setup.py
@@ -76,10 +76,9 @@ To create the package for pypi.
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
from distutils.core import Command
|
||||
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
|
||||
|
||||
@@ -28,7 +28,6 @@ import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from collections.abc import Mapping
|
||||
from distutils.util import strtobool
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from typing import Iterator, List, Optional, Union
|
||||
@@ -93,6 +92,7 @@ from .utils import (
|
||||
is_torchdynamo_available,
|
||||
is_torchvision_available,
|
||||
is_vision_available,
|
||||
strtobool,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import sys
|
||||
import time
|
||||
import warnings
|
||||
from collections.abc import Mapping
|
||||
from distutils.util import strtobool
|
||||
from pathlib import Path
|
||||
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_tpu_available,
|
||||
logging,
|
||||
strtobool,
|
||||
)
|
||||
from .utils.generic import ContextManagers
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ from .generic import (
|
||||
is_torch_tensor,
|
||||
reshape,
|
||||
squeeze,
|
||||
strtobool,
|
||||
tensor_size,
|
||||
to_numpy,
|
||||
to_py_obj,
|
||||
|
||||
@@ -56,6 +56,21 @@ class cached_property(property):
|
||||
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):
|
||||
"""
|
||||
Tests if `x` is a `torch.Tensor`, `tf.Tensor`, `jaxlib.xla_extension.DeviceArray` or `np.ndarray`.
|
||||
|
||||
Reference in New Issue
Block a user