"tests/vscode:/vscode.git/clone" did not exist on "9ec9df57ca9a920250f4f0d6a010868a6866772e"
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. ...@@ -81,9 +81,8 @@ To create the package for PyPI.
import os import os
import re import re
import sys import sys
from distutils.core import Command
from setuptools import find_packages, setup from setuptools import Command, find_packages, setup
# IMPORTANT: # IMPORTANT:
...@@ -163,7 +162,7 @@ def deps_list(*pkgs): ...@@ -163,7 +162,7 @@ def deps_list(*pkgs):
class DepsTableUpdateCommand(Command): 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 usage: python setup.py deps_table_update
""" """
......
...@@ -14,7 +14,6 @@ import time ...@@ -14,7 +14,6 @@ import time
import unittest import unittest
import urllib.parse import urllib.parse
from contextlib import contextmanager from contextlib import contextmanager
from distutils.util import strtobool
from io import BytesIO, StringIO from io import BytesIO, StringIO
from pathlib import Path from pathlib import Path
from typing import Callable, Dict, List, Optional, Union from typing import Callable, Dict, List, Optional, Union
...@@ -151,7 +150,7 @@ def parse_flag_from_env(key, default=False): ...@@ -151,7 +150,7 @@ def parse_flag_from_env(key, default=False):
else: else:
# KEY is set, convert it to True or False. # KEY is set, convert it to True or False.
try: try:
_value = strtobool(value) _value = str_to_bool(value)
except ValueError: except ValueError:
# More values are supported, but let's keep the message simple. # More values are supported, but let's keep the message simple.
raise ValueError(f"If set, {key} must be yes or no.") raise ValueError(f"If set, {key} must be yes or no.")
...@@ -921,6 +920,22 @@ def backend_supports_training(device: str): ...@@ -921,6 +920,22 @@ def backend_supports_training(device: str):
return BACKEND_SUPPORTS_TRAINING[device] 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 # Guard for when Torch is not available
if is_torch_available(): if is_torch_available():
# Update device function dict mapping # Update device function dict mapping
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
import os import os
import unittest import unittest
from distutils.util import strtobool
import pytest import pytest
from diffusers import __version__ from diffusers import __version__
from diffusers.utils import deprecate from diffusers.utils import deprecate
from diffusers.utils.testing_utils import str_to_bool
# Used to test the hub # Used to test the hub
...@@ -191,7 +191,7 @@ def parse_flag_from_env(key, default=False): ...@@ -191,7 +191,7 @@ def parse_flag_from_env(key, default=False):
else: else:
# KEY is set, convert it to True or False. # KEY is set, convert it to True or False.
try: try:
_value = strtobool(value) _value = str_to_bool(value)
except ValueError: except ValueError:
# More values are supported, but let's keep the message simple. # More values are supported, but let's keep the message simple.
raise ValueError(f"If set, {key} must be yes or no.") 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