Skip to content

Commit 3c67864

Browse files
authored
Remove distutils (#7455)
* strtobool * replace Command from setuptools.
1 parent 3636990 commit 3c67864

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

setup.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@
8181
import os
8282
import re
8383
import sys
84-
from distutils.core import Command
8584

86-
from setuptools import find_packages, setup
85+
from setuptools import Command, find_packages, setup
8786

8887

8988
# IMPORTANT:
@@ -163,7 +162,7 @@ def deps_list(*pkgs):
163162

164163
class DepsTableUpdateCommand(Command):
165164
"""
166-
A custom distutils command that updates the dependency table.
165+
A custom command that updates the dependency table.
167166
usage: python setup.py deps_table_update
168167
"""
169168

src/diffusers/utils/testing_utils.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import unittest
1515
import urllib.parse
1616
from contextlib import contextmanager
17-
from distutils.util import strtobool
1817
from io import BytesIO, StringIO
1918
from pathlib import Path
2019
from typing import Callable, Dict, List, Optional, Union
@@ -151,7 +150,7 @@ def parse_flag_from_env(key, default=False):
151150
else:
152151
# KEY is set, convert it to True or False.
153152
try:
154-
_value = strtobool(value)
153+
_value = str_to_bool(value)
155154
except ValueError:
156155
# More values are supported, but let's keep the message simple.
157156
raise ValueError(f"If set, {key} must be yes or no.")
@@ -921,6 +920,22 @@ def backend_supports_training(device: str):
921920
return BACKEND_SUPPORTS_TRAINING[device]
922921

923922

923+
# Taken from the following PR:
924+
# https://github.com/huggingface/accelerate/pull/1964
925+
def str_to_bool(value) -> int:
926+
"""
927+
Converts a string representation of truth to `True` (1) or `False` (0).
928+
True values are `y`, `yes`, `t`, `true`, `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
929+
"""
930+
value = value.lower()
931+
if value in ("y", "yes", "t", "true", "on", "1"):
932+
return 1
933+
elif value in ("n", "no", "f", "false", "off", "0"):
934+
return 0
935+
else:
936+
raise ValueError(f"invalid truth value {value}")
937+
938+
924939
# Guard for when Torch is not available
925940
if is_torch_available():
926941
# Update device function dict mapping

tests/others/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
import os
1717
import unittest
18-
from distutils.util import strtobool
1918

2019
import pytest
2120

2221
from diffusers import __version__
2322
from diffusers.utils import deprecate
23+
from diffusers.utils.testing_utils import str_to_bool
2424

2525

2626
# Used to test the hub
@@ -191,7 +191,7 @@ def parse_flag_from_env(key, default=False):
191191
else:
192192
# KEY is set, convert it to True or False.
193193
try:
194-
_value = strtobool(value)
194+
_value = str_to_bool(value)
195195
except ValueError:
196196
# More values are supported, but let's keep the message simple.
197197
raise ValueError(f"If set, {key} must be yes or no.")

0 commit comments

Comments
 (0)