diff options
| author | Benoit Pierre <benoit.pierre@gmail.com> | 2017-10-25 17:55:26 +0200 |
|---|---|---|
| committer | Benoit Pierre <benoit.pierre@gmail.com> | 2017-10-25 23:16:15 +0200 |
| commit | 2c897b5b877d401e13b661f2a0a14e99a1aabdc8 (patch) | |
| tree | 5f6e7a21ba5566840d879ca3a0d1fef180c2d47f /setuptools/__init__.py | |
| parent | 3686dedb4bfbd0e6630c10119c8fe7af9369248e (diff) | |
| download | external_python_setuptools-2c897b5b877d401e13b661f2a0a14e99a1aabdc8.tar.gz external_python_setuptools-2c897b5b877d401e13b661f2a0a14e99a1aabdc8.tar.bz2 external_python_setuptools-2c897b5b877d401e13b661f2a0a14e99a1aabdc8.zip | |
improve encoding handling for `setup.cfg`
Support the same mechanism as for Python sources for declaring
the encoding to be used when reading `setup.cfg` (see PEP 263),
and return the results of reading it as Unicode.
Fix #1062 and #1136.
Diffstat (limited to 'setuptools/__init__.py')
| -rw-r--r-- | setuptools/__init__.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 04f76740..77b4a374 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -4,9 +4,12 @@ import os import functools import distutils.core import distutils.filelist +import re +from distutils.errors import DistutilsOptionError from distutils.util import convert_path from fnmatch import fnmatchcase +from setuptools.extern.six import string_types from setuptools.extern.six.moves import filter, map import setuptools.version @@ -127,6 +130,37 @@ class Command(_Command): _Command.__init__(self, dist) vars(self).update(kw) + def _ensure_stringlike(self, option, what, default=None): + val = getattr(self, option) + if val is None: + setattr(self, option, default) + return default + elif not isinstance(val, string_types): + raise DistutilsOptionError("'%s' must be a %s (got `%s`)" + % (option, what, val)) + return val + + def ensure_string_list(self, option): + r"""Ensure that 'option' is a list of strings. If 'option' is + currently a string, we split it either on /,\s*/ or /\s+/, so + "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become + ["foo", "bar", "baz"]. + """ + val = getattr(self, option) + if val is None: + return + elif isinstance(val, string_types): + setattr(self, option, re.split(r',\s*|\s+', val)) + else: + if isinstance(val, list): + ok = all(isinstance(v, string_types) for v in val) + else: + ok = False + if not ok: + raise DistutilsOptionError( + "'%s' must be a list of strings (got %r)" + % (option, val)) + def reinitialize_command(self, command, reinit_subcommands=0, **kw): cmd = _Command.reinitialize_command(self, command, reinit_subcommands) vars(cmd).update(kw) |
