"src/vscode:/vscode.git/clone" did not exist on "e1b7f1f240526bf958c4bec79443094e4057fbf5"
Unverified Commit 3c67864c authored by Sayak Paul's avatar Sayak Paul Committed by GitHub
Browse files

Remove `distutils` (#7455)

* strtobool

* replace Command from setuptools.
parent 36369904
......@@ -81,9 +81,8 @@ To create the package for PyPI.
import os
import re
import sys
from distutils.core import Command
from setuptools import find_packages, setup
from setuptools import Command, find_packages, setup
# IMPORTANT:
......@@ -163,7 +162,7 @@ def deps_list(*pkgs):
class DepsTableUpdateCommand(Command):
"""
A custom distutils command that updates the dependency table.
A custom command that updates the dependency table.
usage: python setup.py deps_table_update
"""
......
......@@ -14,7 +14,6 @@ import time
import unittest
import urllib.parse
from contextlib import contextmanager
from distutils.util import strtobool
from io import BytesIO, StringIO
from pathlib import Path
from typing import Callable, Dict, List, Optional, Union
......@@ -151,7 +150,7 @@ def parse_flag_from_env(key, default=False):
else:
# KEY is set, convert it to True or False.
try:
_value = strtobool(value)
_value = str_to_bool(value)
except ValueError:
# More values are supported, but let's keep the message simple.
raise ValueError(f"If set, {key} must be yes or no.")
......@@ -921,6 +920,22 @@ def backend_supports_training(device: str):
return BACKEND_SUPPORTS_TRAINING[device]
# Taken from the following PR:
# https://github.com/huggingface/accelerate/pull/1964
def str_to_bool(value) -> int:
"""
Converts a string representation of truth to `True` (1) or `False` (0).
True values are `y`, `yes`, `t`, `true`, `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
"""
value = value.lower()
if value in ("y", "yes", "t", "true", "on", "1"):
return 1
elif value in ("n", "no", "f", "false", "off", "0"):
return 0
else:
raise ValueError(f"invalid truth value {value}")
# Guard for when Torch is not available
if is_torch_available():
# Update device function dict mapping
......
......@@ -15,12 +15,12 @@
import os
import unittest
from distutils.util import strtobool
import pytest
from diffusers import __version__
from diffusers.utils import deprecate
from diffusers.utils.testing_utils import str_to_bool
# Used to test the hub
......@@ -191,7 +191,7 @@ def parse_flag_from_env(key, default=False):
else:
# KEY is set, convert it to True or False.
try:
_value = strtobool(value)
_value = str_to_bool(value)
except ValueError:
# More values are supported, but let's keep the message simple.
raise ValueError(f"If set, {key} must be yes or no.")
......
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