Skip to content

Commit 1089223

Browse files
authored
Merge pull request #4996 from abravalheri/cleanup-distutils
Remove almost identical copies of methods already defined in `distutils`
2 parents 00c16df + 7ad574d commit 1089223

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

newsfragments/4996.misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove code duplication for ``_ensure_stringlike`` and ``ensure_string_list``
2+
in ``setuptools/__init__.py`` (already exists in ``distutils/cmd.py``).

setuptools/__init__.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import functools
1111
import os
12-
import re
1312
import sys
1413
from abc import abstractmethod
1514
from collections.abc import Mapping
@@ -30,7 +29,6 @@
3029
from .warnings import SetuptoolsDeprecationWarning
3130

3231
import distutils.core
33-
from distutils.errors import DistutilsOptionError
3432

3533
__all__ = [
3634
'setup',
@@ -175,42 +173,6 @@ def __init__(self, dist: Distribution, **kw) -> None:
175173
super().__init__(dist)
176174
vars(self).update(kw)
177175

178-
def _ensure_stringlike(self, option, what, default=None):
179-
val = getattr(self, option)
180-
if val is None:
181-
setattr(self, option, default)
182-
return default
183-
elif not isinstance(val, str):
184-
raise DistutilsOptionError(f"'{option}' must be a {what} (got `{val}`)")
185-
return val
186-
187-
def ensure_string_list(self, option: str) -> None:
188-
r"""Ensure that 'option' is a list of strings. If 'option' is
189-
currently a string, we split it either on /,\s*/ or /\s+/, so
190-
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
191-
["foo", "bar", "baz"].
192-
193-
..
194-
TODO: This method seems to be similar to the one in ``distutils.cmd``
195-
Probably it is just here for backward compatibility with old Python versions?
196-
197-
:meta private:
198-
"""
199-
val = getattr(self, option)
200-
if val is None:
201-
return
202-
elif isinstance(val, str):
203-
setattr(self, option, re.split(r',\s*|\s+', val))
204-
else:
205-
if isinstance(val, list):
206-
ok = all(isinstance(v, str) for v in val)
207-
else:
208-
ok = False
209-
if not ok:
210-
raise DistutilsOptionError(
211-
f"'{option}' must be a list of strings (got {val!r})"
212-
)
213-
214176
@overload
215177
def reinitialize_command(
216178
self, command: str, reinit_subcommands: bool = False, **kw

0 commit comments

Comments
 (0)